braidfs 0.0.76 → 0.0.78
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 +18 -10
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -61,24 +61,24 @@ if (argv.length === 1 && argv[0].match(/^(run|serve)$/)) {
|
|
|
61
61
|
} else if (argv.length && argv.length % 2 == 0 && argv.every((x, i) => i % 2 != 0 || x.match(/^(sync|unsync)$/))) {
|
|
62
62
|
return (async () => {
|
|
63
63
|
for (let i = 0; i < argv.length; i += 2) {
|
|
64
|
-
var
|
|
64
|
+
var sync = argv[i] === 'sync',
|
|
65
65
|
url = argv[i + 1]
|
|
66
66
|
if (!url.match(/^https?:\/\//)) {
|
|
67
67
|
if (url.startsWith('/')) url = require('path').relative(proxy_base, url)
|
|
68
68
|
url = `https://${url}`
|
|
69
69
|
}
|
|
70
|
-
console.log(`${
|
|
70
|
+
console.log(`${sync ? '' : 'un'}subscribing ${sync ? 'to' : 'from'} ${url}`)
|
|
71
71
|
try {
|
|
72
72
|
var res = await braid_fetch(`http://localhost:${config.port}/.braidfs/config`, {
|
|
73
73
|
method: 'PUT',
|
|
74
74
|
patches: [{
|
|
75
75
|
unit: 'json',
|
|
76
76
|
range: `sync[${JSON.stringify(url)}]`,
|
|
77
|
-
content:
|
|
77
|
+
content: sync ? 'true' : ''
|
|
78
78
|
}]
|
|
79
79
|
})
|
|
80
80
|
if (res.ok) {
|
|
81
|
-
console.log(
|
|
81
|
+
console.log(`Now ${sync ? '' : 'un'}subscribed ${sync ? 'to' : 'from'} ${url} in ~/http/.braidfs/config`)
|
|
82
82
|
} else {
|
|
83
83
|
console.log(`failed to ${operation} ${url}`)
|
|
84
84
|
console.log(`server responded with ${res.status}: ${await res.text()}`)
|
|
@@ -91,7 +91,6 @@ You can run it with:
|
|
|
91
91
|
return
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
|
-
console.log('All operations completed successfully.')
|
|
95
94
|
})()
|
|
96
95
|
} else {
|
|
97
96
|
return console.log(`Usage:
|
|
@@ -263,6 +262,10 @@ async function trash_file(fullpath, path) {
|
|
|
263
262
|
await require('fs').promises.rename(fullpath, dest)
|
|
264
263
|
|
|
265
264
|
// and log an error
|
|
265
|
+
await log_error(`error: unsynced file ${fullpath}; moved to ${dest}`)
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
async function log_error(text) {
|
|
266
269
|
var x = await braid_text.get('.braidfs/errors', {}),
|
|
267
270
|
len = [...x.body].length
|
|
268
271
|
await braid_text.put('.braidfs/errors', {
|
|
@@ -270,7 +273,7 @@ async function trash_file(fullpath, path) {
|
|
|
270
273
|
patches: [{
|
|
271
274
|
unit: 'text',
|
|
272
275
|
range: `[${len}:${len}]`,
|
|
273
|
-
content:
|
|
276
|
+
content: `${text}\n`
|
|
274
277
|
}]
|
|
275
278
|
})
|
|
276
279
|
}
|
|
@@ -676,9 +679,12 @@ async function proxy_url(url) {
|
|
|
676
679
|
subscribe: true,
|
|
677
680
|
retry: {
|
|
678
681
|
onRes: (res) => {
|
|
679
|
-
if (res.status !== 209)
|
|
680
|
-
`
|
|
681
|
-
|
|
682
|
+
if (res.status !== 209) {
|
|
683
|
+
log_error(`Can't sync ${url} -- got bad response ${res.status} from server (expected 209)`)
|
|
684
|
+
return console.log(
|
|
685
|
+
`FAILED TO CONNECT TO: ${url}\n` +
|
|
686
|
+
`GOT STATUS CODE: ${res.status}, expected 209.`)
|
|
687
|
+
}
|
|
682
688
|
|
|
683
689
|
console.log(`connected to ${url}`)
|
|
684
690
|
console.log(` editable = ${res.headers.get('editable')}`)
|
|
@@ -738,8 +744,10 @@ async function proxy_url(url) {
|
|
|
738
744
|
return
|
|
739
745
|
}
|
|
740
746
|
|
|
741
|
-
if (r.headers.get('version') == null)
|
|
747
|
+
if (r.headers.get('version') == null) {
|
|
748
|
+
log_error(`Can't sync ${url} -- got no version from server`)
|
|
742
749
|
return console.log(`GOT NO VERSION FROM: ${url}`)
|
|
750
|
+
}
|
|
743
751
|
var parents = JSON.parse(`[${r.headers.get('version')}]`)
|
|
744
752
|
|
|
745
753
|
var bytes = (await braid_text.get_resource(url)).doc.toBytes()
|