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