braid-blob 0.0.11 → 0.0.12
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 +21 -10
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -37,19 +37,22 @@ braid_blob.serve = async (req, res, options = {}) => {
|
|
|
37
37
|
if (req.method === 'GET') {
|
|
38
38
|
// Handle GET request for binary files
|
|
39
39
|
|
|
40
|
+
if (our_v == null) {
|
|
41
|
+
res.statusCode = 404
|
|
42
|
+
return res.end('')
|
|
43
|
+
}
|
|
44
|
+
|
|
40
45
|
// Set Version header;
|
|
41
46
|
// but if this is a subscription,
|
|
42
47
|
// then we set Current-Version instead
|
|
43
|
-
res.setHeader((req.subscribe ? 'Current-' : '') + 'Version',
|
|
44
|
-
our_v != null ? `"${our_v}"` : '')
|
|
48
|
+
res.setHeader((req.subscribe ? 'Current-' : '') + 'Version', `"${our_v}"`)
|
|
45
49
|
|
|
46
50
|
// Set Content-Type
|
|
47
51
|
if (meta.content_type)
|
|
48
52
|
res.setHeader('Content-Type', meta.content_type)
|
|
49
53
|
|
|
50
54
|
if (!req.subscribe)
|
|
51
|
-
return res.end(
|
|
52
|
-
await fs.promises.readFile(filename) : '')
|
|
55
|
+
return res.end(await fs.promises.readFile(filename))
|
|
53
56
|
|
|
54
57
|
if (!res.hasHeader("editable"))
|
|
55
58
|
res.setHeader("Editable", "true")
|
|
@@ -67,12 +70,11 @@ braid_blob.serve = async (req, res, options = {}) => {
|
|
|
67
70
|
|
|
68
71
|
|
|
69
72
|
// Send an immediate update when:
|
|
70
|
-
if (!req.parents ||
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
)))
|
|
73
|
+
if (!req.parents || // 1) They have no version history
|
|
74
|
+
// (need full sync)
|
|
75
|
+
!req.parents.length || // 2) Or their version is the empty set
|
|
76
|
+
our_v > 1*req.parents[0] // 3) Or our version is newer
|
|
77
|
+
)
|
|
76
78
|
return res.sendUpdate({
|
|
77
79
|
version: our_v != null ? ['' + our_v] : [],
|
|
78
80
|
body: our_v != null ? await fs.promises.readFile(filename) : ''
|
|
@@ -117,6 +119,15 @@ braid_blob.serve = async (req, res, options = {}) => {
|
|
|
117
119
|
res.setHeader("Version", our_v != null ? `"${our_v}"` : '')
|
|
118
120
|
}
|
|
119
121
|
res.end('')
|
|
122
|
+
} else if (req.method === 'DELETE') {
|
|
123
|
+
try {
|
|
124
|
+
await fs.promises.unlink(filename)
|
|
125
|
+
} catch (e) {}
|
|
126
|
+
try {
|
|
127
|
+
await fs.promises.unlink(metaname)
|
|
128
|
+
} catch (e) {}
|
|
129
|
+
res.statusCode = 204 // No Content
|
|
130
|
+
res.end('')
|
|
120
131
|
}
|
|
121
132
|
})
|
|
122
133
|
}
|