braidfs 0.0.49 → 0.0.51
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.
- package/index.js +57 -123
- package/package.json +3 -3
package/index.js
CHANGED
|
@@ -301,6 +301,7 @@ async function proxy_url(url) {
|
|
|
301
301
|
if (!proxy_url.cache[path]) proxy_url.cache[path] = proxy_url.chain = proxy_url.chain.then(async () => {
|
|
302
302
|
var freed = false,
|
|
303
303
|
aborts = new Set(),
|
|
304
|
+
braid_text_get_options = null,
|
|
304
305
|
wait_count = 0
|
|
305
306
|
var wait_promise, wait_promise_done
|
|
306
307
|
var start_something = () => {
|
|
@@ -318,6 +319,7 @@ async function proxy_url(url) {
|
|
|
318
319
|
freed = true
|
|
319
320
|
for (let a of aborts) a.abort()
|
|
320
321
|
await wait_promise
|
|
322
|
+
if (braid_text_get_options) await braid_text.forget(url, braid_text_get_options)
|
|
321
323
|
await braid_text.delete(url)
|
|
322
324
|
try { await require('fs').promises.unlink(meta_path) } catch (e) {}
|
|
323
325
|
try { await require('fs').promises.unlink(await get_fullpath()) } catch (e) {}
|
|
@@ -516,139 +518,71 @@ async function proxy_url(url) {
|
|
|
516
518
|
file_loop_pump_lock--
|
|
517
519
|
}
|
|
518
520
|
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
let head_res = await braid_fetch(url, {
|
|
527
|
-
signal: a.signal,
|
|
528
|
-
method: 'HEAD',
|
|
529
|
-
headers: {
|
|
530
|
-
Accept: 'text/plain',
|
|
531
|
-
...config.domains?.[(new URL(url)).hostname]?.auth_headers,
|
|
532
|
-
},
|
|
533
|
-
retry: true,
|
|
534
|
-
})
|
|
521
|
+
if (is_external_link) connect()
|
|
522
|
+
function connect() {
|
|
523
|
+
let a = new AbortController()
|
|
524
|
+
aborts.add(a)
|
|
525
|
+
self.reconnect = () => {
|
|
526
|
+
console.log(`reconnecting ${url}`)
|
|
527
|
+
|
|
535
528
|
aborts.delete(a)
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
null
|
|
539
|
-
self.file_read_only = head_res.headers.get('editable') === 'false'
|
|
540
|
-
signal_file_needs_writing()
|
|
541
|
-
} catch (e) {
|
|
542
|
-
console.log('HEAD failed: ', e)
|
|
529
|
+
a.abort()
|
|
530
|
+
connect()
|
|
543
531
|
}
|
|
544
532
|
|
|
545
|
-
console.log(`
|
|
533
|
+
console.log(`connecting to ${url}`)
|
|
534
|
+
braid_fetch(url, {
|
|
535
|
+
signal: a.signal,
|
|
536
|
+
headers: {
|
|
537
|
+
"Merge-Type": "dt",
|
|
538
|
+
Accept: 'text/plain',
|
|
539
|
+
...config.domains?.[(new URL(url)).hostname]?.auth_headers,
|
|
540
|
+
},
|
|
541
|
+
subscribe: true,
|
|
542
|
+
retry: {
|
|
543
|
+
onRes: (res) => {
|
|
544
|
+
console.log(`connected to ${url}`)
|
|
545
|
+
console.log(` editable = ${res.headers.get('editable')}`)
|
|
546
|
+
|
|
547
|
+
self.file_read_only = res.headers.get('editable') === 'false'
|
|
548
|
+
signal_file_needs_writing()
|
|
549
|
+
}
|
|
550
|
+
},
|
|
551
|
+
heartbeats: 120,
|
|
552
|
+
parents: async () => {
|
|
553
|
+
let cur = await braid_text.get(url, {})
|
|
554
|
+
if (cur.version.length) return cur.version
|
|
555
|
+
},
|
|
556
|
+
peer
|
|
557
|
+
}).then(x => {
|
|
558
|
+
x.subscribe(async update => {
|
|
559
|
+
console.log(`got external update about ${url}`)
|
|
546
560
|
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
let [a, seq] = p.split('-')
|
|
550
|
-
if (seq > (waiting_for_versions[a] ?? -1))
|
|
551
|
-
waiting_for_versions[a] = seq
|
|
552
|
-
}
|
|
561
|
+
if (update.body) update.body = update.body_text
|
|
562
|
+
if (update.patches) for (let p of update.patches) p.content = p.content_text
|
|
553
563
|
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
done()
|
|
558
|
-
done = null
|
|
559
|
-
}
|
|
564
|
+
// console.log(`update: ${JSON.stringify(update, null, 4)}`)
|
|
565
|
+
if (update.version.length === 0) return
|
|
566
|
+
if (update.version.length !== 1) throw 'unexpected'
|
|
560
567
|
|
|
561
|
-
|
|
562
|
-
function connect() {
|
|
563
|
-
let a = new AbortController()
|
|
564
|
-
aborts.add({
|
|
565
|
-
abort: () => {
|
|
566
|
-
a.abort()
|
|
567
|
-
done?.()
|
|
568
|
-
done = null
|
|
569
|
-
}
|
|
570
|
-
})
|
|
571
|
-
self.reconnect = () => {
|
|
572
|
-
console.log(`reconnecting ${url}`)
|
|
568
|
+
if (!start_something()) return
|
|
573
569
|
|
|
574
|
-
|
|
575
|
-
a.abort()
|
|
576
|
-
connect()
|
|
577
|
-
}
|
|
570
|
+
await braid_text.put(url, { ...update, peer, merge_type: 'dt' })
|
|
578
571
|
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
Accept: 'text/plain',
|
|
585
|
-
...config.domains?.[(new URL(url)).hostname]?.auth_headers,
|
|
586
|
-
},
|
|
587
|
-
subscribe: true,
|
|
588
|
-
retry: {
|
|
589
|
-
onRes: (res) => {
|
|
590
|
-
console.log(`connected to ${url}`)
|
|
591
|
-
console.log(` editable = ${res.headers.get('editable')}`)
|
|
592
|
-
|
|
593
|
-
self.file_read_only = res.headers.get('editable') === 'false'
|
|
594
|
-
signal_file_needs_writing()
|
|
595
|
-
}
|
|
596
|
-
},
|
|
597
|
-
heartbeats: 120,
|
|
598
|
-
parents: async () => {
|
|
599
|
-
let cur = await braid_text.get(url, {})
|
|
600
|
-
if (cur.version.length) {
|
|
601
|
-
if (done) {
|
|
602
|
-
for (let v of cur.version) {
|
|
603
|
-
let [a, seq] = v.split('-')
|
|
604
|
-
if (waiting_for_versions[a] <= seq)
|
|
605
|
-
delete waiting_for_versions[a]
|
|
606
|
-
}
|
|
607
|
-
if (!Object.keys(waiting_for_versions).length) {
|
|
608
|
-
console.log('got everything we were waiting for.')
|
|
609
|
-
done()
|
|
610
|
-
done = null
|
|
611
|
-
}
|
|
612
|
-
}
|
|
613
|
-
|
|
614
|
-
return cur.version
|
|
615
|
-
}
|
|
616
|
-
},
|
|
617
|
-
peer
|
|
618
|
-
}).then(x => {
|
|
619
|
-
x.subscribe(async update => {
|
|
620
|
-
console.log(`got external update about ${url}`)
|
|
621
|
-
|
|
622
|
-
if (update.body) update.body = update.body_text
|
|
623
|
-
if (update.patches) for (let p of update.patches) p.content = p.content_text
|
|
624
|
-
|
|
625
|
-
// console.log(`update: ${JSON.stringify(update, null, 4)}`)
|
|
626
|
-
if (update.version.length === 0) return
|
|
627
|
-
if (update.version.length !== 1) throw 'unexpected'
|
|
628
|
-
|
|
629
|
-
if (!start_something()) return
|
|
630
|
-
|
|
631
|
-
await braid_text.put(url, { ...update, peer, merge_type: 'dt' })
|
|
632
|
-
|
|
633
|
-
if (done) {
|
|
634
|
-
let [a, seq] = update.version[0].split('-')
|
|
635
|
-
if (waiting_for_versions[a] <= seq) delete waiting_for_versions[a]
|
|
636
|
-
if (!Object.keys(waiting_for_versions).length) {
|
|
637
|
-
console.log('got everything we were waiting for..')
|
|
638
|
-
done()
|
|
639
|
-
done = null
|
|
640
|
-
}
|
|
641
|
-
}
|
|
642
|
-
|
|
643
|
-
signal_file_needs_writing()
|
|
644
|
-
finish_something()
|
|
645
|
-
}, e => (e?.name !== "AbortError") && crash(e))
|
|
646
|
-
}).catch(e => (e?.name !== "AbortError") && crash(e))
|
|
647
|
-
}
|
|
648
|
-
})
|
|
649
|
-
finish_something()
|
|
572
|
+
|
|
573
|
+
signal_file_needs_writing()
|
|
574
|
+
finish_something()
|
|
575
|
+
}, e => (e?.name !== "AbortError") && crash(e))
|
|
576
|
+
}).catch(e => (e?.name !== "AbortError") && crash(e))
|
|
650
577
|
}
|
|
651
578
|
|
|
579
|
+
// for config and errors file, listen for web changes
|
|
580
|
+
if (!is_external_link) braid_text.get(url, braid_text_get_options = {
|
|
581
|
+
merge_type: 'dt',
|
|
582
|
+
peer,
|
|
583
|
+
subscribe: signal_file_needs_writing,
|
|
584
|
+
})
|
|
585
|
+
|
|
652
586
|
return self
|
|
653
587
|
})
|
|
654
588
|
return await proxy_url.cache[url]
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "braidfs",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.51",
|
|
4
4
|
"description": "braid technology synchronizing files and webpages",
|
|
5
5
|
"author": "Braid Working Group",
|
|
6
6
|
"repository": "braid-org/braidfs",
|
|
7
7
|
"homepage": "https://braid.org",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"braid-http": "^1.3.
|
|
10
|
-
"braid-text": "^0.2.
|
|
9
|
+
"braid-http": "^1.3.16",
|
|
10
|
+
"braid-text": "^0.2.6",
|
|
11
11
|
"chokidar": "^3.6.0"
|
|
12
12
|
},
|
|
13
13
|
"bin": {
|