braidfs 0.0.94 → 0.0.95
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 +49 -49
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -489,55 +489,6 @@ async function sync_url(url) {
|
|
|
489
489
|
file_loop_pump()
|
|
490
490
|
}
|
|
491
491
|
|
|
492
|
-
async function my_fetch(params) {
|
|
493
|
-
if (freed) return
|
|
494
|
-
try {
|
|
495
|
-
var a = new AbortController()
|
|
496
|
-
aborts.add(a)
|
|
497
|
-
return await braid_fetch(url, {
|
|
498
|
-
signal: a.signal,
|
|
499
|
-
headers: {
|
|
500
|
-
"Merge-Type": "dt",
|
|
501
|
-
"Content-Type": 'text/plain',
|
|
502
|
-
...(x => x && {Cookie: x})(config.cookies?.[new URL(url).hostname])
|
|
503
|
-
},
|
|
504
|
-
retry: { retryRes: r => r.status !== 401 && r.status !== 403 },
|
|
505
|
-
...params
|
|
506
|
-
})
|
|
507
|
-
} catch (e) {
|
|
508
|
-
if (freed) return
|
|
509
|
-
if (e?.name !== "AbortError") console.log(e)
|
|
510
|
-
} finally {
|
|
511
|
-
if (freed) return
|
|
512
|
-
aborts.delete(a)
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
async function send_out(stuff) {
|
|
517
|
-
if (!is_external_link) return
|
|
518
|
-
if (freed) return
|
|
519
|
-
|
|
520
|
-
console.log(`send_out ${url} ${JSON.stringify(stuff, null, 4).slice(0, 1000)}`)
|
|
521
|
-
|
|
522
|
-
var r = await my_fetch({ method: "PUT", ...stuff })
|
|
523
|
-
if (freed) return
|
|
524
|
-
|
|
525
|
-
// the server has acknowledged this version,
|
|
526
|
-
// so add it to the fork point
|
|
527
|
-
if (r.ok) self.update_fork_point(stuff.version[0], stuff.parents)
|
|
528
|
-
|
|
529
|
-
// if we're not authorized,
|
|
530
|
-
if (r.status == 401 || r.status == 403) {
|
|
531
|
-
// and it's one of our versions (a local edit),
|
|
532
|
-
if (self.peer === braid_text.decode_version(stuff.version[0])[0]) {
|
|
533
|
-
// then revert it
|
|
534
|
-
console.log(`access denied: reverting local edits`)
|
|
535
|
-
unsync_url(url)
|
|
536
|
-
sync_url(url)
|
|
537
|
-
}
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
|
|
541
492
|
await within_fiber(fullpath, async () => {
|
|
542
493
|
if (freed) return
|
|
543
494
|
var fullpath = await get_fullpath()
|
|
@@ -776,6 +727,55 @@ async function sync_url(url) {
|
|
|
776
727
|
return frontier.sort()
|
|
777
728
|
}
|
|
778
729
|
|
|
730
|
+
async function my_fetch(params) {
|
|
731
|
+
if (freed) return
|
|
732
|
+
try {
|
|
733
|
+
var a = new AbortController()
|
|
734
|
+
aborts.add(a)
|
|
735
|
+
return await braid_fetch(url, {
|
|
736
|
+
signal: a.signal,
|
|
737
|
+
headers: {
|
|
738
|
+
"Merge-Type": "dt",
|
|
739
|
+
"Content-Type": 'text/plain',
|
|
740
|
+
...(x => x && {Cookie: x})(config.cookies?.[new URL(url).hostname])
|
|
741
|
+
},
|
|
742
|
+
retry: { retryRes: r => r.status !== 401 && r.status !== 403 },
|
|
743
|
+
...params
|
|
744
|
+
})
|
|
745
|
+
} catch (e) {
|
|
746
|
+
if (freed) return
|
|
747
|
+
if (e?.name !== "AbortError") console.log(e)
|
|
748
|
+
} finally {
|
|
749
|
+
if (freed) return
|
|
750
|
+
aborts.delete(a)
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
async function send_out(stuff) {
|
|
755
|
+
if (!is_external_link) return
|
|
756
|
+
if (freed) return
|
|
757
|
+
|
|
758
|
+
console.log(`send_out ${url} ${JSON.stringify(stuff, null, 4).slice(0, 1000)}`)
|
|
759
|
+
|
|
760
|
+
var r = await my_fetch({ method: "PUT", ...stuff })
|
|
761
|
+
if (freed) return
|
|
762
|
+
|
|
763
|
+
// the server has acknowledged this version,
|
|
764
|
+
// so add it to the fork point
|
|
765
|
+
if (r.ok) self.update_fork_point(stuff.version[0], stuff.parents)
|
|
766
|
+
|
|
767
|
+
// if we're not authorized,
|
|
768
|
+
if (r.status == 401 || r.status == 403) {
|
|
769
|
+
// and it's one of our versions (a local edit),
|
|
770
|
+
if (self.peer === braid_text.decode_version(stuff.version[0])[0]) {
|
|
771
|
+
// then revert it
|
|
772
|
+
console.log(`access denied: reverting local edits`)
|
|
773
|
+
unsync_url(url)
|
|
774
|
+
sync_url(url)
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
|
|
779
779
|
async function find_fork_point() {
|
|
780
780
|
if (freed) return
|
|
781
781
|
console.log(`[find_fork_point] url: ${url}`)
|