dsh-profile-config-sync 0.6.46 → 0.7.0

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/client.js CHANGED
@@ -70,6 +70,11 @@ window.__ModuleLoader__.load({
70
70
  return true
71
71
  }
72
72
  const M = (zh, en) => (langIsZh() ? zh : en)
73
+ // 0.6.49:本机是不是 Windows 形状(status.platform.local.isWindows)。
74
+ // 面板里凡是「路径示例 / 脚本后缀」都该按它切,别再一律写 D:\ 与 .cmd。
75
+ const isWindowsLike = (data) => Boolean(
76
+ data && data.platform && data.platform.local && data.platform.local.isWindows,
77
+ )
73
78
  const localeNow = () => (langIsZh() ? 'zh-CN' : 'en-US')
74
79
  const langHeaders = () => ({ 'accept-language': langIsZh() ? 'zh-CN,zh;q=0.9' : 'en-US,en;q=0.9' })
75
80
 
@@ -287,14 +292,20 @@ window.__ModuleLoader__.load({
287
292
  // 三件不能混成一件事的:从没同步过 / 扫描没跑完 / 真的没有
288
293
  if (local.known === false) return { kind: 'idle', text: M('还没有同步记录:先推送或拉取一次', 'No sync record yet — push or pull once') }
289
294
  if (local.truncated) return { kind: 'warn', text: M('待推送扫描没跑完(文件太多或超时),数字可能偏小', 'Pending scan did not finish (too many files or timeout) — the count may be low') }
290
- // 非 Windows:执行体只抓 profile / 提示 / Skills / 预设,别让「没有待推送」被读成「全都同步了」
295
+ // 非 Windows:别让「没有待推送」被读成「全都同步了」。0.6.49 起引擎覆盖全部 12 组,
296
+ // 这时就直说「都同步」;没覆盖全的平台才列清单并提 Windows。
291
297
  if (Array.isArray(local.engineGroups) && local.pending === 0) {
292
298
  return {
293
299
  kind: 'idle',
294
- text: M(
295
- `已同步(这台机器走跨平台引擎,只处理 ${local.engineGroups.join(' / ')};会话记录、插件数据、额外路径等组要 Windows 版才会同步)`,
296
- `Up to date (this machine uses the cross-platform engine, which only handles ${local.engineGroups.join(' / ')}; conversations, plugin data and extra paths sync on Windows)`,
297
- ),
300
+ text: local.engineAllGroups
301
+ ? M(
302
+ `已同步(这台机器走跨平台引擎,${local.engineGroups.length} 组内容都与仓库一致)`,
303
+ `Up to date (this machine uses the cross-platform engine; all ${local.engineGroups.length} groups match the repo)`,
304
+ )
305
+ : M(
306
+ `已同步(这台机器走跨平台引擎,只处理 ${local.engineGroups.join(' / ')};其余组要 Windows 版才会同步)`,
307
+ `Up to date (this machine uses the cross-platform engine, which only handles ${local.engineGroups.join(' / ')}; the rest sync on Windows)`,
308
+ ),
298
309
  }
299
310
  }
300
311
  if (local.pending > 0) {
@@ -395,8 +406,15 @@ window.__ModuleLoader__.load({
395
406
  return body
396
407
  }
397
408
 
398
- /** 自动同步接口:check / pull-now / push-now / push-live / cancel。 */
399
- async function callAuto(payload) {
409
+ /**
410
+ * 自动同步接口:check / pull-now / push-now / push-live / cancel。
411
+ *
412
+ * 0.6.49:宿主在 macOS 上用 osascript 弹原生确认框(display dialog)。面板点按钮时那个框
413
+ * 可能被应用窗口挡住、甚至根本不出现在前台 —— 请求就这么挂到 12 分钟超时,用户看到的是
414
+ * 「按钮转圈、没反应」。现在改成两段式:宿主第一遍回 needConfirm + 文案,面板自己问
415
+ * (window.confirm),确认后带 confirmed:true 重发同一请求。命令行/curl 调用仍然走原生框。
416
+ */
417
+ async function autoFetch(payload, depth = 0) {
400
418
  const res = await fetch('/config-sync/auto', {
401
419
  method: 'POST',
402
420
  cache: 'no-store',
@@ -407,9 +425,17 @@ window.__ModuleLoader__.load({
407
425
  const text = await res.text()
408
426
  let body
409
427
  try { body = text ? JSON.parse(text) : null } catch { throw badJson(res) }
428
+ if (body && body.needConfirm && depth < 2) {
429
+ const canAsk = typeof window !== 'undefined' && typeof window.confirm === 'function'
430
+ const ok = canAsk ? window.confirm(String(body.message || body.title || '继续?')) : false
431
+ // 用户点了取消:不抛错(取消不是失败),把决定原样交回调用方
432
+ if (!ok) return { ok: true, action: payload.action, cancelled: true, needConfirm: true }
433
+ return autoFetch({ ...payload, confirmed: true }, depth + 1)
434
+ }
410
435
  if (!res.ok || !body || body.ok !== true) throw new Error((body && body.error) || `${res.status}`)
411
436
  return body
412
437
  }
438
+ async function callAuto(payload) { return autoFetch(payload) }
413
439
 
414
440
  /**
415
441
  * 同步内容勾选:GET 取十组内容与当前勾选,POST 落盘 `<DshHome>\config-sync-scope.json`。
@@ -722,6 +748,8 @@ window.__ModuleLoader__.load({
722
748
  const currentWdUrl = st.url || ''
723
749
  const currentWdUser = st.user || ''
724
750
  const currentWdDir = st.dir || ''
751
+ // 0.6.48:自定义 User-Agent(留空 = 不发 User-Agent 头)
752
+ const currentWdUa = st.userAgent || ''
725
753
  const currentGitUrl = remote.url || ''
726
754
  const currentGitKey = remote.sshKey || ''
727
755
 
@@ -731,6 +759,7 @@ window.__ModuleLoader__.load({
731
759
  const [wdUser, setWdUser] = react.useState(currentWdUser)
732
760
  const [wdPass, setWdPass] = react.useState('')
733
761
  const [wdDir, setWdDir] = react.useState(currentWdDir)
762
+ const [wdUa, setWdUa] = react.useState(currentWdUa)
734
763
  const [gitUrl, setGitUrl] = react.useState(currentGitUrl)
735
764
  const [gitKey, setGitKey] = react.useState(currentGitKey)
736
765
  const [busy, setBusy] = react.useState(false)
@@ -751,19 +780,25 @@ window.__ModuleLoader__.load({
751
780
  setWdUrl(currentWdUrl)
752
781
  setWdUser(currentWdUser)
753
782
  setWdDir(currentWdDir)
783
+ setWdUa(currentWdUa)
754
784
  setWdPass('')
755
785
  setGitUrl(currentGitUrl)
756
786
  setGitKey(currentGitKey)
757
- }, [editing, currentMode, currentWdUrl, currentWdUser, currentWdDir, currentGitUrl, currentGitKey])
787
+ }, [editing, currentMode, currentWdUrl, currentWdUser, currentWdDir, currentWdUa, currentGitUrl, currentGitKey])
758
788
 
759
- const activeMode = editing ? mode : currentMode
760
789
  const wdConfigured = Boolean(st.configured || st.url)
761
790
  const gitConfigured = Boolean(remote.configured || remote.url)
791
+ // 0.6.49 修复(用户实测):卡片在「什么云端都还没配」时会**强制**进入编辑态,
792
+ // 但那时 editing 仍是 false。原来 activeMode 取 `editing ? mode : currentMode`,
793
+ // 于是选了 WebDAV 之后字段不跟着切 —— 显示的还是 Git 那套(远端地址 / SSH 私钥),
794
+ // 保存时校验按 webdav 走,报「请填写 WebDAV 地址」,用户根本填不到那个框。
795
+ // 现在由 isEditing 决定,强制编辑态也跟随下拉框。
796
+ const isEditing = editing || (!wdConfigured && !gitConfigured && Boolean(props.data))
797
+ const activeMode = isEditing ? mode : currentMode
762
798
  const missing = Boolean(props.data) && (
763
799
  activeMode === 'webdav' ? !wdConfigured
764
800
  : (activeMode === 'git' ? !gitConfigured : (!wdConfigured && !gitConfigured))
765
801
  )
766
- const isEditing = editing || (!wdConfigured && !gitConfigured && Boolean(props.data))
767
802
 
768
803
  const sourceLabel = (s) => s === 'settings' ? M('本机设置', 'Machine settings')
769
804
  : (s === 'git' ? M('git 配置', 'git config')
@@ -774,6 +809,7 @@ window.__ModuleLoader__.load({
774
809
  setWdUrl(currentWdUrl)
775
810
  setWdUser(currentWdUser)
776
811
  setWdDir(currentWdDir)
812
+ setWdUa(currentWdUa)
777
813
  setWdPass('')
778
814
  setGitUrl(currentGitUrl)
779
815
  setGitKey(currentGitKey)
@@ -784,6 +820,7 @@ window.__ModuleLoader__.load({
784
820
  setWdUrl(currentWdUrl)
785
821
  setWdUser(currentWdUser)
786
822
  setWdDir(currentWdDir)
823
+ setWdUa(currentWdUa)
787
824
  setWdPass('')
788
825
  setGitUrl(currentGitUrl)
789
826
  setGitKey(currentGitKey)
@@ -802,13 +839,19 @@ window.__ModuleLoader__.load({
802
839
  if (mode === 'auto' && !wdUrl.trim() && !gitUrl.trim()) {
803
840
  throw new Error(M('自动模式下请至少填写 WebDAV 地址或 Git 远端地址', 'In Auto mode, provide at least a WebDAV URL or a Git remote URL'))
804
841
  }
805
- await callWebdav({ action: 'save', url: wdUrl, user: wdUser, dir: wdDir, mode, pass: wdPass })
842
+ await callWebdav({ action: 'save', url: wdUrl, user: wdUser, dir: wdDir, mode, pass: wdPass, userAgent: wdUa })
806
843
  let gitSet = false
807
- const gitDirty = gitUrl.trim() !== currentGitUrl.trim() || gitKey.trim() !== currentGitKey.trim()
844
+ // 0.6.49 修复:选了 WebDAV 就不该再动 git 设置。原来这里不看模式,
845
+ // 用户在「远端地址」里先前填过的 DAV 地址会被当成 git 远端存下去,
846
+ // 随后 git remote set-url 失败、整套回滚,报一个跟 WebDAV 毫无关系的错。
847
+ const gitDirty = mode !== 'webdav'
848
+ && (gitUrl.trim() !== currentGitUrl.trim() || gitKey.trim() !== currentGitKey.trim())
808
849
  if (gitDirty && (gitUrl.trim() || currentGitUrl.trim() || gitKey.trim() || currentGitKey.trim())) {
809
850
  const r = await callSettings({ remoteUrl: gitUrl, sshKey: gitKey })
810
851
  gitSet = Boolean(r && r.gitRemoteSet)
811
852
  }
853
+ // 注意:这里**不清空** Git 那两格的本地 state —— 用户可能只是临时切到 WebDAV,
854
+ // 清掉会让「再切回 Git」时私钥路径凭空消失(磁盘上的值还在,但看起来像丢了)。
812
855
  setEditing(false); setWdPass('')
813
856
  setMsg(M(
814
857
  `已保存${gitSet ? ',并已更新本机 git origin' : ''}`,
@@ -824,7 +867,29 @@ window.__ModuleLoader__.load({
824
867
  try {
825
868
  const r = await callWebdav({ action })
826
869
  const res = r.result || r
827
- if (res.ok === false) throw new Error(res.error || M('操作失败', 'Operation failed'))
870
+ if (res.ok === false) {
871
+ // 0.6.48:失败时把「该改哪一项」直接摊开(服务端已按状态码给出可执行的文案),
872
+ // 并且顺带报出实际发出去的 UA —— 排查 UA 拦截时这是第一个要确认的事实。
873
+ const parts = [String(res.error || M('操作失败', 'Operation failed'))]
874
+ // 上传/下载的失败原因在 errors 数组里(每条一个文件),
875
+ // 只报一句「操作失败」等于把服务端刚给出的诊断又丢了。
876
+ if (Array.isArray(res.errors) && res.errors.length) {
877
+ parts.push(res.errors.slice(0, 5).join(';'))
878
+ }
879
+ if (action === 'test' && res.userAgent !== undefined) {
880
+ parts.push(M(`本次 User-Agent:${res.userAgent || '(未发送)'}`, `User-Agent sent: ${res.userAgent || '(none)'}`))
881
+ }
882
+ throw new Error(parts.join(' · '))
883
+ }
884
+ if (action === 'test') {
885
+ const n = res.files ?? (res.rootFiles || 0) + (res.rootDirs || 0)
886
+ setMsg(M(
887
+ `连通正常:云端根目录 ${n} 项${res.exists === false ? '(目录还不存在,首次推送会自动创建)' : ''}${res.userAgent ? ` · UA ${res.userAgent}` : ' · 未发送 User-Agent'}`,
888
+ `Connected: ${n} item(s) at the cloud root${res.exists === false ? ' (folder does not exist yet; the first push creates it)' : ''}${res.userAgent ? ` · UA ${res.userAgent}` : ' · no User-Agent sent'}`,
889
+ ))
890
+ if (typeof props.onSaved === 'function') props.onSaved()
891
+ return
892
+ }
828
893
  setMsg(M(
829
894
  `完成:上传 ${res.uploaded || 0} · 下载 ${res.downloaded || 0} · 跳过 ${res.skipped || 0} · 冲突 ${res.conflicts || 0}`,
830
895
  `Done: uploaded ${res.uploaded || 0} · downloaded ${res.downloaded || 0} · skipped ${res.skipped || 0} · conflicts ${res.conflicts || 0}`,
@@ -898,6 +963,12 @@ window.__ModuleLoader__.load({
898
963
  v: st.hasPassword ? M('已设置(不回显)', 'set (not shown)') : M('未设置', 'not set'),
899
964
  }),
900
965
  field(M('远端目录', 'Remote dir'), isEditing ? wdDir : currentWdDir, setWdDir, 'dsh-config-sync'),
966
+ // 0.6.48:UA。第三方 DAV 常按客户端名放行/拦截,默认 undici UA 会被 401/403。
967
+ field(M('User-Agent', 'User-Agent'), isEditing ? wdUa : currentWdUa, setWdUa, M('留空 = 不发(默认)', 'blank = do not send')),
968
+ isEditing
969
+ ? h('div', { style: { ...S.footnote, marginTop: '-2px' } }, M(
970
+ '部分第三方 WebDAV(群晖 / 坚果云 / 自建 DAV)会按客户端 User-Agent 放行或拦截;连不上且报 403 时,填它要求的客户端名(如 Mozilla/5.0 或 davfs2)。留空则不发 User-Agent。',
971
+ 'Some third-party WebDAV servers (Synology / Jianguoyun / self-hosted DAV) allow or block by client User-Agent; if you get 403, put the client name they expect (e.g. Mozilla/5.0 or davfs2). Leave blank to send no User-Agent.')) : null,
901
972
  h(Kv, {
902
973
  k: M('传输安全', 'Transport'),
903
974
  v: (st.secure === false)
@@ -1104,7 +1175,11 @@ window.__ModuleLoader__.load({
1104
1175
  isEditing
1105
1176
  ? h('input', {
1106
1177
  type: 'text', style: S.input, value: path, spellCheck: false,
1107
- placeholder: M('D:\\dsh-config(那台机器上装仓库的目录)', 'D:\\dsh-config (directory holding the repo on this machine)'),
1178
+ // 0.6.49:占位符随平台走 —— 原来一律是 D:\dsh-config,
1179
+ // macOS 用户照着填会在本机建出一个叫 `D:\dsh-config` 的目录(实测踩过)。
1180
+ placeholder: isWindowsLike(props.data)
1181
+ ? M('D:\\dsh-config(那台机器上装仓库的目录)', 'D:\\dsh-config (directory holding the repo on this machine)')
1182
+ : M('/Users/你/dsh-config(那台机器上装仓库的目录)', '/Users/you/dsh-config (directory holding the repo on this machine)'),
1108
1183
  onChange: (e) => setPath(e.target.value),
1109
1184
  })
1110
1185
  : h('div', { style: { ...S.kvVal, fontFamily: 'Consolas, ui-monospace, monospace' } }, repo.path || M('(未配置)', '(not set)')),
@@ -1167,8 +1242,8 @@ window.__ModuleLoader__.load({
1167
1242
  ))
1168
1243
  : null,
1169
1244
  h('div', { style: S.footnote }, M(
1170
- '路径只存本机设置文件(~\\.dsh\\dsh-config-sync.json),不进仓库,各机器各配各的。',
1171
- 'The path lives only in the local settings file (~\\.dsh\\dsh-config-sync.json), never in the repo.',
1245
+ '路径只存本机设置文件(~/.dsh/dsh-config-sync.json),不进仓库,各机器各配各的。',
1246
+ 'The path lives only in the local settings file (~/.dsh/dsh-config-sync.json), never in the repo.',
1172
1247
  )),
1173
1248
  forced
1174
1249
  ? h('div', { style: { ...S.hint, color: 'var(--dsw-alias-state-error-primary)' } },
@@ -2280,6 +2355,9 @@ window.__ModuleLoader__.load({
2280
2355
  const excluded = items.filter((i) => i.enabled === false).length
2281
2356
  const expanded = open[g.id] === true
2282
2357
  const groupOn = g.enabled !== false
2358
+ // 0.6.49:宿主会按平台告诉这一组「本机引擎到底会不会同步」(非 Windows 只有四组)。
2359
+ // 不支持的组一律禁用勾选并标注原因 —— 让人勾着却永远不生效是最糟的那种"看起来能用"。
2360
+ const supported = g.supported !== false
2283
2361
  const canExpand = items.length > 0
2284
2362
  return h('div', {
2285
2363
  key: g.id,
@@ -2296,10 +2374,13 @@ window.__ModuleLoader__.load({
2296
2374
  }, expanded ? '▾' : '▸')
2297
2375
  : h('span', { style: { flexShrink: 0, width: '10px' } }),
2298
2376
  h('input', {
2299
- type: 'checkbox', checked: groupOn, disabled: busy || !editing || g.required === true,
2300
- title: g.required === true
2301
- ? M('必需内容:取消会让另一台机器拉取时直接报错', 'Required: unchecking it makes the other machine fail on pull')
2302
- : (editing ? '' : M('只读:先点「修改」', 'Read-only: click Edit first')),
2377
+ type: 'checkbox', checked: groupOn,
2378
+ disabled: busy || !editing || g.required === true || !supported,
2379
+ title: !supported
2380
+ ? M('此平台暂不支持:要 Windows 版才会同步这一组', 'Not supported on this platform yet — this group syncs on Windows')
2381
+ : (g.required === true
2382
+ ? M('必需内容:取消会让另一台机器拉取时直接报错', 'Required: unchecking it makes the other machine fail on pull')
2383
+ : (editing ? '' : M('只读:先点「修改」', 'Read-only: click Edit first'))),
2303
2384
  onClick: (e) => e.stopPropagation(), // 勾选别当成"点行展开"
2304
2385
  onChange: () => toggleGroup(g.id), style: { flexShrink: 0 },
2305
2386
  }),
@@ -2310,7 +2391,9 @@ window.__ModuleLoader__.load({
2310
2391
  color: groupOn ? 'var(--dsw-alias-label-primary)' : 'var(--dsw-alias-label-tertiary)',
2311
2392
  textDecoration: groupOn ? 'none' : 'line-through',
2312
2393
  },
2313
- }, g.required === true ? `${g.title} · ${M('必需', 'required')}` : g.title),
2394
+ }, g.required === true
2395
+ ? `${g.title} · ${M('必需', 'required')}`
2396
+ : (supported ? g.title : `${g.title} · ${M('此平台暂不支持', 'not on this platform')}`)),
2314
2397
  g.desc
2315
2398
  ? h('div', { style: S.footnote },
2316
2399
  g.required === true
@@ -2402,17 +2485,9 @@ window.__ModuleLoader__.load({
2402
2485
  })
2403
2486
  }
2404
2487
  try {
2405
- const res = await fetch('/config-sync/auto', {
2406
- method: 'POST', cache: 'no-store', credentials: 'same-origin',
2407
- headers: jsonHeaders(),
2408
- body: JSON.stringify({ action, ...(extra || {}) }),
2409
- })
2410
- const text = await res.text()
2411
- let body
2412
- // 这一处原来是全文件唯一没有 try 的 JSON.parse:宿主代理回一页 HTML 错误时,
2413
- // 用户看到的是 "Unexpected token '<'" 这种噪声,而不是「500 返回非 JSON」。
2414
- try { body = text ? JSON.parse(text) : null } catch { throw badJson(res) }
2415
- if (!res.ok || !body || body.ok !== true) throw new Error((body && body.error) || `${res.status}`)
2488
+ // 0.6.49:走 autoFetch —— 需要确认时在面板里问,不再依赖宿主弹的原生框
2489
+ const body = await autoFetch({ action, ...(extra || {}) })
2490
+ if (body && body.cancelled) { setBusy(''); setMsg(M('已取消', 'Cancelled')); return }
2416
2491
  if (action === 'check') {
2417
2492
  const d = body.drift
2418
2493
  setMsg(d
@@ -2519,10 +2594,21 @@ window.__ModuleLoader__.load({
2519
2594
  + `${pendingReason ? `, reason: ${pendingReason}` : ''})`,
2520
2595
  ))
2521
2596
  : null,
2597
+ // 0.6.49:后台自动拉取在 macOS 上不再弹原生框(启动时的对话框常被窗口挡住,
2598
+ // 用户看不见就等于永不发生)。宿主把提示挂进 status.auto.pullPrompt,这里明说一句,
2599
+ // 让用户知道「该点下面那个按钮」——而不是以为自动同步在工作。
2600
+ auto.pullPrompt && !pending
2601
+ ? h('div', { style: { ...S.hint, color: 'var(--dsw-alias-state-warn-primary)' } },
2602
+ M(
2603
+ `云端领先 ${auto.pullPrompt.behind} 个提交:自动拉取需要你点一下「立即拉取」(退出后才会执行)`,
2604
+ `The cloud is ${auto.pullPrompt.behind} commit(s) ahead — click "Pull now" to sync (it runs after DSH exits)`,
2605
+ ))
2606
+ : null,
2522
2607
  !auto.script
2523
2608
  ? h('div', { style: { ...S.hint, color: 'var(--dsw-alias-state-warn-primary)' } },
2524
- M('找不到 post-exit.ps1:自动同步排不了队,重装插件即可',
2525
- 'post-exit.ps1 is missing from both the plugin and the repo, so auto sync cannot queue — reinstall the plugin (the current package ships runtime/)'))
2609
+ // 0.6.49:执行体名随平台(Windows post-exit.ps1 / macOS、Linux post-exit.mjs)
2610
+ M(`找不到 ${isWindowsLike(data) ? 'post-exit.ps1' : 'post-exit.mjs'}:自动同步排不了队,重装插件即可`,
2611
+ `${isWindowsLike(data) ? 'post-exit.ps1' : 'post-exit.mjs'} is missing from both the plugin and the repo, so auto sync cannot queue — reinstall the plugin (the current package ships runtime/)`))
2526
2612
  : null,
2527
2613
  h('div', { style: S.actions },
2528
2614
  h('button', {
@@ -2742,10 +2828,8 @@ window.__ModuleLoader__.load({
2742
2828
  const [toast, setToast] = react.useState('')
2743
2829
  const [upd, setUpd] = react.useState(null)
2744
2830
  const [updBusy, setUpdBusy] = react.useState(false)
2745
- // 「插件更新」卡里的配置编辑态:清单地址 + 只读令牌都放这一张卡,不散到云端仓库那去
2746
- const [updEdit, setUpdEdit] = react.useState(false)
2747
- const [updManifest, setUpdManifest] = react.useState('')
2748
- const [updToken, setUpdToken] = react.useState('')
2831
+ // 0.6.47:更新源固定是 npm,「更新清单地址 / 更新令牌」两项配置撤掉,
2832
+ // 所以这里不再有编辑态与对应输入框。旧的本机设置仍留在配置文件里,不主动删。
2749
2833
  const [updMsg, setUpdMsg] = react.useState('')
2750
2834
  const [updErr, setUpdErr] = react.useState('')
2751
2835
  // 「本机路径」平时不占版面:只在标题行按钮被点开时才渲染;按钮本身在
@@ -2910,40 +2994,9 @@ window.__ModuleLoader__.load({
2910
2994
  setUpdBusy(false)
2911
2995
  }
2912
2996
  }
2913
-
2914
- const startEditUpd = () => {
2915
- const cfg = (upd && upd.config) || {}
2916
- setUpdManifest(cfg.manifestUrlIsDefault ? '' : (cfg.manifestUrl || ''))
2917
- setUpdToken('')
2918
- setUpdErr('')
2919
- setUpdMsg('')
2920
- setUpdEdit(true)
2921
- }
2922
- const cancelEditUpd = () => { setUpdEdit(false); setUpdErr(''); setUpdToken('') }
2923
- const saveUpdConfig = async () => {
2924
- setUpdBusy(true); setUpdErr(''); setUpdMsg('')
2925
- try {
2926
- const payload = { updateManifestUrl: updManifest.trim() }
2927
- if (updToken.trim()) payload.updateToken = updToken.trim()
2928
- await callSettings(payload)
2929
- setUpdEdit(false)
2930
- setUpdToken('')
2931
- setUpdMsg(M('已保存', 'Saved'))
2932
- setUpd(await callUpdate({ action: 'check' }))
2933
- } catch (e) {
2934
- setUpdErr(String((e && e.message) || e))
2935
- } finally { setUpdBusy(false) }
2936
- }
2937
- const clearUpdToken = async () => {
2938
- setUpdBusy(true); setUpdErr(''); setUpdMsg('')
2939
- try {
2940
- await callSettings({ clearUpdateToken: true })
2941
- setUpdMsg(M('已清除本机保存的更新令牌', 'Cleared the update token stored on this machine'))
2942
- setUpd(await callUpdate({ action: 'check' }))
2943
- } catch (e) {
2944
- setUpdErr(String((e && e.message) || e))
2945
- } finally { setUpdBusy(false) }
2946
- }
2997
+ // 0.6.47:更新源固定是 npm,不再有「更新清单地址 / 更新令牌」可配。
2998
+ // 旧的设置项仍留在本机配置文件里(不主动删用户填过的东西),但更新检查不读它们。
2999
+ // 需要换源时用 npm 自己的 registry 配置(.npmrc),不在插件里另开一套。
2947
3000
 
2948
3001
  // 打开面板就自动检查一次云端,之后每 2 分钟复查一次(只读,不改仓库、不动 profile)
2949
3002
  react.useEffect(() => {
@@ -3131,8 +3184,8 @@ window.__ModuleLoader__.load({
3131
3184
  `Current ${local} → can update to ${remote}${notesText ? ` · ${notesText}` : ''}`,
3132
3185
  )
3133
3186
  : (failed
3134
- ? M(`读不到更新清单:${u.error || '未知原因'}${sourceNote}`, `Cannot read the manifest: ${u.error || 'unknown reason'}${sourceNote}`)
3135
- : (u.checkedAt ? M(`当前 ${local},云端没有更新的版本`, `Current ${local}; no newer version upstream`) : M('正在读云端版本清单…', 'Reading the cloud manifest…')))))
3187
+ ? M(`读不到 npm 上的版本信息:${u.error || '未知原因'}${sourceNote}`, `Cannot read the version info from npm: ${u.error || 'unknown reason'}${sourceNote}`)
3188
+ : (u.checkedAt ? M(`当前 ${local},npm 上没有更新的版本`, `Current ${local}; no newer version on npm`) : M('正在读 npm 上的版本…', 'Reading the version list from npm…')))))
3136
3189
  return h('div', { style: S.card },
3137
3190
  h('div', { style: S.cardHead },
3138
3191
  h('div', { style: S.cardTitle }, M('插件更新', 'Plugin update')),
@@ -3154,90 +3207,38 @@ window.__ModuleLoader__.load({
3154
3207
  onClick: downloadUpdate,
3155
3208
  }, updBusy ? M('下载中…', 'Downloading…') : M(`下载更新 ${remote}`, `Download ${remote}`)) : null)),
3156
3209
  h('button', { type: 'button', style: S.btn, disabled: updBusy, onClick: checkUpdateNow }, M('检查更新', 'Check for updates')),
3157
- updEdit
3158
- ? null
3159
- : h('button', { type: 'button', style: S.btn, disabled: !u.local, onClick: startEditUpd }, M('修改配置', 'Edit config')),
3160
3210
  ),
3161
3211
  ),
3162
3212
  h('div', { style: S.hint }, text),
3163
- updEdit
3164
- ? h('div', null,
3165
- h('div', { style: S.kvRow },
3166
- h('div', { style: S.kvKey }, M('更新清单', 'Manifest')),
3167
- h('input', {
3168
- type: 'text', style: S.input, value: updManifest, spellCheck: false,
3169
- placeholder: cfg.manifestUrlIsDefault
3170
- ? M(`留空 = 用内置默认(${cfg.manifestUrl || ''})`, `Leave empty = built-in default (${cfg.manifestUrl || ''})`)
3171
- : 'https://…/version.json',
3172
- onChange: (e) => setUpdManifest(e.target.value),
3173
- }),
3174
- ),
3175
- h('div', { style: S.kvRow },
3176
- h('div', { style: S.kvKey }, M('更新令牌', 'Token')),
3177
- h('input', {
3178
- type: 'text', style: S.input, value: updToken, spellCheck: false,
3179
- placeholder: cfg.tokenSet
3180
- ? M('已配置;留空表示不改(支持 $GITHUB_TOKEN 读取环境变量)', 'Already set; leave empty to keep (or enter $GITHUB_TOKEN for env var)')
3181
- : M('GitHub / Gitee 令牌,或填 $GITHUB_TOKEN 读取本机环境变量', 'GitHub / Gitee token, or $GITHUB_TOKEN to read from env'),
3182
- onChange: (e) => setUpdToken(e.target.value),
3183
- }),
3184
- ),
3185
- h('div', { style: S.actions },
3186
- h('button', { type: 'button', style: S.btnPrimary, disabled: updBusy, onClick: saveUpdConfig }, updBusy ? M('保存中…', 'Saving…') : M('保存', 'Save')),
3187
- h('button', { type: 'button', style: S.btn, disabled: updBusy, onClick: cancelEditUpd }, M('取消', 'Cancel')),
3188
- cfg.tokenSaved
3189
- ? h('button', { type: 'button', style: S.btn, disabled: updBusy, onClick: clearUpdToken }, M('清除已存令牌', 'Clear stored token'))
3190
- : null,
3191
- ),
3192
- )
3193
- : h('div', null,
3194
- h(Kv, {
3195
- k: M('更新清单', 'Manifest'),
3196
- v: cfg.manifestUrlIsDefault
3197
- ? M('内置默认(GitHub API / gh-proxy / ghfast / GitHub raw 依次尝试)', 'Built-in default (GitHub API / gh-proxy / ghfast / GitHub raw in order)')
3198
- : (cfg.manifestUrl || '…'),
3199
- }),
3200
- h(Kv, {
3201
- k: M('更新源', 'Source'),
3202
- v: u.sourceUsed
3203
- ? u.sourceUsed
3204
- : M('本次检查还没读到清单', 'No source reached yet'),
3205
- }),
3206
- h(Kv, {
3207
- k: M('更新令牌', 'Token'),
3208
- v: cfg.tokenSource === 'env' && cfg.tokenEnv
3209
- ? M(`已从环境变量 ${cfg.tokenEnv} 读取(不落盘、绝不推送)`, `From env var ${cfg.tokenEnv} (not stored, never pushed)`)
3210
- : cfg.tokenSource === 'git-credential'
3211
- ? M('已从本机 git 凭据自动读取(不落盘、绝不推送)', 'From local git credential (not stored, never pushed)')
3212
- : cfg.tokenSource === 'gh-cli'
3213
- ? M('已从 GitHub CLI (gh) 自动读取(不落盘、绝不推送)', 'From GitHub CLI (gh) (not stored, never pushed)')
3214
- : cfg.tokenSet
3215
- ? M('已配置(仅存本机,绝不推送)', 'Set (local only, never pushed)')
3216
- : M('未配置(公开库可不填;私有库可用本机 GitHub 登录、$GITHUB_TOKEN 或填入令牌)', 'Not set (optional for public repos; private repos use local GitHub login, $GITHUB_TOKEN, or a token)'),
3217
- }),
3218
- u.remote && u.remote.npmTgzUrls && u.remote.npmTgzUrls.length
3219
- ? h(Kv, {
3220
- k: M('npm 下载路径', 'npm download URL'),
3221
- v: h('span', { style: { display: 'inline-flex', flexDirection: 'column', gap: '2px' } },
3222
- u.remote.npmTgzUrls.map((url, i) =>
3223
- h('span', { key: i, title: url }, url)
3224
- )
3225
- ),
3226
- })
3227
- : u.remote && u.remote.npmTgz
3228
- ? h(Kv, {
3229
- k: M('npm 下载路径', 'npm download URL'),
3230
- v: u.remote.npmTgz,
3231
- })
3232
- : null,
3233
- ),
3213
+ h('div', null,
3214
+ h(Kv, {
3215
+ k: M('更新源', 'Source'),
3216
+ v: M('npm(只查 npm,不查 GitHub)', 'npm only (GitHub is not checked)'),
3217
+ }),
3218
+ h(Kv, {
3219
+ k: M('npm 包', 'npm package'),
3220
+ v: (cfg.packageName || 'dsh-profile-config-sync'),
3221
+ }),
3222
+ h(Kv, {
3223
+ k: M('本次查询', 'Last query'),
3224
+ v: u.sourceUsed
3225
+ ? u.sourceUsed
3226
+ : M('本次检查还没读到版本信息', 'No version info reached yet'),
3227
+ }),
3228
+ u.remote && u.remote.npmTgz
3229
+ ? h(Kv, {
3230
+ k: M('下载地址', 'Download URL'),
3231
+ v: u.remote.npmTgz,
3232
+ })
3233
+ : null,
3234
+ ),
3234
3235
  h('div', { style: S.footnote },
3235
3236
  M(
3236
- '下载只写 update-staging 并校验 sha256,插件目录不动;「重启并安装」在退出后覆盖安装并自动重开,失败自动回滚。令牌只存本机。',
3237
- 'Download only writes to update-staging and verifies sha256; "Restart & install" overwrites after exit and relaunches, rolling back on failure. The token stays local.',
3237
+ '更新只查 npm registry,不看 GitHub。下载只写 update-staging 并按 npm 给的 integrity 校验,插件目录不动;「重启并安装」在退出后覆盖安装并自动重开,失败自动回滚。',
3238
+ 'Updates are checked against the npm registry only, never GitHub. The download only writes to update-staging and is verified with the integrity value npm provides; "Restart & install" overwrites after exit and relaunches, rolling back on failure.',
3238
3239
  )),
3239
- updErr ? h('div', { style: { ...S.footnote, color: 'var(--dsw-alias-state-error-primary)' } }, M(`保存失败:${updErr}`, `Save failed: ${updErr}`)) : null,
3240
3240
  updMsg ? h('div', { style: { ...S.footnote, color: 'var(--dsw-alias-state-success-primary)' } }, updMsg) : null,
3241
+ updErr ? h('div', { style: { ...S.footnote, color: 'var(--dsw-alias-state-error-primary)' } }, updErr) : null,
3241
3242
  )
3242
3243
  })()
3243
3244
 
@@ -3872,10 +3873,62 @@ window.__ModuleLoader__.load({
3872
3873
  const [busy, setBusy] = react.useState(false)
3873
3874
  const [msg, setMsg] = react.useState('')
3874
3875
  const [err, setErr] = react.useState('')
3876
+ // 0.6.48(issue #9):附件(图片 / 视频 / 日志)。选文件后读成 base64 跟着提交走,
3877
+ // 服务端传到仓库的 release assets,正文引用 —— 不借道第三方图床。
3878
+ const [files, setFiles] = react.useState([])
3875
3879
  // 筛选:状态走本地过滤(一次拉全量、计数才准),关键词也本地过,输入即筛,不打接口
3876
3880
  const [filter, setFilter] = react.useState('open')
3877
3881
  const [kw, setKw] = react.useState('')
3878
3882
 
3883
+ const MAX_ATTACH = 4
3884
+ const MAX_ATTACH_MB = 20
3885
+ const ATTACH_OK = /\.(png|jpe?g|gif|webp|bmp|svg|mp4|mov|webm|log|txt|md|json)$/i
3886
+
3887
+ /** 读一个 File 成 base64(去掉 data: 前缀)。FileReader 在面板进程里可用。 */
3888
+ const readAsBase64 = (file) => new Promise((resolve, reject) => {
3889
+ try {
3890
+ const fr = new FileReader()
3891
+ fr.onload = () => {
3892
+ const s = String(fr.result || '')
3893
+ const comma = s.indexOf(',')
3894
+ resolve(comma >= 0 ? s.slice(comma + 1) : '')
3895
+ }
3896
+ fr.onerror = () => reject(new Error(String((fr.error && fr.error.message) || 'read failed')))
3897
+ fr.readAsDataURL(file)
3898
+ } catch (e) { reject(e) }
3899
+ })
3900
+
3901
+ const addFiles = async (list) => {
3902
+ const picked = Array.from(list || [])
3903
+ if (!picked.length) return
3904
+ setErr(''); setMsg('')
3905
+ const next = [...files]
3906
+ const problems = []
3907
+ for (const f of picked) {
3908
+ if (next.length >= MAX_ATTACH) { problems.push(M(`附件最多 ${MAX_ATTACH} 个`, `At most ${MAX_ATTACH} attachments`)); break }
3909
+ if (!ATTACH_OK.test(f.name || '')) {
3910
+ problems.push(M(`${f.name}:不支持的类型(只收图片 / 视频 / 日志)`, `${f.name}: unsupported type (images, videos, logs only)`))
3911
+ continue
3912
+ }
3913
+ if ((f.size || 0) > MAX_ATTACH_MB * 1024 * 1024) {
3914
+ problems.push(M(`${f.name}:超过 ${MAX_ATTACH_MB} MB`, `${f.name}: larger than ${MAX_ATTACH_MB} MB`))
3915
+ continue
3916
+ }
3917
+ try {
3918
+ const data = await readAsBase64(f)
3919
+ if (!data) { problems.push(M(`${f.name}:读不出内容`, `${f.name}: cannot read content`)); continue }
3920
+ next.push({ name: f.name || 'attachment', size: f.size || 0, type: f.type || '', data })
3921
+ } catch (e) {
3922
+ problems.push(M(`${f.name}:${String((e && e.message) || e)}`, `${f.name}: ${String((e && e.message) || e)}`))
3923
+ }
3924
+ }
3925
+ setFiles(next)
3926
+ if (problems.length) setErr(problems.join(';'))
3927
+ else if (next.length > files.length) setMsg(M(`已加 ${next.length - files.length} 个附件(点「提交到 GitHub」一起发)`, `Added ${next.length - files.length} attachment(s) — they go with the report`))
3928
+ }
3929
+
3930
+ const removeFile = (idx) => { setFiles(files.filter((_, i) => i !== idx)); setErr(''); setMsg('') }
3931
+
3879
3932
  const load = async (forceRefresh = false) => {
3880
3933
  setBusy(true)
3881
3934
  try {
@@ -3892,18 +3945,37 @@ window.__ModuleLoader__.load({
3892
3945
  const submit = async () => {
3893
3946
  setBusy(true); setErr(''); setMsg('')
3894
3947
  try {
3895
- const r = await callFeedback({ title, body: text })
3948
+ // 只把 { name, type, data } 发出去:size 是本机展示用的,服务端不需要
3949
+ const attachments = files.map((f) => ({ name: f.name, type: f.type, data: f.data }))
3950
+ const r = await callFeedback({ title, body: text, attachments })
3951
+ const attachNote = (r && Array.isArray(r.attachmentErrors) && r.attachmentErrors.length)
3952
+ ? M(`;有附件没传上去:${r.attachmentErrors.join('、')}`, `; some attachments failed: ${r.attachmentErrors.join(', ')}`)
3953
+ : ''
3896
3954
  if (r && r.needToken && r.fallbackUrl) {
3897
3955
  // 没有令牌:把这单交给浏览器——预填好标题/正文/环境块,登录状态下点一下就建好了
3898
3956
  try { window.open(r.fallbackUrl, '_blank', 'noopener') } catch { }
3899
- setMsg(M('没有令牌,已打开浏览器里的新建 issue 页面(标题和正文都填好了),点一下提交即可。', 'No token: opened the prefilled new-issue page in the browser - press submit there.'))
3957
+ const pending = (r.pendingAttachments || []).length
3958
+ ? M(
3959
+ `;附件(${(r.pendingAttachments || []).join('、')})没能上传,请在页面里手动拖进正文`,
3960
+ `; attachments (${(r.pendingAttachments || []).join(', ')}) were not uploaded — drag them into the body`,
3961
+ )
3962
+ : ''
3963
+ setMsg(M('没有令牌,已打开浏览器里的新建 issue 页面(标题和正文都填好了),点一下提交即可。', 'No token: opened the prefilled new-issue page in the browser - press submit there.') + pending + attachNote)
3964
+ setFiles([])
3900
3965
  } else if (r && r.number) {
3901
- setMsg(M(`已建 Issue #${r.number},列表里能看到,网页上也点得开。`, `Issue #${r.number} created; it shows in the list and opens in the browser.`))
3966
+ const n = (r.attachments || []).length
3967
+ setMsg(M(
3968
+ `已建 Issue #${r.number},列表里能看到,网页上也点得开。${n ? `(带了 ${n} 个附件)` : ''}`,
3969
+ `Issue #${r.number} created; it shows in the list and opens in the browser.${n ? ` (${n} attachment(s))` : ''}`,
3970
+ ) + attachNote)
3902
3971
  setTitle('')
3903
3972
  setText('')
3973
+ setFiles([])
3904
3974
  } else {
3975
+ const kept = (r && (r.attachments || []).length) ? M('(附件已上传,补发时会自动引用)', '(attachments uploaded; Flush will reference them)') : ''
3905
3976
  setMsg(M(`没连上 GitHub(${(r && r.error) || '网络不通'}),已存进本机待发队列(${r ? r.remaining : 0} 条),联网后点「补发」。`,
3906
- `Could not reach GitHub (${(r && r.error) || 'network'}). Saved to the local queue (${r ? r.remaining : 0} item(s)); press Flush when online.`))
3977
+ `Could not reach GitHub (${(r && r.error) || 'network'}). Saved to the local queue (${r ? r.remaining : 0} item(s)); press Flush when online.`) + kept + attachNote)
3978
+ if (!(r && (r.attachments || []).length)) setFiles([])
3907
3979
  }
3908
3980
  await load()
3909
3981
  } catch (e) {
@@ -4113,6 +4185,37 @@ window.__ModuleLoader__.load({
4113
4185
  onChange: (e) => setText(e.target.value),
4114
4186
  }),
4115
4187
  ),
4188
+ // 0.6.48(issue #9):附件。截图 / 录屏是「界面不对」「同步报错」这类反馈里最关键的证据,
4189
+ // 以前只能靠打字描述。选完文件后读成 base64 跟提交一起发,服务端传到仓库资产、正文引用。
4190
+ h('div', { style: S.kvRow },
4191
+ h('div', { style: S.kvKey }, M('附件', 'Attachments')),
4192
+ h('div', { style: { ...S.kvVal, display: 'flex', flexDirection: 'column', gap: '6px' } },
4193
+ h('div', { style: { display: 'flex', gap: '8px', alignItems: 'center', flexWrap: 'wrap' } },
4194
+ h('input', {
4195
+ key: 'file', type: 'file', multiple: true, disabled: busy,
4196
+ accept: '.png,.jpg,.jpeg,.gif,.webp,.bmp,.svg,.mp4,.mov,.webm,.log,.txt,.md,.json',
4197
+ style: { fontSize: '12px' },
4198
+ onChange: (e) => { addFiles(e.target.files); try { e.target.value = '' } catch { } },
4199
+ }),
4200
+ h('span', { style: S.footnote }, M(
4201
+ `图片 / 视频 / 日志,最多 ${MAX_ATTACH} 个、每个 ${MAX_ATTACH_MB} MB`,
4202
+ `Images / videos / logs, up to ${MAX_ATTACH} files, ${MAX_ATTACH_MB} MB each`,
4203
+ )),
4204
+ ),
4205
+ files.length
4206
+ ? h('div', { style: { display: 'flex', flexDirection: 'column', gap: '2px' } },
4207
+ files.map((f, i) => h('div', { key: `${f.name}-${i}`, style: { display: 'flex', gap: '8px', alignItems: 'center', fontSize: '12px' } },
4208
+ h('span', { style: { flex: 1, minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, f.name),
4209
+ h('span', { style: S.footnote }, `${Math.max(1, Math.round((f.size || 0) / 1024))} KB`),
4210
+ h('button', { type: 'button', style: S.btn, disabled: busy, onClick: () => removeFile(i) }, M('移除', 'Remove')),
4211
+ )))
4212
+ : null,
4213
+ h('div', { style: S.footnote }, M(
4214
+ '附件会作为 GitHub 资产上传到本反馈仓库,Issue 正文引用它:换机器、别人看都能打开,不依赖你本机的文件还在。没有令牌时附件传不上去,会提示手动拖进网页。',
4215
+ 'Attachments are uploaded as assets of the feedback repo and referenced from the issue body: readable from any machine, no dependency on your local file. Without a token they cannot be uploaded, and you are told to drag them into the page.',
4216
+ )),
4217
+ ),
4218
+ ),
4116
4219
  h('div', { style: S.actions },
4117
4220
  h('button', { type: 'button', style: S.btnPrimary, disabled: busy || !title.trim(), onClick: submit },
4118
4221
  busy ? M('提交中…', 'Submitting…') : M('提交到 GitHub', 'Submit to GitHub')),