@summerscar/dsh-mnemon-sync 0.1.7 → 0.1.8
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 +39 -4
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -40,10 +40,10 @@ const API_PREFIX = '/api/mnemon-sync'
|
|
|
40
40
|
const ARCHIVE_PREFIX = 'mnemon-sync-'
|
|
41
41
|
|
|
42
42
|
export const name = 'dsh-mnemon-sync'
|
|
43
|
-
// `
|
|
44
|
-
//
|
|
45
|
-
// its page there.
|
|
46
|
-
export const inject = ['webServer']
|
|
43
|
+
// `connection` gates every HTTP route below. `mnemonMemory` stays optional on
|
|
44
|
+
// purpose: the plugin still backs up on a profile where dsh-mnemon is absent
|
|
45
|
+
// or too old to accept Sources, it just cannot offer its page there.
|
|
46
|
+
export const inject = ['webServer', 'connection']
|
|
47
47
|
|
|
48
48
|
/**
|
|
49
49
|
* `MNEMON_DATA_DIR` names the Mnemon home; the memory store itself lives in
|
|
@@ -201,10 +201,45 @@ export function apply(ctx, config = {}) {
|
|
|
201
201
|
// page use its own type instead of borrowing `memory-spaces`, which is the
|
|
202
202
|
// only way its tab can highlight independently.
|
|
203
203
|
|
|
204
|
+
/**
|
|
205
|
+
* Admit only requests the Host's connection service vouches for.
|
|
206
|
+
*
|
|
207
|
+
* These routes read credentials, trigger uploads and can restore files onto
|
|
208
|
+
* disk, so an unauthenticated local request must never reach them. Follow
|
|
209
|
+
* the current `requestRejection(req)` contract (undefined = admit, or an
|
|
210
|
+
* HTTP status); older Hosts exposing only `authorizeIndex` still work.
|
|
211
|
+
* If neither is available, reject rather than falling back to Host/Origin
|
|
212
|
+
* or loopback checks — a missing guard is not a reason to open the route.
|
|
213
|
+
*/
|
|
214
|
+
const rejected = (req, res) => {
|
|
215
|
+
const connection = typeof ctx.get === 'function' ? ctx.get('connection') : undefined
|
|
216
|
+
if (connection === undefined || connection === null) {
|
|
217
|
+
res.statusCode = 401
|
|
218
|
+
res.end()
|
|
219
|
+
return true
|
|
220
|
+
}
|
|
221
|
+
if (typeof connection.requestRejection === 'function') {
|
|
222
|
+
const rejection = connection.requestRejection(req)
|
|
223
|
+
if (rejection === undefined) return false
|
|
224
|
+
res.statusCode = rejection
|
|
225
|
+
res.end()
|
|
226
|
+
return true
|
|
227
|
+
}
|
|
228
|
+
if (typeof connection.authorizeIndex === 'function') {
|
|
229
|
+
// `authorizeIndex` answers the response itself when it rejects; its
|
|
230
|
+
// boolean says which way it went.
|
|
231
|
+
return connection.authorizeIndex(req, res) === false
|
|
232
|
+
}
|
|
233
|
+
res.statusCode = 401
|
|
234
|
+
res.end()
|
|
235
|
+
return true
|
|
236
|
+
}
|
|
237
|
+
|
|
204
238
|
ctx.effect(() => ctx.webServer.register({
|
|
205
239
|
kind: 'prefix',
|
|
206
240
|
path: API_PREFIX,
|
|
207
241
|
handler: (req, res) => {
|
|
242
|
+
if (rejected(req, res)) return
|
|
208
243
|
void handle(req, res).catch((error) => {
|
|
209
244
|
sendJson(res, 500, { error: error instanceof Error ? error.message : String(error) })
|
|
210
245
|
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@summerscar/dsh-mnemon-sync",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"description": "Back up and restore dsh-mnemon memory components (memory spaces, project documents, runtime memory) to S3-compatible storage or WebDAV.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|