braidfs 0.0.88 → 0.0.90
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 +24 -20
- package/package.json +3 -3
package/index.js
CHANGED
|
@@ -296,12 +296,14 @@ async function watch_files() {
|
|
|
296
296
|
if (!fullpath.startsWith(sync_base))
|
|
297
297
|
return on_watcher_miss(`path ${fullpath} outside ${sync_base}`)
|
|
298
298
|
|
|
299
|
+
// See if this is a file we should skip..
|
|
300
|
+
var path = require('path').relative(sync_base, fullpath)
|
|
301
|
+
if (skip_file(path)) return
|
|
302
|
+
|
|
299
303
|
// Make sure the path is to a file, and not a directory
|
|
300
304
|
if (event != 'unlink' && (await require('fs').promises.stat(fullpath)).isDirectory())
|
|
301
305
|
return on_watcher_miss(`expected file, got: ${fullpath}`)
|
|
302
306
|
|
|
303
|
-
var path = require('path').relative(sync_base, fullpath)
|
|
304
|
-
if (skip_file(path)) return
|
|
305
307
|
console.log(`file event: ${path}, event: ${event}`)
|
|
306
308
|
|
|
307
309
|
var sync = await sync_url.cache[normalize_url(path)]
|
|
@@ -358,7 +360,8 @@ function unsync_url(url) {
|
|
|
358
360
|
console.log(`unsync_url: ${url}`)
|
|
359
361
|
|
|
360
362
|
delete sync_url.cache[url]
|
|
361
|
-
|
|
363
|
+
sync_url.chain = sync_url.chain.then(unsync_url.cache[url])
|
|
364
|
+
delete unsync_url.cache[url]
|
|
362
365
|
}
|
|
363
366
|
|
|
364
367
|
async function sync_url(url) {
|
|
@@ -374,7 +377,7 @@ async function sync_url(url) {
|
|
|
374
377
|
|
|
375
378
|
if (!sync_url.cache) sync_url.cache = {}
|
|
376
379
|
if (!sync_url.chain) sync_url.chain = Promise.resolve()
|
|
377
|
-
if (!sync_url.cache[path])
|
|
380
|
+
if (!sync_url.cache[path]) {
|
|
378
381
|
var freed = false,
|
|
379
382
|
aborts = new Set(),
|
|
380
383
|
braid_text_get_options = null,
|
|
@@ -390,7 +393,6 @@ async function sync_url(url) {
|
|
|
390
393
|
if (!wait_count) wait_promise_done()
|
|
391
394
|
}
|
|
392
395
|
if (!unsync_url.cache) unsync_url.cache = {}
|
|
393
|
-
var old_unsync = unsync_url.cache[path]
|
|
394
396
|
unsync_url.cache[path] = async () => {
|
|
395
397
|
freed = true
|
|
396
398
|
for (let a of aborts) a.abort()
|
|
@@ -406,8 +408,9 @@ async function sync_url(url) {
|
|
|
406
408
|
try { await require('fs').promises.unlink(meta_path) } catch (e) {}
|
|
407
409
|
try { await require('fs').promises.unlink(await get_fullpath()) } catch (e) {}
|
|
408
410
|
}
|
|
409
|
-
|
|
410
|
-
|
|
411
|
+
sync_url.cache[path] = sync_url.chain = sync_url.chain.then(init)
|
|
412
|
+
}
|
|
413
|
+
async function init() {
|
|
411
414
|
var self = {url}
|
|
412
415
|
|
|
413
416
|
console.log(`sync_url: ${url}`)
|
|
@@ -495,7 +498,7 @@ async function sync_url(url) {
|
|
|
495
498
|
"Content-Type": 'text/plain',
|
|
496
499
|
...(x => x && {Cookie: x})(config.cookies?.[new URL(url).hostname])
|
|
497
500
|
},
|
|
498
|
-
retry: true,
|
|
501
|
+
retry: { retryRes: () => true },
|
|
499
502
|
...params
|
|
500
503
|
})
|
|
501
504
|
} catch (e) {
|
|
@@ -636,9 +639,7 @@ async function sync_url(url) {
|
|
|
636
639
|
|
|
637
640
|
add_to_version_cache(text, version)
|
|
638
641
|
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
await braid_text.put(url, { version, parents, patches, peer: self.peer, merge_type: 'dt' })
|
|
642
|
+
await braid_text.put(url, { version, parents, patches, merge_type: 'dt' })
|
|
642
643
|
|
|
643
644
|
await write_meta_file()
|
|
644
645
|
} else {
|
|
@@ -782,9 +783,12 @@ async function sync_url(url) {
|
|
|
782
783
|
return self.fork_point
|
|
783
784
|
}
|
|
784
785
|
|
|
785
|
-
|
|
786
|
+
var initial_connect_done
|
|
787
|
+
var initial_connect_promise = new Promise(done => initial_connect_done = done)
|
|
788
|
+
|
|
789
|
+
if (is_external_link) find_fork_point().then(async fork_point => {
|
|
790
|
+
await send_new_stuff(fork_point)
|
|
786
791
|
connect(fork_point)
|
|
787
|
-
send_new_stuff(fork_point)
|
|
788
792
|
})
|
|
789
793
|
|
|
790
794
|
function connect(fork_point) {
|
|
@@ -808,6 +812,7 @@ async function sync_url(url) {
|
|
|
808
812
|
},
|
|
809
813
|
subscribe: true,
|
|
810
814
|
retry: {
|
|
815
|
+
retryRes: () => true,
|
|
811
816
|
onRes: (res) => {
|
|
812
817
|
if (res.status !== 209)
|
|
813
818
|
return log_error(`Can't sync ${url} -- got bad response ${res.status} from server (expected 209)`)
|
|
@@ -827,7 +832,9 @@ async function sync_url(url) {
|
|
|
827
832
|
},
|
|
828
833
|
peer: self.peer
|
|
829
834
|
}).then(x => {
|
|
830
|
-
if (x.status
|
|
835
|
+
if (x.status !== 209) throw new Error(`unexpected status: ${x.status}`)
|
|
836
|
+
initial_connect_done()
|
|
837
|
+
x.subscribe(async update => {
|
|
831
838
|
console.log(`got external update about ${url}`)
|
|
832
839
|
|
|
833
840
|
if (update.body) update.body = update.body_text
|
|
@@ -854,18 +861,15 @@ async function sync_url(url) {
|
|
|
854
861
|
|
|
855
862
|
// send them stuff we have but they don't
|
|
856
863
|
async function send_new_stuff(fork_point) {
|
|
857
|
-
var r = await my_fetch({ method: "HEAD" })
|
|
858
|
-
if (r.headers.get('editable') === 'false')
|
|
859
|
-
return console.log('do not send updates for read-only file: ' + url)
|
|
860
|
-
|
|
861
864
|
var in_parallel = create_parallel_promises(10)
|
|
862
|
-
braid_text.get(url, braid_text_get_options = {
|
|
865
|
+
await braid_text.get(url, braid_text_get_options = {
|
|
863
866
|
parents: fork_point,
|
|
864
867
|
merge_type: 'dt',
|
|
865
868
|
peer: self.peer,
|
|
866
869
|
subscribe: async (u) => {
|
|
867
870
|
if (u.version.length) {
|
|
868
871
|
self.signal_file_needs_writing()
|
|
872
|
+
await initial_connect_promise
|
|
869
873
|
in_parallel(() => send_out({...u, peer: self.peer}))
|
|
870
874
|
}
|
|
871
875
|
},
|
|
@@ -880,7 +884,7 @@ async function sync_url(url) {
|
|
|
880
884
|
})
|
|
881
885
|
|
|
882
886
|
return self
|
|
883
|
-
}
|
|
887
|
+
}
|
|
884
888
|
return await sync_url.cache[url]
|
|
885
889
|
}
|
|
886
890
|
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "braidfs",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.90",
|
|
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.75",
|
|
10
|
+
"braid-text": "^0.2.28",
|
|
11
11
|
"chokidar": "^3.6.0"
|
|
12
12
|
},
|
|
13
13
|
"bin": {
|