-
Notifications
You must be signed in to change notification settings - Fork 325
/
Copy pathstate.js
39 lines (35 loc) · 1.5 KB
/
state.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
'use strict'
/* eslint-env browser, webextensions */
const { safeURL } = require('./options')
const offlinePeerCount = -1
// CID of a 'blessed' Web UI release
// which should work without setting CORS headers
const webuiCid = 'QmeSXt32frzhvewLKwA1dePTSjkTfGVwTh55ZcsJxrCSnk' // v2.5.7
function initState (options) {
// we store options and some pregenerated values to avoid async storage
// reads and minimize performance impact on overall browsing experience
const state = Object.assign({}, options)
// generate some additional values
state.peerCount = offlinePeerCount
state.pubGwURL = safeURL(options.publicGatewayUrl)
state.pubGwURLString = state.pubGwURL.toString()
delete state.publicGatewayUrl
state.pubSubdomainGwURL = safeURL(options.publicSubdomainGatewayUrl)
state.pubSubdomainGwURLString = state.pubSubdomainGwURL.toString()
delete state.publicSubdomainGatewayUrl
state.redirect = options.useCustomGateway
delete state.useCustomGateway
state.apiURL = safeURL(options.ipfsApiUrl)
state.apiURLString = state.apiURL.toString()
delete state.ipfsApiUrl
state.gwURL = safeURL(options.customGatewayUrl)
state.gwURLString = state.gwURL.toString()
delete state.customGatewayUrl
state.dnslinkPolicy = String(options.dnslinkPolicy) === 'false' ? false : options.dnslinkPolicy
state.webuiCid = webuiCid
state.webuiRootUrl = `${state.gwURLString}ipfs/${state.webuiCid}/`
return state
}
exports.initState = initState
exports.offlinePeerCount = offlinePeerCount
exports.webuiCid = webuiCid