braidfs 0.0.66 → 0.0.69
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 +14 -5
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -132,7 +132,7 @@ async function main() {
|
|
|
132
132
|
|
|
133
133
|
if (req.url === '/favicon.ico') return
|
|
134
134
|
|
|
135
|
-
if (
|
|
135
|
+
if (!['::ffff:127.0.0.1', '127.0.0.1', '::1'].includes(req.socket.remoteAddress)) {
|
|
136
136
|
res.writeHead(403, { 'Content-Type': 'text/plain' })
|
|
137
137
|
return res.end('Access denied: only accessible from localhost')
|
|
138
138
|
}
|
|
@@ -161,8 +161,7 @@ async function main() {
|
|
|
161
161
|
var proxy = await proxy_url.cache[normalize_url(path)]
|
|
162
162
|
|
|
163
163
|
var parents = JSON.parse(decodeURIComponent(m[2]))
|
|
164
|
-
var parent_text = (await braid_text.get(proxy.url,
|
|
165
|
-
{ parents })).body
|
|
164
|
+
var parent_text = proxy?.version_to_text_cache.get(JSON.stringify(parents)) ?? (await braid_text.get(proxy.url, { parents })).body
|
|
166
165
|
|
|
167
166
|
var text = await new Promise(done => {
|
|
168
167
|
const chunks = []
|
|
@@ -462,16 +461,26 @@ async function proxy_url(url) {
|
|
|
462
461
|
// store a recent mapping of content-hashes to their versions,
|
|
463
462
|
// to support the command line: braidfs editing filename < file
|
|
464
463
|
self.hash_to_version_cache = new Map()
|
|
464
|
+
self.version_to_text_cache = new Map()
|
|
465
465
|
function add_to_version_cache(text, version) {
|
|
466
|
+
if (self.hash_to_version_cache.size)
|
|
467
|
+
[...self.hash_to_version_cache.values()].pop().time = Date.now()
|
|
468
|
+
|
|
466
469
|
var hash = sha256(text)
|
|
467
|
-
self.hash_to_version_cache.
|
|
468
|
-
|
|
470
|
+
var value = self.hash_to_version_cache.get(hash)
|
|
471
|
+
if (value) {
|
|
472
|
+
self.hash_to_version_cache.delete(hash)
|
|
473
|
+
self.version_to_text_cache.delete(JSON.stringify(value.version))
|
|
474
|
+
}
|
|
475
|
+
self.hash_to_version_cache.set(hash, { version })
|
|
476
|
+
self.version_to_text_cache.set(JSON.stringify(version), text)
|
|
469
477
|
|
|
470
478
|
var too_old = Date.now() - 30000
|
|
471
479
|
for (var [key, value] of self.hash_to_version_cache) {
|
|
472
480
|
if (value.time > too_old ||
|
|
473
481
|
self.hash_to_version_cache.size <= 1) break
|
|
474
482
|
self.hash_to_version_cache.delete(key)
|
|
483
|
+
self.version_to_text_cache.delete(JSON.stringify(value.version))
|
|
475
484
|
}
|
|
476
485
|
}
|
|
477
486
|
|