braidfs 0.0.133 → 0.0.134

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +41 -42
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -141,6 +141,10 @@ You can run it with:
141
141
  async function main() {
142
142
  process.on("unhandledRejection", (x) => console.log(`unhandledRejection: ${x.stack}`))
143
143
  process.on("uncaughtException", (x) => console.log(`uncaughtException: ${x.stack}`))
144
+
145
+ await braid_text.db_folder_init()
146
+ await braid_blob.init()
147
+
144
148
  require('http').createServer(async (req, res) => {
145
149
  try {
146
150
  // console.log(`${req.method} ${req.url}`)
@@ -216,45 +220,44 @@ async function main() {
216
220
  console.log(`daemon started on port ${config.port}`)
217
221
  console.log('!! only accessible from localhost !!')
218
222
 
219
- sync_url('.braidfs/config').then(() => {
220
- braid_text.get('.braidfs/config', {
221
- subscribe: async update => {
222
- let prev = config
223
+ sync_url('.braidfs/config')
224
+ braid_text.get('.braidfs/config', {
225
+ subscribe: async update => {
226
+ let prev = config
223
227
 
224
- let x = await braid_text.get('.braidfs/config')
225
- try {
226
- config = JSON.parse(x)
227
-
228
- // did anything get deleted?
229
- var old_syncs = Object.entries(prev.sync).filter(x => x[1]).map(x => normalize_url(x[0]).replace(/^https?:\/\//, ''))
230
- var new_syncs = new Set(Object.entries(config.sync).filter(x => x[1]).map(x => normalize_url(x[0]).replace(/^https?:\/\//, '')))
231
- for (let url of old_syncs.filter(x => !new_syncs.has(x)))
232
- unsync_url(url)
233
-
234
- // sync all the new stuff
235
- for (let x of Object.entries(config.sync)) if (x[1]) sync_url(x[0])
236
-
237
- // if any auth stuff has changed,
238
- // have the appropriate connections reconnect
239
- let changed = new Set()
240
- // any old domains no longer exist?
241
- for (let domain of Object.keys(prev.cookies ?? {}))
242
- if (!config.cookies?.[domain]) changed.add(domain)
243
- // any new domains not like the old?
244
- for (let [domain, v] of Object.entries(config.cookies ?? {}))
245
- if (!prev.cookies?.[domain]
246
- || JSON.stringify(prev.cookies[domain]) !== JSON.stringify(v))
247
- changed.add(domain)
248
- // ok, have every domain which has changed reconnect
249
- for (let [path, x] of Object.entries(sync_url.cache))
250
- if (changed.has(path.split(/\//)[0].split(/:/)[0]))
251
- (await x).reconnect?.()
252
- } catch (e) {
253
- if (x !== '') console.log(`warning: config file is currently invalid.`)
254
- return
255
- }
228
+ let x = await braid_text.get('.braidfs/config')
229
+ try {
230
+ config = JSON.parse(x)
231
+
232
+ // did anything get deleted?
233
+ var old_syncs = Object.entries(prev.sync).filter(x => x[1]).map(x => normalize_url(x[0]).replace(/^https?:\/\//, ''))
234
+ var new_syncs = new Set(Object.entries(config.sync).filter(x => x[1]).map(x => normalize_url(x[0]).replace(/^https?:\/\//, '')))
235
+ for (let url of old_syncs.filter(x => !new_syncs.has(x)))
236
+ unsync_url(url)
237
+
238
+ // sync all the new stuff
239
+ for (let x of Object.entries(config.sync)) if (x[1]) sync_url(x[0])
240
+
241
+ // if any auth stuff has changed,
242
+ // have the appropriate connections reconnect
243
+ let changed = new Set()
244
+ // any old domains no longer exist?
245
+ for (let domain of Object.keys(prev.cookies ?? {}))
246
+ if (!config.cookies?.[domain]) changed.add(domain)
247
+ // any new domains not like the old?
248
+ for (let [domain, v] of Object.entries(config.cookies ?? {}))
249
+ if (!prev.cookies?.[domain]
250
+ || JSON.stringify(prev.cookies[domain]) !== JSON.stringify(v))
251
+ changed.add(domain)
252
+ // ok, have every domain which has changed reconnect
253
+ for (let [path, x] of Object.entries(sync_url.cache))
254
+ if (changed.has(path.split(/\//)[0].split(/:/)[0]))
255
+ (await x).reconnect?.()
256
+ } catch (e) {
257
+ if (x !== '') console.log(`warning: config file is currently invalid.`)
258
+ return
256
259
  }
257
- })
260
+ }
258
261
  })
259
262
  sync_url('.braidfs/errors')
260
263
 
@@ -413,15 +416,12 @@ function unsync_url(url) {
413
416
  delete unsync_url.cache[url]
414
417
  }
415
418
 
416
- async function sync_url(url) {
419
+ function sync_url(url) {
417
420
  // normalize url by removing any trailing /index/index/
418
421
  var normalized_url = normalize_url(url),
419
422
  wasnt_normal = normalized_url != url
420
423
  url = normalized_url
421
424
 
422
- await braid_text.db_folder_init()
423
- await braid_blob.init()
424
-
425
425
  var is_external_link = url.match(/^https?:\/\//),
426
426
  path = is_external_link ? url.replace(/^https?:\/\//, '') : url,
427
427
  fullpath = `${sync_base}/${path}`,
@@ -480,7 +480,6 @@ async function sync_url(url) {
480
480
  } else throw new Error(`unknown merge-type: ${self.merge_type}`)
481
481
  })()
482
482
  }
483
- return
484
483
 
485
484
  async function detect_merge_type() {
486
485
  // special case for .braidfs/config and .braidfs/error
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "braidfs",
3
- "version": "0.0.133",
3
+ "version": "0.0.134",
4
4
  "description": "braid technology synchronizing files and webpages",
5
5
  "author": "Braid Working Group",
6
6
  "repository": "braid-org/braidfs",