@summerscar/dsh-mnemon-sync 0.1.6 → 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.
Files changed (3) hide show
  1. package/README.md +2 -0
  2. package/index.js +39 -4
  3. package/package.json +3 -2
package/README.md CHANGED
@@ -33,6 +33,8 @@ dsh plugin --profile web add @summerscar/dsh-mnemon-sync
33
33
 
34
34
  重启 DSH,打开记忆系统即可看到「同步备份」。没装 `dsh-mnemon` 时插件仍可运行,只是不显示标签页。
35
35
 
36
+ > **Desktop 版**:在桌面应用的插件界面里安装即可。`desktop` profile 由 Electron 应用独占管理,命令行 `dsh plugin --profile desktop` 会被拒绝,这是 dsh 自身的限制。
37
+
36
38
  ## 功能
37
39
 
38
40
  **三个组件,任意组合**(默认全选)
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
- // `mnemonMemory` is optional on purpose: the plugin still backs up on a profile
44
- // where dsh-mnemon is absent or too old to accept Sources, it just cannot offer
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.6",
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",
@@ -86,7 +86,8 @@
86
86
  "compatibility": {
87
87
  "dsh": ">=0.2.1-rc.1 <0.3.0-0",
88
88
  "profiles": [
89
- "web"
89
+ "web",
90
+ "desktop"
90
91
  ]
91
92
  }
92
93
  },