This repository has been archived by the owner on Jun 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathindex.js
54 lines (45 loc) · 1.49 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
const assert = require('assert')
const {join} = require('path')
const debugLogger = require('./lib/debug-logger')
const globals = require('./globals')
const {getEnvVar} = require('./lib/env')
const dat = require('./dat')
const dbs = require('./dbs')
const webapis = require('./web-apis/bg')
module.exports = {
getEnvVar,
globals,
dat,
dbs,
debugLogger: debugLogger.debugLogger,
getLogFilePath: debugLogger.getLogFilePath,
getLogFileContent: debugLogger.getLogFileContent,
async setup (opts) {
assert(typeof opts.userDataPath === 'string', 'userDataPath must be a string')
assert(typeof opts.homePath === 'string', 'homePath must be a string')
assert(typeof opts.templatesPath === 'string', 'templatesPath must be a string')
assert(!!opts.datDaemonProcess, 'must provide datDaemonProcess')
assert(!!opts.permsAPI, 'must provide permsAPI')
assert(!!opts.uiAPI, 'must provide uiAPI')
assert(!!opts.rpcAPI, 'must provide rpcAPI')
assert(!!opts.downloadsWebAPI, 'must provide downloadsWebAPI')
assert(!!opts.browserWebAPI, 'must provide browserWebAPI')
for (let k in opts) {
globals[k] = opts[k]
}
// initiate log
debugLogger.setup(join(opts.userDataPath, 'debug.log'))
// setup databases
for (let k in dbs) {
if (dbs[k].setup) {
dbs[k].setup(opts)
}
}
// setup dat
await dat.library.setup(opts)
// setup watchlist
await dat.watchlist.setup()
// setup web apis
webapis.setup(opts)
}
}