braidfs 0.0.26 → 0.0.28
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 +37 -6
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -19,7 +19,7 @@ if (!require('fs').existsSync(braidfs_config_file)) {
|
|
|
19
19
|
sync_urls: [],
|
|
20
20
|
sync_index_urls: [],
|
|
21
21
|
proxy_base: require('path').join(require('os').homedir(), 'http'),
|
|
22
|
-
|
|
22
|
+
proxy_base_meta: require('path').join(braidfs_config_dir, 'proxy_base_meta'),
|
|
23
23
|
braid_text_db: require('path').join(braidfs_config_dir, 'braid-text-db'),
|
|
24
24
|
domains: { 'example.com': { auth_headers: { Cookie: "secret_pass" } } }
|
|
25
25
|
}, null, 4))
|
|
@@ -28,33 +28,52 @@ if (!require('fs').existsSync(braidfs_config_file)) {
|
|
|
28
28
|
let config = JSON.parse(require('fs').readFileSync(braidfs_config_file, 'utf8'))
|
|
29
29
|
|
|
30
30
|
// process command line args (override config)
|
|
31
|
+
console.log(`braidfs version: ${require('./package.json').version}`)
|
|
31
32
|
let argv = process.argv.slice(2)
|
|
32
33
|
let save_config = false
|
|
33
34
|
while (argv.length) {
|
|
34
35
|
let a = argv.shift()
|
|
35
36
|
if (a.match(/^\d+$/)) {
|
|
36
37
|
config.port = parseInt(a)
|
|
38
|
+
console.log(`setting port to ${config.port}`)
|
|
37
39
|
} else if (a === 'sync') {
|
|
38
40
|
let b = argv.shift()
|
|
39
41
|
if (b === 'index') {
|
|
40
42
|
config.sync_index_urls.push(argv.shift())
|
|
43
|
+
console.log(`syncing index url: ${config.sync_index_urls.slice(-1)[0]}`)
|
|
41
44
|
} else {
|
|
42
45
|
config.sync_urls.push(b)
|
|
46
|
+
console.log(`syncing url: ${config.sync_urls.slice(-1)[0]}`)
|
|
43
47
|
}
|
|
44
48
|
} else if (a === 'save') {
|
|
45
49
|
save_config = true
|
|
50
|
+
console.log(`will save new config file`)
|
|
46
51
|
} else if (a === 'expose') {
|
|
47
52
|
config.allow_remote_access = true
|
|
53
|
+
console.log(`exposing server to the outside world`)
|
|
48
54
|
} else if (a === 'unexpose') {
|
|
49
55
|
config.allow_remote_access = false
|
|
56
|
+
console.log(`unexpose server from the outside world`)
|
|
50
57
|
}
|
|
51
58
|
}
|
|
52
|
-
if (
|
|
59
|
+
if (config.proxy_base_last_versions && !config.proxy_base_meta) {
|
|
60
|
+
config.proxy_base_meta = config.proxy_base_last_versions
|
|
61
|
+
delete config.proxy_base_last_versions
|
|
62
|
+
console.log((save_config ?
|
|
63
|
+
`updating config file "proxy_base_last_versions" to "proxy_base_meta": ` :
|
|
64
|
+
`config file "proxy_base_last_versions" being interpreted as "proxy_base_meta": `) +
|
|
65
|
+
config.proxy_base_meta)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (save_config) {
|
|
69
|
+
require('fs').writeFileSync(braidfs_config_file, JSON.stringify(config, null, 4))
|
|
70
|
+
console.log(`saved config file`)
|
|
71
|
+
}
|
|
53
72
|
|
|
54
73
|
braid_text.db_folder = config.braid_text_db
|
|
55
74
|
|
|
56
75
|
require('fs').mkdirSync(config.proxy_base, { recursive: true })
|
|
57
|
-
require('fs').mkdirSync(config.
|
|
76
|
+
require('fs').mkdirSync(config.proxy_base_meta, { recursive: true })
|
|
58
77
|
|
|
59
78
|
let host_to_protocol = {}
|
|
60
79
|
let path_to_func = {}
|
|
@@ -77,6 +96,10 @@ braid_text.list().then(x => {
|
|
|
77
96
|
require('chokidar').watch(config.proxy_base).
|
|
78
97
|
on('change', (path) => {
|
|
79
98
|
path = require('path').relative(config.proxy_base, path)
|
|
99
|
+
|
|
100
|
+
// Skip any temp files with a # in the name
|
|
101
|
+
if (path.includes('#')) return
|
|
102
|
+
|
|
80
103
|
console.log(`path changed: ${path}`)
|
|
81
104
|
|
|
82
105
|
path = normalize_url(path)
|
|
@@ -86,6 +109,10 @@ require('chokidar').watch(config.proxy_base).
|
|
|
86
109
|
}).
|
|
87
110
|
on('add', async (path) => {
|
|
88
111
|
path = require('path').relative(config.proxy_base, path)
|
|
112
|
+
|
|
113
|
+
// Skip any temp files with a # in the name
|
|
114
|
+
if (path.includes('#')) return
|
|
115
|
+
|
|
89
116
|
console.log(`path added: ${path}`)
|
|
90
117
|
|
|
91
118
|
let url = null
|
|
@@ -217,6 +244,7 @@ async function proxy_url(url) {
|
|
|
217
244
|
let peer = Math.random().toString(36).slice(2)
|
|
218
245
|
var char_counter = -1
|
|
219
246
|
let file_last_version = null
|
|
247
|
+
let file_last_digest = null
|
|
220
248
|
let file_last_text = null
|
|
221
249
|
self.file_read_only = null
|
|
222
250
|
let file_needs_reading = true
|
|
@@ -255,13 +283,16 @@ async function proxy_url(url) {
|
|
|
255
283
|
|
|
256
284
|
if (file_last_version === null) {
|
|
257
285
|
try {
|
|
258
|
-
file_last_version = JSON.parse(await require('fs').promises.readFile(require('path').join(config.
|
|
286
|
+
({version: file_last_version, digest: file_last_digest} = JSON.parse(await require('fs').promises.readFile(require('path').join(config.proxy_base_meta, braid_text.encode_filename(url)), { encoding: 'utf8' })))
|
|
259
287
|
file_last_text = (await braid_text.get(url, { version: file_last_version })).body
|
|
260
288
|
file_needs_writing = !v_eq(file_last_version, (await braid_text.get(url, {})).version)
|
|
261
289
|
} catch (e) {
|
|
262
290
|
file_last_text = ''
|
|
263
291
|
file_needs_writing = true
|
|
264
292
|
}
|
|
293
|
+
|
|
294
|
+
// sanity check
|
|
295
|
+
if (file_last_version && require('crypto').createHash('sha256').update(file_last_text).digest('base64') != file_last_digest) throw new Error('file_last_text does not match file_last_digest')
|
|
265
296
|
}
|
|
266
297
|
|
|
267
298
|
while (file_needs_reading || file_needs_writing) {
|
|
@@ -288,7 +319,7 @@ async function proxy_url(url) {
|
|
|
288
319
|
|
|
289
320
|
await braid_text.put(url, { version, parents, patches, peer })
|
|
290
321
|
|
|
291
|
-
await require('fs').promises.writeFile(require('path').join(config.
|
|
322
|
+
await require('fs').promises.writeFile(require('path').join(config.proxy_base_meta, braid_text.encode_filename(url)), JSON.stringify({version: file_last_version, digest: require('crypto').createHash('sha256').update(file_last_text).digest('base64')}))
|
|
292
323
|
}
|
|
293
324
|
}
|
|
294
325
|
if (file_needs_writing) {
|
|
@@ -303,7 +334,7 @@ async function proxy_url(url) {
|
|
|
303
334
|
file_last_version = version
|
|
304
335
|
file_last_text = body
|
|
305
336
|
await require('fs').promises.writeFile(await get_fullpath(), file_last_text)
|
|
306
|
-
await require('fs').promises.writeFile(require('path').join(config.
|
|
337
|
+
await require('fs').promises.writeFile(require('path').join(config.proxy_base_meta, braid_text.encode_filename(url)), JSON.stringify({version: file_last_version, digest: require('crypto').createHash('sha256').update(file_last_text).digest('base64')}))
|
|
307
338
|
}
|
|
308
339
|
|
|
309
340
|
if (await is_read_only(await get_fullpath()) !== self.file_read_only) await set_read_only(await get_fullpath(), self.file_read_only)
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "braidfs",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.28",
|
|
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": "^0.3.20",
|
|
10
|
-
"braid-text": "^0.0.
|
|
10
|
+
"braid-text": "^0.0.31",
|
|
11
11
|
"chokidar": "^3.6.0"
|
|
12
12
|
},
|
|
13
13
|
"bin": {
|