dsh-remote-plugin 0.8.5 → 0.8.7
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/apk/dsh-remote.apk +0 -0
- package/gateway.cjs +189 -21
- package/index.mjs +25 -1
- package/package.json +1 -1
- package/public/admin.html +29 -29
- package/public/admin.js +23 -5
- package/public/announcements.json +41 -0
- package/public/app.js +263 -26
- package/public/build.json +2 -2
- package/public/desktop/desktop.html +64 -62
- package/public/desktop/desktop.js +45 -9
- package/public/doctor.css +1 -1
- package/public/e2ee-transport.js +35 -11
- package/public/image-preview.js +112 -13
- package/public/index.html +80 -72
- package/public/operations.js +39 -7
- package/public/plugin.html +25 -25
- package/public/relay-autopair.js +60 -26
- package/public/relay-devices.js +11 -5
- package/public/relay-settings.css +9 -0
- package/public/relay-settings.js +67 -9
- package/public/skins/blue-fish/preview.html +3 -3
- package/public/skins/bocchi/preview.html +5 -5
- package/public/skins/kita/preview.html +6 -6
- package/public/skins/nijika/preview.html +6 -6
- package/public/skins/penguin/preview.html +3 -3
- package/public/skins/ryo/preview.html +6 -6
- package/public/styles.css +30 -0
- package/public/update.json +12 -12
- package/public/version.json +1 -1
- package/public/workflow.css +4 -3
- package/public/workflow.js +22 -13
- package/session-file.mjs +8 -3
- package/skills/dsh-remote-doctor/references/wiki/connection.md +3 -1
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
<!doctype html>
|
|
2
2
|
<html lang="zh-CN">
|
|
3
3
|
<head>
|
|
4
|
-
<meta name="dsh-remote-build" content="
|
|
4
|
+
<meta name="dsh-remote-build" content="7b7352352544bd35e441ffdb4de480368defbe9386c58dff9a6ed41c2318b2e3">
|
|
5
5
|
<meta charset="utf-8">
|
|
6
6
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
7
7
|
<title>DSH Remote · 桌面</title>
|
|
8
8
|
<script>/* 首帧前应用皮肤 */ (function(){try{var t=localStorage.getItem('dshTheme');if(t!=='default'&&t!=='dark'&&t!=='light'&&t!=='neutral'&&t!=='mono'&&t!=='fish'&&t!=='penguin'&&t!=='penguin-night'&&t!=='bocchi'&&t!=='nijika'&&t!=='ryo'&&t!=='kita'){t='fish'}}catch(e){t='fish'}document.documentElement.setAttribute('data-theme',t)})()</script>
|
|
9
|
-
<link rel="stylesheet" href="../theme-vars.css?dsr-build=
|
|
10
|
-
<link rel="stylesheet" href="desktop.css?dsr-build=
|
|
11
|
-
<link rel="stylesheet" href="../plugin-center.css?dsr-build=
|
|
12
|
-
<link rel="stylesheet" href="../skills.css?dsr-build=
|
|
13
|
-
<link rel="stylesheet" href="../doctor.css?dsr-build=
|
|
14
|
-
<link rel="stylesheet" href="../extensions.css?dsr-build=
|
|
15
|
-
<link rel="stylesheet" href="../insights.css?dsr-build=
|
|
16
|
-
<link rel="stylesheet" href="../workflow.css?dsr-build=
|
|
17
|
-
<link rel="stylesheet" href="../relay-settings.css?dsr-build=
|
|
18
|
-
<link rel="stylesheet" href="../subagents.css?dsr-build=
|
|
19
|
-
<link rel="stylesheet" href="../skins/blue-fish/skin.css?dsr-build=
|
|
20
|
-
<link rel="stylesheet" href="../skins/penguin/skin.css?dsr-build=
|
|
21
|
-
<link rel="stylesheet" href="../skins/bocchi/skin.css?dsr-build=
|
|
22
|
-
<link rel="stylesheet" href="../skins/kessoku/skin.css?dsr-build=
|
|
23
|
-
<link rel="stylesheet" href="../skins/nijika/skin.css?dsr-build=
|
|
24
|
-
<link rel="stylesheet" href="../skins/ryo/skin.css?dsr-build=
|
|
25
|
-
<link rel="stylesheet" href="../skins/kita/skin.css?dsr-build=
|
|
26
|
-
<link rel="stylesheet" href="../theme-picker.css?dsr-build=
|
|
9
|
+
<link rel="stylesheet" href="../theme-vars.css?dsr-build=7b7352352544bd35e441ffdb4de480368defbe9386c58dff9a6ed41c2318b2e3">
|
|
10
|
+
<link rel="stylesheet" href="desktop.css?dsr-build=7b7352352544bd35e441ffdb4de480368defbe9386c58dff9a6ed41c2318b2e3">
|
|
11
|
+
<link rel="stylesheet" href="../plugin-center.css?dsr-build=7b7352352544bd35e441ffdb4de480368defbe9386c58dff9a6ed41c2318b2e3">
|
|
12
|
+
<link rel="stylesheet" href="../skills.css?dsr-build=7b7352352544bd35e441ffdb4de480368defbe9386c58dff9a6ed41c2318b2e3">
|
|
13
|
+
<link rel="stylesheet" href="../doctor.css?dsr-build=7b7352352544bd35e441ffdb4de480368defbe9386c58dff9a6ed41c2318b2e3">
|
|
14
|
+
<link rel="stylesheet" href="../extensions.css?dsr-build=7b7352352544bd35e441ffdb4de480368defbe9386c58dff9a6ed41c2318b2e3">
|
|
15
|
+
<link rel="stylesheet" href="../insights.css?dsr-build=7b7352352544bd35e441ffdb4de480368defbe9386c58dff9a6ed41c2318b2e3">
|
|
16
|
+
<link rel="stylesheet" href="../workflow.css?dsr-build=7b7352352544bd35e441ffdb4de480368defbe9386c58dff9a6ed41c2318b2e3">
|
|
17
|
+
<link rel="stylesheet" href="../relay-settings.css?dsr-build=7b7352352544bd35e441ffdb4de480368defbe9386c58dff9a6ed41c2318b2e3">
|
|
18
|
+
<link rel="stylesheet" href="../subagents.css?dsr-build=7b7352352544bd35e441ffdb4de480368defbe9386c58dff9a6ed41c2318b2e3">
|
|
19
|
+
<link rel="stylesheet" href="../skins/blue-fish/skin.css?dsr-build=7b7352352544bd35e441ffdb4de480368defbe9386c58dff9a6ed41c2318b2e3">
|
|
20
|
+
<link rel="stylesheet" href="../skins/penguin/skin.css?dsr-build=7b7352352544bd35e441ffdb4de480368defbe9386c58dff9a6ed41c2318b2e3">
|
|
21
|
+
<link rel="stylesheet" href="../skins/bocchi/skin.css?dsr-build=7b7352352544bd35e441ffdb4de480368defbe9386c58dff9a6ed41c2318b2e3">
|
|
22
|
+
<link rel="stylesheet" href="../skins/kessoku/skin.css?dsr-build=7b7352352544bd35e441ffdb4de480368defbe9386c58dff9a6ed41c2318b2e3">
|
|
23
|
+
<link rel="stylesheet" href="../skins/nijika/skin.css?dsr-build=7b7352352544bd35e441ffdb4de480368defbe9386c58dff9a6ed41c2318b2e3">
|
|
24
|
+
<link rel="stylesheet" href="../skins/ryo/skin.css?dsr-build=7b7352352544bd35e441ffdb4de480368defbe9386c58dff9a6ed41c2318b2e3">
|
|
25
|
+
<link rel="stylesheet" href="../skins/kita/skin.css?dsr-build=7b7352352544bd35e441ffdb4de480368defbe9386c58dff9a6ed41c2318b2e3">
|
|
26
|
+
<link rel="stylesheet" href="../theme-picker.css?dsr-build=7b7352352544bd35e441ffdb4de480368defbe9386c58dff9a6ed41c2318b2e3">
|
|
27
27
|
</head>
|
|
28
28
|
<body>
|
|
29
29
|
<div class="ds-app" id="ds-app">
|
|
@@ -618,6 +618,7 @@
|
|
|
618
618
|
'ds.connPollTitle': '当前网络不支持实时推送,已降级为轮询(延迟数秒)',
|
|
619
619
|
'ds.currentServer': '{group} · {url}', 'ds.origin': '当前页面',
|
|
620
620
|
'ds.toastSent': '已发送', 'ds.toastCopied': '令牌已复制', 'ds.toastAuth': '令牌无效',
|
|
621
|
+
'ds.sendUnconfirmedSwitched': '连接已切换(原连接:{host})。上次操作结果未确认,可能已生效;请核对会话,并可在首页“查看回执”中查询。',
|
|
621
622
|
'ds.toastConnFailed': '连接失败', 'ds.toastOpFailed': '操作失败',
|
|
622
623
|
'ds.sessionsEmpty': '暂无会话', 'ds.loading': '加载中…',
|
|
623
624
|
'ds.historyRenderFailed': '部分记录显示失败,请重试',
|
|
@@ -748,6 +749,7 @@
|
|
|
748
749
|
'ds.connPollTitle': 'Realtime push is unavailable on this network; degraded to polling (a few seconds delay)',
|
|
749
750
|
'ds.currentServer': '{group} · {url}', 'ds.origin': 'this page',
|
|
750
751
|
'ds.toastSent': 'Sent', 'ds.toastCopied': 'Token copied', 'ds.toastAuth': 'Invalid token',
|
|
752
|
+
'ds.sendUnconfirmedSwitched': 'The connection changed (previous host: {host}). The last operation is unconfirmed and may have been applied. Check the conversation or open “Check receipts” on Home.',
|
|
751
753
|
'ds.toastConnFailed': 'Connection failed', 'ds.toastOpFailed': 'Operation failed',
|
|
752
754
|
'ds.sessionsEmpty': 'No sessions', 'ds.loading': 'Loading…',
|
|
753
755
|
'ds.historyRenderFailed': 'Some records could not be displayed. Retry.',
|
|
@@ -822,48 +824,48 @@
|
|
|
822
824
|
</div>
|
|
823
825
|
<div class="image-lightbox-hint" data-image-lightbox-hint>双击放大 · 点空白处关闭</div>
|
|
824
826
|
</div>
|
|
825
|
-
<script src="i18n.js?dsr-build=
|
|
826
|
-
<link rel="stylesheet" href="../genui.css?dsr-build=
|
|
827
|
-
<script src="../genui.js?dsr-build=
|
|
828
|
-
<script src="../chat-files.js?dsr-build=
|
|
829
|
-
<script src="../md.js?dsr-build=
|
|
830
|
-
<script src="../vendor/gsap/gsap.min.js?dsr-build=
|
|
831
|
-
<script src="../motion.js?dsr-build=
|
|
832
|
-
<script type="module" src="../morphicons-init.js?dsr-build=
|
|
833
|
-
<script src="../plugin-center.js?dsr-build=
|
|
834
|
-
<script src="../skills.js?dsr-build=
|
|
835
|
-
<script src="../insights.js?dsr-build=
|
|
836
|
-
<script src="../teams.js?dsr-build=
|
|
837
|
-
<script src="../task-board.js?dsr-build=
|
|
838
|
-
<script src="../extensions.js?dsr-build=
|
|
839
|
-
<script src="../sha256.js?dsr-build=
|
|
840
|
-
<script src="../diagnostics.js?dsr-build=
|
|
841
|
-
<script src="../doctor.js?dsr-build=
|
|
842
|
-
<script src="../history.js?dsr-build=
|
|
843
|
-
<script src="../activity.js?dsr-build=
|
|
844
|
-
<script src="../turn-results.js?dsr-build=
|
|
845
|
-
<script src="../image-cache.js?dsr-build=
|
|
846
|
-
<script src="../chat-copy.js?dsr-build=
|
|
847
|
-
<script src="../image-preview.js?dsr-build=
|
|
848
|
-
<script src="../link-check.js?dsr-build=
|
|
849
|
-
<script src="../network.js?dsr-build=
|
|
850
|
-
<script src="../operations.js?dsr-build=
|
|
851
|
-
<script src="../workflow.js?dsr-build=
|
|
852
|
-
<script src="../sponsor-entry.js?dsr-build=
|
|
853
|
-
<script src="../relay-devices.js?dsr-build=
|
|
854
|
-
<script src="../relay-settings.js?dsr-build=
|
|
855
|
-
<script src="../subagents.js?dsr-build=
|
|
856
|
-
<script src="../session-presets.js?dsr-build=
|
|
857
|
-
<script src="../permission-presets.js?dsr-build=
|
|
858
|
-
<script src="../approval-records.js?dsr-build=
|
|
859
|
-
<script src="../approval-summary.js?dsr-build=
|
|
860
|
-
<script src="../doctor-entry.js?dsr-build=
|
|
861
|
-
<link rel="stylesheet" href="../file-inbox.css?dsr-build=
|
|
862
|
-
<script src="../file-inbox.js?dsr-build=
|
|
863
|
-
<link rel="stylesheet" href="../session-deck.css?dsr-build=
|
|
864
|
-
<script src="../session-deck.js?dsr-build=
|
|
865
|
-
<script src="../theme.js?dsr-build=
|
|
866
|
-
<script src="../cache-upgrade.js?dsr-build=
|
|
867
|
-
<script src="desktop.js?dsr-build=
|
|
827
|
+
<script src="i18n.js?dsr-build=7b7352352544bd35e441ffdb4de480368defbe9386c58dff9a6ed41c2318b2e3"></script>
|
|
828
|
+
<link rel="stylesheet" href="../genui.css?dsr-build=7b7352352544bd35e441ffdb4de480368defbe9386c58dff9a6ed41c2318b2e3">
|
|
829
|
+
<script src="../genui.js?dsr-build=7b7352352544bd35e441ffdb4de480368defbe9386c58dff9a6ed41c2318b2e3"></script>
|
|
830
|
+
<script src="../chat-files.js?dsr-build=7b7352352544bd35e441ffdb4de480368defbe9386c58dff9a6ed41c2318b2e3"></script>
|
|
831
|
+
<script src="../md.js?dsr-build=7b7352352544bd35e441ffdb4de480368defbe9386c58dff9a6ed41c2318b2e3"></script>
|
|
832
|
+
<script src="../vendor/gsap/gsap.min.js?dsr-build=7b7352352544bd35e441ffdb4de480368defbe9386c58dff9a6ed41c2318b2e3"></script>
|
|
833
|
+
<script src="../motion.js?dsr-build=7b7352352544bd35e441ffdb4de480368defbe9386c58dff9a6ed41c2318b2e3"></script>
|
|
834
|
+
<script type="module" src="../morphicons-init.js?dsr-build=7b7352352544bd35e441ffdb4de480368defbe9386c58dff9a6ed41c2318b2e3"></script>
|
|
835
|
+
<script src="../plugin-center.js?dsr-build=7b7352352544bd35e441ffdb4de480368defbe9386c58dff9a6ed41c2318b2e3"></script>
|
|
836
|
+
<script src="../skills.js?dsr-build=7b7352352544bd35e441ffdb4de480368defbe9386c58dff9a6ed41c2318b2e3"></script>
|
|
837
|
+
<script src="../insights.js?dsr-build=7b7352352544bd35e441ffdb4de480368defbe9386c58dff9a6ed41c2318b2e3"></script>
|
|
838
|
+
<script src="../teams.js?dsr-build=7b7352352544bd35e441ffdb4de480368defbe9386c58dff9a6ed41c2318b2e3"></script>
|
|
839
|
+
<script src="../task-board.js?dsr-build=7b7352352544bd35e441ffdb4de480368defbe9386c58dff9a6ed41c2318b2e3"></script>
|
|
840
|
+
<script src="../extensions.js?dsr-build=7b7352352544bd35e441ffdb4de480368defbe9386c58dff9a6ed41c2318b2e3"></script>
|
|
841
|
+
<script src="../sha256.js?dsr-build=7b7352352544bd35e441ffdb4de480368defbe9386c58dff9a6ed41c2318b2e3"></script>
|
|
842
|
+
<script src="../diagnostics.js?dsr-build=7b7352352544bd35e441ffdb4de480368defbe9386c58dff9a6ed41c2318b2e3"></script>
|
|
843
|
+
<script src="../doctor.js?dsr-build=7b7352352544bd35e441ffdb4de480368defbe9386c58dff9a6ed41c2318b2e3"></script>
|
|
844
|
+
<script src="../history.js?dsr-build=7b7352352544bd35e441ffdb4de480368defbe9386c58dff9a6ed41c2318b2e3"></script>
|
|
845
|
+
<script src="../activity.js?dsr-build=7b7352352544bd35e441ffdb4de480368defbe9386c58dff9a6ed41c2318b2e3"></script>
|
|
846
|
+
<script src="../turn-results.js?dsr-build=7b7352352544bd35e441ffdb4de480368defbe9386c58dff9a6ed41c2318b2e3"></script>
|
|
847
|
+
<script src="../image-cache.js?dsr-build=7b7352352544bd35e441ffdb4de480368defbe9386c58dff9a6ed41c2318b2e3"></script>
|
|
848
|
+
<script src="../chat-copy.js?dsr-build=7b7352352544bd35e441ffdb4de480368defbe9386c58dff9a6ed41c2318b2e3"></script>
|
|
849
|
+
<script src="../image-preview.js?dsr-build=7b7352352544bd35e441ffdb4de480368defbe9386c58dff9a6ed41c2318b2e3"></script>
|
|
850
|
+
<script src="../link-check.js?dsr-build=7b7352352544bd35e441ffdb4de480368defbe9386c58dff9a6ed41c2318b2e3"></script>
|
|
851
|
+
<script src="../network.js?dsr-build=7b7352352544bd35e441ffdb4de480368defbe9386c58dff9a6ed41c2318b2e3"></script>
|
|
852
|
+
<script src="../operations.js?dsr-build=7b7352352544bd35e441ffdb4de480368defbe9386c58dff9a6ed41c2318b2e3"></script>
|
|
853
|
+
<script src="../workflow.js?dsr-build=7b7352352544bd35e441ffdb4de480368defbe9386c58dff9a6ed41c2318b2e3"></script>
|
|
854
|
+
<script src="../sponsor-entry.js?dsr-build=7b7352352544bd35e441ffdb4de480368defbe9386c58dff9a6ed41c2318b2e3"></script>
|
|
855
|
+
<script src="../relay-devices.js?dsr-build=7b7352352544bd35e441ffdb4de480368defbe9386c58dff9a6ed41c2318b2e3"></script>
|
|
856
|
+
<script src="../relay-settings.js?dsr-build=7b7352352544bd35e441ffdb4de480368defbe9386c58dff9a6ed41c2318b2e3"></script>
|
|
857
|
+
<script src="../subagents.js?dsr-build=7b7352352544bd35e441ffdb4de480368defbe9386c58dff9a6ed41c2318b2e3"></script>
|
|
858
|
+
<script src="../session-presets.js?dsr-build=7b7352352544bd35e441ffdb4de480368defbe9386c58dff9a6ed41c2318b2e3"></script>
|
|
859
|
+
<script src="../permission-presets.js?dsr-build=7b7352352544bd35e441ffdb4de480368defbe9386c58dff9a6ed41c2318b2e3"></script>
|
|
860
|
+
<script src="../approval-records.js?dsr-build=7b7352352544bd35e441ffdb4de480368defbe9386c58dff9a6ed41c2318b2e3"></script>
|
|
861
|
+
<script src="../approval-summary.js?dsr-build=7b7352352544bd35e441ffdb4de480368defbe9386c58dff9a6ed41c2318b2e3"></script>
|
|
862
|
+
<script src="../doctor-entry.js?dsr-build=7b7352352544bd35e441ffdb4de480368defbe9386c58dff9a6ed41c2318b2e3"></script>
|
|
863
|
+
<link rel="stylesheet" href="../file-inbox.css?dsr-build=7b7352352544bd35e441ffdb4de480368defbe9386c58dff9a6ed41c2318b2e3">
|
|
864
|
+
<script src="../file-inbox.js?dsr-build=7b7352352544bd35e441ffdb4de480368defbe9386c58dff9a6ed41c2318b2e3"></script>
|
|
865
|
+
<link rel="stylesheet" href="../session-deck.css?dsr-build=7b7352352544bd35e441ffdb4de480368defbe9386c58dff9a6ed41c2318b2e3">
|
|
866
|
+
<script src="../session-deck.js?dsr-build=7b7352352544bd35e441ffdb4de480368defbe9386c58dff9a6ed41c2318b2e3"></script>
|
|
867
|
+
<script src="../theme.js?dsr-build=7b7352352544bd35e441ffdb4de480368defbe9386c58dff9a6ed41c2318b2e3"></script>
|
|
868
|
+
<script src="../cache-upgrade.js?dsr-build=7b7352352544bd35e441ffdb4de480368defbe9386c58dff9a6ed41c2318b2e3"></script>
|
|
869
|
+
<script src="desktop.js?dsr-build=7b7352352544bd35e441ffdb4de480368defbe9386c58dff9a6ed41c2318b2e3"></script>
|
|
868
870
|
</body>
|
|
869
871
|
</html>
|
|
@@ -791,13 +791,25 @@ async function respond(rpcId, value) {
|
|
|
791
791
|
const receipt = await res.json()
|
|
792
792
|
return receipt?.accepted === true
|
|
793
793
|
}
|
|
794
|
+
function operationPendingHost(connection) {
|
|
795
|
+
try {
|
|
796
|
+
const url = new URL(connection?.server || '', location.href)
|
|
797
|
+
return url.host || location.host
|
|
798
|
+
} catch { return location.host }
|
|
799
|
+
}
|
|
800
|
+
// A durable write may have been applied even if the connection identity changed
|
|
801
|
+
// while its receipt was pending. Never drop that fact silently.
|
|
802
|
+
function notifyPendingOperation(error, connection) {
|
|
803
|
+
if (connection?.valid()) toast(error.message, 'err')
|
|
804
|
+
else toast(t('ds.sendUnconfirmedSwitched', { host: operationPendingHost(connection) }), 'err')
|
|
805
|
+
}
|
|
794
806
|
async function safeRpc(method, payload, errText) {
|
|
795
807
|
const connection = captureConnection()
|
|
796
808
|
try { const value = await rpc(method, payload); return connection.valid() ? value : null }
|
|
797
809
|
catch (e) {
|
|
810
|
+
if (e.operationPending) { notifyPendingOperation(e, connection); return null }
|
|
798
811
|
if (!connection.valid()) return null
|
|
799
812
|
if (e.message === 'AUTH') { toast(t('ds.toastAuth'), 'err'); return null }
|
|
800
|
-
if (e.operationPending) { toast(e.message, 'err'); return null }
|
|
801
813
|
toast(errText ? `${errText}:${e.message}` : e.message, 'err')
|
|
802
814
|
return null
|
|
803
815
|
}
|
|
@@ -2173,7 +2185,9 @@ async function openSession(id) {
|
|
|
2173
2185
|
async function closeSession() {
|
|
2174
2186
|
globalThis.DshDiagnostics?.record('session.back',{phase:'start',sessionId:state.current,loading:state.history.loading,loaded:state.history.loaded,renderErrors:state.history.renderError?1:0})
|
|
2175
2187
|
const sessionId = state.current
|
|
2176
|
-
const
|
|
2188
|
+
const closing = state.byId.get(sessionId)
|
|
2189
|
+
// Ordinary forks also carry parentSessionId; only a subagent record returns to its parent.
|
|
2190
|
+
const parentId = closing?.origin === 'subagent' ? closing.parentSessionId : null
|
|
2177
2191
|
if (parentId && parentId !== sessionId) return openSession(parentId)
|
|
2178
2192
|
const wasLoading = state.history.loading
|
|
2179
2193
|
cancelHistoryLoad()
|
|
@@ -2525,7 +2539,7 @@ function bindTurnResultActions() {
|
|
|
2525
2539
|
if (!context.valid()) return
|
|
2526
2540
|
// A confirmed fork remains usable while the session catalog is stalled.
|
|
2527
2541
|
if (!state.byId.has(id)) {
|
|
2528
|
-
const branch = { ...parent, projections: parent?.projections ? JSON.parse(JSON.stringify(parent.projections)) : undefined,
|
|
2542
|
+
const branch = { ...parent, projections: parent?.projections ? { ...JSON.parse(JSON.stringify(parent.projections)), asOfSeq: 0 } : undefined,
|
|
2529
2543
|
sessionId: id, parentSessionId: context.sessionId, origin: 'fork', running: false, blank: false }
|
|
2530
2544
|
state.byId.set(id, branch)
|
|
2531
2545
|
state.sessions.unshift(branch)
|
|
@@ -2875,7 +2889,7 @@ async function confirmRenameSession() {
|
|
|
2875
2889
|
const value = await safeRpc('session.rename', { sessionId, title }, t('ds.sessionRenameFailed'))
|
|
2876
2890
|
if (!connection.valid() || renamePendingSessionId !== sessionId) return
|
|
2877
2891
|
if (value == null) { setSessionRecovery('error'); return }
|
|
2878
|
-
if (value
|
|
2892
|
+
if (value != null) applyProjection(sessionId, 'title', value.title || title, value.seq)
|
|
2879
2893
|
closeRenameSession()
|
|
2880
2894
|
setSessionRecovery('ready')
|
|
2881
2895
|
toast(t('ds.sessionRenamed'), 'ok')
|
|
@@ -3088,17 +3102,28 @@ function renderNotifStack() {
|
|
|
3088
3102
|
async function approveApproval(id, allow) {
|
|
3089
3103
|
const connection = captureConnection()
|
|
3090
3104
|
const a = state.approvals.find(x => x.approvalId === id)
|
|
3091
|
-
|
|
3105
|
+
const inFlight = approveApproval.inFlight || (approveApproval.inFlight = new Set())
|
|
3106
|
+
if (!a || inFlight.has(id)) return
|
|
3107
|
+
inFlight.add(id)
|
|
3108
|
+
state.approvals = state.approvals.filter(x => x.rpcId !== a.rpcId)
|
|
3109
|
+
renderNotifStack()
|
|
3110
|
+
const restoreCard = () => {
|
|
3111
|
+
if (!state.approvals.some(x => x.rpcId === a.rpcId)) state.approvals = [a, ...state.approvals]
|
|
3112
|
+
renderNotifStack()
|
|
3113
|
+
}
|
|
3092
3114
|
let ok
|
|
3093
3115
|
try {
|
|
3094
3116
|
ok = await respond(a.rpcId, { sessionId: a.sessionId, approvalId: a.approvalId, outcome: allow ? 'allowed-once' : 'rejected' })
|
|
3095
3117
|
} catch (e) {
|
|
3096
|
-
|
|
3118
|
+
inFlight.delete(id)
|
|
3119
|
+
if (!connection.valid()) { restoreCard(); return }
|
|
3120
|
+
restoreCard()
|
|
3097
3121
|
if (e.message === 'AUTH') toast(t('ds.toastAuth'), 'err')
|
|
3098
3122
|
else toast(t('ds.pendingSubmitFailed', { msg: e.message || t('ds.feedbackNetworkError') }), 'err')
|
|
3099
3123
|
return
|
|
3100
3124
|
}
|
|
3101
|
-
|
|
3125
|
+
inFlight.delete(id)
|
|
3126
|
+
if (!connection.valid()) { restoreCard(); return }
|
|
3102
3127
|
toast(ok ? (allow ? t('ds.allowed') : t('ds.rejected')) : t('ds.stale'), ok ? 'ok' : 'err')
|
|
3103
3128
|
state.approvals = state.approvals.filter(x => x.rpcId !== a.rpcId)
|
|
3104
3129
|
renderNotifStack()
|
|
@@ -3169,10 +3194,21 @@ function fsHeaders() {
|
|
|
3169
3194
|
}
|
|
3170
3195
|
|
|
3171
3196
|
/** Local image paths inside Markdown: resolve relative to the open session workspace. */
|
|
3172
|
-
async function chatImageAttachment(
|
|
3197
|
+
async function chatImageAttachment(attachment, sessionId) {
|
|
3173
3198
|
const connection = captureConnection()
|
|
3174
3199
|
if (!sessionId || sessionId !== state.current || !connection.valid()) throw new Error('stale image')
|
|
3175
|
-
const
|
|
3200
|
+
const ref = typeof attachment === 'string' ? { attachmentId: attachment } : attachment
|
|
3201
|
+
if (!ref || !/^(?:sha256:)?[a-f0-9]{64}$/.test(String(ref.attachmentId || ''))) throw new Error('invalid image attachment')
|
|
3202
|
+
// DSH modern RPC validates the whole attachment reference, not only its id.
|
|
3203
|
+
const payload = { sessionId, attachment: {
|
|
3204
|
+
attachmentId: ref.attachmentId,
|
|
3205
|
+
...(ref.mediaType === undefined ? {} : { mediaType: ref.mediaType }),
|
|
3206
|
+
...(ref.bytes === undefined ? {} : { bytes: ref.bytes }),
|
|
3207
|
+
...(ref.width === undefined ? {} : { width: ref.width }),
|
|
3208
|
+
...(ref.height === undefined ? {} : { height: ref.height }),
|
|
3209
|
+
...(ref.name ? { name: ref.name } : {}),
|
|
3210
|
+
} }
|
|
3211
|
+
const result = await rpc('session.attachment', payload, 120000)
|
|
3176
3212
|
if (!connection.valid() || state.current !== sessionId) throw new Error('stale image')
|
|
3177
3213
|
return result
|
|
3178
3214
|
}
|
package/public/doctor.css
CHANGED
|
@@ -7,7 +7,7 @@ body.doctor-open { overflow: hidden; }
|
|
|
7
7
|
display: flex;
|
|
8
8
|
align-items: center;
|
|
9
9
|
justify-content: center;
|
|
10
|
-
padding: max(24px, var(--dsr-safe-
|
|
10
|
+
padding: max(24px, var(--dsr-safe-top, 0px)) 24px max(24px, var(--dsr-safe-b, 0px));
|
|
11
11
|
box-sizing: border-box;
|
|
12
12
|
background: var(--dsr-overlay, rgba(3, 8, 16, .66));
|
|
13
13
|
overflow: auto;
|
package/public/e2ee-transport.js
CHANGED
|
@@ -60,14 +60,18 @@
|
|
|
60
60
|
const anchor = event.target?.closest?.('a[href]')
|
|
61
61
|
if (anchor && !externalAllowed(anchor.href)) { event.preventDefault(); event.stopImmediatePropagation(); externalNotice() }
|
|
62
62
|
}, true)
|
|
63
|
-
root.DshE2eeTransport = { resolve, mount(target, { connection, onConnect, onModeChange, onAutoPaired } = {}) {
|
|
63
|
+
root.DshE2eeTransport = { resolve, mount(target, { connection, onConnect, onModeChange, onAutoPaired, onScan } = {}) {
|
|
64
64
|
if (!target || target.dataset.e2eeMounted) return
|
|
65
65
|
target.dataset.e2eeMounted = 'true'
|
|
66
66
|
const en = () => root.I18N?.lang === 'en', text = (zh, english) => en() ? english : zh
|
|
67
|
-
const
|
|
67
|
+
const guide = document.createElement('section'), title = document.createElement('h3'), explanation = document.createElement('p')
|
|
68
|
+
const progress = document.createElement('p'), button = document.createElement('button'), status = document.createElement('p')
|
|
69
|
+
guide.id = 'relay-phone-pairing'; guide.className = 'relay-pair-guide'; guide.tabIndex = -1
|
|
70
|
+
progress.setAttribute('role', 'status'); progress.className = 'relay-pair-progress'
|
|
68
71
|
const file = document.createElement('input'); file.type = 'file'; file.accept = '.json,application/json'; file.hidden = true
|
|
69
72
|
const autoPair = document.createElement('button'); autoPair.type = 'button'
|
|
70
|
-
|
|
73
|
+
const startLabel = text('开始公网配对', 'Pair for public access')
|
|
74
|
+
autoPair.textContent = startLabel
|
|
71
75
|
const logBox = document.createElement('details'), logSummary = document.createElement('summary')
|
|
72
76
|
const logPre = document.createElement('pre'), logActions = document.createElement('div'), logHint = document.createElement('p')
|
|
73
77
|
const logCopy = document.createElement('button'), logRefresh = document.createElement('button'), logClear = document.createElement('button')
|
|
@@ -106,10 +110,10 @@
|
|
|
106
110
|
status.textContent = text('请先连接自己电脑的局域网地址,再配置公网配对。', 'Connect to your computer’s LAN address first, then configure relay pairing.')
|
|
107
111
|
return
|
|
108
112
|
}
|
|
109
|
-
|
|
110
|
-
void root.DshRelayAutoPair.offer({ connection, onPaired: onAutoPaired, force: true, onStatus:
|
|
111
|
-
|
|
112
|
-
|
|
113
|
+
status.textContent = ''
|
|
114
|
+
void root.DshRelayAutoPair.offer({ connection, onPaired: onAutoPaired, force: true, onStatus: value => {
|
|
115
|
+
if (!ctx.valid()) return
|
|
116
|
+
status.textContent = root.DshRelayAutoPair.progress?.(ctx) ? '' : value
|
|
113
117
|
renderLog(); renderMode()
|
|
114
118
|
} })
|
|
115
119
|
})
|
|
@@ -117,10 +121,19 @@
|
|
|
117
121
|
modeLabel.className = 'relay-encryption-switch'; modeSwitch.type = 'checkbox'; modeSwitch.checked = true; modeSwitch.dataset.e2eeToggle = 'true'
|
|
118
122
|
modeText.textContent = text('端到端加密(默认开启)', 'End-to-end encryption (on by default)'); modeLabel.append(modeSwitch, modeText)
|
|
119
123
|
modeStatus.setAttribute('role', 'status'); modeStatus.className = 'relay-encryption-status'
|
|
120
|
-
title.textContent = text('
|
|
121
|
-
explanation.textContent = text('
|
|
124
|
+
title.textContent = text('手机公网配对', 'Pair this phone for public access')
|
|
125
|
+
explanation.textContent = text('电脑开通中转后,用这台手机扫描电脑管理页的连接码。已连上电脑局域网时,也可在这里直接配对。', 'After enabling relay on your computer, scan its connection code with this phone. You can also pair here over an existing LAN connection.')
|
|
126
|
+
const advanced = document.createElement('details'), advancedTitle = document.createElement('summary')
|
|
127
|
+
advancedTitle.textContent = text('配对文件、加密设置与日志', 'Pairing files, encryption and logs')
|
|
122
128
|
button.type = 'button'; button.textContent = text('导入本机配对文件', 'Import local pairing file')
|
|
123
|
-
status.setAttribute('role', 'status')
|
|
129
|
+
status.setAttribute('role', 'status')
|
|
130
|
+
const scan = document.createElement('button')
|
|
131
|
+
scan.type = 'button'; scan.textContent = text('扫描电脑连接码', 'Scan computer connection code')
|
|
132
|
+
scan.hidden = typeof onScan !== 'function'
|
|
133
|
+
scan.addEventListener('click', () => onScan?.())
|
|
134
|
+
guide.append(title, explanation, progress, scan, autoPair, status)
|
|
135
|
+
advanced.append(advancedTitle, modeLabel, modeStatus, button, file, logBox)
|
|
136
|
+
target.append(guide, advanced)
|
|
124
137
|
let selectedOrigin = '', identity = ''
|
|
125
138
|
function modeContext() {
|
|
126
139
|
const ctx = connection(), key = JSON.stringify([ctx.url('/relay'),ctx.headers?.authorization||''])
|
|
@@ -130,7 +143,18 @@
|
|
|
130
143
|
}
|
|
131
144
|
function renderMode() {
|
|
132
145
|
try {
|
|
133
|
-
modeContext()
|
|
146
|
+
const ctx = modeContext(), pairing = root.DshRelayAutoPair?.progress?.(ctx)
|
|
147
|
+
const local = root.DshRelayAutoPair?.localUrl(ctx.url('/relay')) && /^Bearer \S+$/.test(ctx.headers?.authorization || '')
|
|
148
|
+
const message = pairing?.message || (local
|
|
149
|
+
? text('已选中局域网地址,可以开始公网配对。', 'A LAN address is selected. Start public pairing here.')
|
|
150
|
+
: text('请扫描电脑显示的连接码,或先连接电脑的局域网地址。', 'Scan the code shown on the computer or connect to it over LAN.'))
|
|
151
|
+
if (progress.textContent !== message) progress.textContent = message
|
|
152
|
+
progress.dataset.phase = pairing?.phase || 'idle'
|
|
153
|
+
autoPair.textContent = pairing?.phase === 'ready' || pairing?.phase === 'error'
|
|
154
|
+
? text('重新验证公网配对', 'Verify public pairing again') : startLabel
|
|
155
|
+
autoPair.disabled = !local || pairing?.phase === 'working'
|
|
156
|
+
scan.disabled = pairing?.phase === 'working'
|
|
157
|
+
const state = JSON.parse(bridge.info(selectedOrigin))
|
|
134
158
|
modeSwitch.checked = state.encrypted !== false
|
|
135
159
|
modeSwitch.disabled = !!state.error || !state.configured || typeof bridge.setEncryption !== 'function'
|
|
136
160
|
modeStatus.dataset.security = !state.configured || state.error ? 'pending' : modeSwitch.checked ? 'encrypted' : 'legacy'
|
package/public/image-preview.js
CHANGED
|
@@ -3,13 +3,23 @@
|
|
|
3
3
|
;(function(root){
|
|
4
4
|
const english=()=>root.I18N?.lang==='en'
|
|
5
5
|
let lightbox=null,stage=null,image=null,closeButton=null,hint=null,opener=null
|
|
6
|
-
let resolver=null,attachmentResolver=null,capture=null,observer=null,mutation=null,generation=0
|
|
6
|
+
let resolver=null,attachmentResolver=null,capture=null,observer=null,mutation=null,generation=0,saver=null
|
|
7
|
+
let currentRef=null,saveMenu=null,saveMenuRef=null,pressTimer=null,pressOrigin=null,pressPointer=null,suppressClickUntil=0
|
|
7
8
|
const objectUrls=new Map()
|
|
8
9
|
const escape=value=>String(value??'').replace(/[&<>"']/g,c=>({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c]))
|
|
10
|
+
function attachmentRef(attachment){
|
|
11
|
+
if(!attachment||typeof attachment!=='object')return null
|
|
12
|
+
const attachmentId=String(attachment.attachmentId||'')
|
|
13
|
+
if(!/^(?:sha256:)?[a-f0-9]{64}$/.test(attachmentId))return null
|
|
14
|
+
// DSH modern RPC validates the whole reference, not only the storage id.
|
|
15
|
+
return { attachmentId, mediaType:String(attachment.mediaType||''), bytes:Number(attachment.bytes)||0,
|
|
16
|
+
width:Number(attachment.width)||0, height:Number(attachment.height)||0, ...(attachment.name?{name:String(attachment.name)}:{}) }
|
|
17
|
+
}
|
|
9
18
|
function attachmentHtml(attachment,label,sessionId){
|
|
10
|
-
|
|
19
|
+
const ref=attachmentRef(attachment)
|
|
20
|
+
if(!ref)return '<span class="chat-image-status">'+escape(label)+'</span>'
|
|
11
21
|
const alt=escape(attachment.name||label)
|
|
12
|
-
return '<button type="button" class="chat-image is-loading" data-chat-image data-chat-image-attachment="'+
|
|
22
|
+
return '<button type="button" class="chat-image is-loading" data-chat-image data-chat-image-attachment="'+ref.attachmentId+'" data-chat-image-ref="'+escape(JSON.stringify(ref))+'" data-chat-image-session="'+escape(sessionId)+'" data-chat-image-alt="'+alt+'" aria-label="'+alt+'"><span class="chat-image-status">'+escape(label)+'</span></button>'
|
|
13
23
|
}
|
|
14
24
|
function labels(){
|
|
15
25
|
if(!lightbox)return
|
|
@@ -30,9 +40,10 @@
|
|
|
30
40
|
}
|
|
31
41
|
function toggleZoom(){setZoom(!isZoomed())}
|
|
32
42
|
function isOpen(){return !!lightbox&&!lightbox.classList.contains('hidden')}
|
|
33
|
-
function open(src,alt=''){
|
|
43
|
+
function open(src,alt='',ref=null){
|
|
34
44
|
if(!src||!elements())return
|
|
35
45
|
opener=root.document.activeElement||null
|
|
46
|
+
currentRef=ref||null
|
|
36
47
|
image.src=src
|
|
37
48
|
image.alt=alt||(english()?'Image':'图片')
|
|
38
49
|
lightbox.classList.remove('hidden')
|
|
@@ -42,6 +53,7 @@
|
|
|
42
53
|
}
|
|
43
54
|
function close(){
|
|
44
55
|
if(!lightbox||lightbox.classList.contains('hidden'))return
|
|
56
|
+
closeSaveMenu()
|
|
45
57
|
setZoom(false)
|
|
46
58
|
lightbox.classList.add('hidden')
|
|
47
59
|
root.document.body?.classList.remove('image-preview-open')
|
|
@@ -49,12 +61,49 @@
|
|
|
49
61
|
const target=opener;opener=null
|
|
50
62
|
target?.focus?.({preventScroll:true})
|
|
51
63
|
}
|
|
64
|
+
function descriptorFor(trigger){
|
|
65
|
+
if(!trigger)return null
|
|
66
|
+
const attachmentId=trigger.dataset?.chatImageAttachment
|
|
67
|
+
if(attachmentId){
|
|
68
|
+
let ref=null
|
|
69
|
+
try{ref=JSON.parse(trigger.dataset.chatImageRef||'null')}catch{}
|
|
70
|
+
return {kind:'attachment',attachmentId,sessionId:trigger.dataset.chatImageSession||'',name:(ref&&ref.name)||trigger.dataset.chatImageAlt||'',mediaType:ref?.mediaType||''}
|
|
71
|
+
}
|
|
72
|
+
const path=trigger.dataset?.chatImagePath
|
|
73
|
+
return path?{kind:'path',path,name:trigger.dataset.chatImageAlt||''}:null
|
|
74
|
+
}
|
|
75
|
+
function cancelPress(){
|
|
76
|
+
if(pressTimer){clearTimeout(pressTimer);pressTimer=null}
|
|
77
|
+
pressOrigin=null;pressPointer=null
|
|
78
|
+
}
|
|
79
|
+
function closeSaveMenu(){
|
|
80
|
+
if(!saveMenu||saveMenu.classList.contains('hidden'))return false
|
|
81
|
+
saveMenu.classList.add('hidden');saveMenuRef=null;return true
|
|
82
|
+
}
|
|
83
|
+
function openSaveMenu(ref){
|
|
84
|
+
if(!saveMenu||!ref)return
|
|
85
|
+
saveMenuRef=ref
|
|
86
|
+
saveMenu.classList.remove('hidden')
|
|
87
|
+
}
|
|
88
|
+
async function saveRef(ref){
|
|
89
|
+
if(!ref)return
|
|
90
|
+
try{
|
|
91
|
+
if(saver)return await saver(ref)
|
|
92
|
+
// Browser shells without a host-specific saver can still keep the rendered image.
|
|
93
|
+
const src=image?.src
|
|
94
|
+
if(!src)return
|
|
95
|
+
const link=root.document.createElement('a')
|
|
96
|
+
link.href=src;link.download=(ref.name||'image').replace(/[\\/\x00-\x1f]/g,'_').slice(0,200)||'image'
|
|
97
|
+
root.document.body.append(link);link.click();link.remove()
|
|
98
|
+
}catch{}
|
|
99
|
+
}
|
|
52
100
|
// Markdown images may point at a local file. The host shell supplies an authenticated
|
|
53
101
|
// request for that path; load lazily and swap the placeholder for a real previewable image.
|
|
54
102
|
function configure(options={}){
|
|
55
103
|
if(typeof options.resolvePath==='function')resolver=options.resolvePath
|
|
56
104
|
if(typeof options.resolveAttachment==='function')attachmentResolver=options.resolveAttachment
|
|
57
105
|
if(typeof options.capture==='function')capture=options.capture
|
|
106
|
+
if(typeof options.save==='function')saver=options.save
|
|
58
107
|
if(!mutation&&typeof root.MutationObserver==='function'&&root.document?.body){
|
|
59
108
|
// History renders (paging, streaming, cache restore) replace nodes without a full render call.
|
|
60
109
|
mutation=new root.MutationObserver(records=>{
|
|
@@ -96,6 +145,11 @@
|
|
|
96
145
|
async function loadPathImage(button){
|
|
97
146
|
const path=button.dataset.chatImagePath
|
|
98
147
|
const attachmentId=button.dataset.chatImageAttachment
|
|
148
|
+
let attachment=null
|
|
149
|
+
if(attachmentId){
|
|
150
|
+
try{const parsed=JSON.parse(button.dataset.chatImageRef||'null');if(parsed&&parsed.attachmentId===attachmentId)attachment=parsed}catch{}
|
|
151
|
+
if(!attachment)attachment={attachmentId}
|
|
152
|
+
}
|
|
99
153
|
if(attachmentId?!attachmentResolver:(!path||!resolver))return
|
|
100
154
|
const identity=capture?.(),version=generation
|
|
101
155
|
const valid=()=>version===generation&&button.isConnected!==false&&(!identity||identity.valid())
|
|
@@ -110,8 +164,8 @@
|
|
|
110
164
|
const value=await root.DshImageCache.load(identity.scope,id,async cached=>{
|
|
111
165
|
if(!valid())throw Error('stale image')
|
|
112
166
|
if(attachmentId){
|
|
113
|
-
const result=await attachmentResolver(
|
|
114
|
-
if(result?.attachment?.attachmentId!==attachmentId||!/^image\/(?:png|jpeg|webp|gif)$/.test(result.attachment.mediaType)||typeof result.data!=='string'||!result.data||result.data.length>16*1024*1024||!/^[A-Za-z0-9+/]*={0,2}$/.test(result.data))throw Object.assign(Error('invalid image attachment'),{status:422})
|
|
167
|
+
const result=await attachmentResolver(attachment,button.dataset.chatImageSession)
|
|
168
|
+
if(result?.attachment?.attachmentId!==attachment.attachmentId||!/^image\/(?:png|jpeg|webp|gif)$/.test(result.attachment.mediaType)||typeof result.data!=='string'||!result.data||result.data.length>16*1024*1024||!/^[A-Za-z0-9+/]*={0,2}$/.test(result.data))throw Object.assign(Error('invalid image attachment'),{status:422})
|
|
115
169
|
const binary=root.atob(result.data),bytes=new Uint8Array(binary.length)
|
|
116
170
|
for(let i=0;i<binary.length;i++)bytes[i]=binary.charCodeAt(i)
|
|
117
171
|
return {blob:new root.Blob([bytes],{type:result.attachment.mediaType})}
|
|
@@ -131,8 +185,8 @@
|
|
|
131
185
|
url=root.URL.createObjectURL(value.blob)
|
|
132
186
|
objectUrls.set(button,url)
|
|
133
187
|
}else if(attachmentId){
|
|
134
|
-
const result=await attachmentResolver(
|
|
135
|
-
if(result?.attachment?.attachmentId!==attachmentId||!/^image\/(?:png|jpeg|webp|gif)$/.test(result.attachment.mediaType)||typeof result.data!=='string'||!result.data||result.data.length>16*1024*1024||!/^[A-Za-z0-9+/]*={0,2}$/.test(result.data))throw new Error('invalid image attachment')
|
|
188
|
+
const result=await attachmentResolver(attachment,button.dataset.chatImageSession)
|
|
189
|
+
if(result?.attachment?.attachmentId!==attachment.attachmentId||!/^image\/(?:png|jpeg|webp|gif)$/.test(result.attachment.mediaType)||typeof result.data!=='string'||!result.data||result.data.length>16*1024*1024||!/^[A-Za-z0-9+/]*={0,2}$/.test(result.data))throw new Error('invalid image attachment')
|
|
136
190
|
url='data:'+result.attachment.mediaType+';base64,'+result.data
|
|
137
191
|
}else{
|
|
138
192
|
const source=await resolver(path)
|
|
@@ -152,11 +206,10 @@
|
|
|
152
206
|
node.addEventListener('load',()=>{button.classList.remove('is-loading');button.classList.add('is-loaded')})
|
|
153
207
|
button.replaceChildren(node)
|
|
154
208
|
button.dataset.chatImageLoaded='1'
|
|
155
|
-
delete button.dataset.chatImagePath
|
|
156
209
|
}catch(error){if(valid())pathImageFailed(button)}
|
|
157
210
|
}
|
|
158
211
|
function release(button){const url=objectUrls.get(button);if(url)root.URL?.revokeObjectURL?.(url);objectUrls.delete(button)}
|
|
159
|
-
function reset(){generation++;close();for(const button of objectUrls.keys())release(button)}
|
|
212
|
+
function reset(){generation++;close();closeSaveMenu();for(const button of objectUrls.keys())release(button)}
|
|
160
213
|
function pathImageFailed(button){
|
|
161
214
|
release(button)
|
|
162
215
|
button.classList.remove('is-loading')
|
|
@@ -176,16 +229,62 @@
|
|
|
176
229
|
lightbox.addEventListener('click',event=>{const target=event.target;if(target===lightbox||target===stage)close()})
|
|
177
230
|
stage?.addEventListener('click',event=>{if(event.target===stage)close()})
|
|
178
231
|
image?.addEventListener('dblclick',event=>{event.preventDefault?.();toggleZoom()})
|
|
179
|
-
root.document.addEventListener('keydown',event=>{if(event.key==='Escape'&&isOpen()){event.preventDefault?.();close()}})
|
|
232
|
+
root.document.addEventListener('keydown',event=>{if(event.key==='Escape'&&isOpen()){event.preventDefault?.();if(closeSaveMenu())return;close()}})
|
|
233
|
+
// A long press opens a two-action sheet; the preview click below is suppressed after it.
|
|
234
|
+
saveMenu=root.document.getElementById('image-save-menu')
|
|
235
|
+
if(!saveMenu){
|
|
236
|
+
saveMenu=root.document.createElement('div')
|
|
237
|
+
saveMenu.id='image-save-menu'
|
|
238
|
+
saveMenu.className='image-save-menu hidden'
|
|
239
|
+
saveMenu.setAttribute('role','menu')
|
|
240
|
+
saveMenu.innerHTML='<button type="button" role="menuitem" data-image-save-action="save"></button><button type="button" role="menuitem" data-image-save-action="cancel"></button>'
|
|
241
|
+
const mount = root.document.body
|
|
242
|
+
if (mount && typeof mount.appendChild === 'function') mount.appendChild(saveMenu)
|
|
243
|
+
else if (mount && typeof mount.append === 'function') mount.append(saveMenu)
|
|
244
|
+
saveMenu.addEventListener('click',event=>{
|
|
245
|
+
const action=event.target?.closest?.('[data-image-save-action]')?.dataset.imageSaveAction
|
|
246
|
+
if(!action)return
|
|
247
|
+
event.preventDefault?.();event.stopPropagation?.()
|
|
248
|
+
const ref=saveMenuRef
|
|
249
|
+
closeSaveMenu()
|
|
250
|
+
if(action==='save')void saveRef(ref)
|
|
251
|
+
})
|
|
252
|
+
}
|
|
253
|
+
const saveLabel=saveMenu.querySelector('[data-image-save-action="save"]'),cancelLabel=saveMenu.querySelector('[data-image-save-action="cancel"]')
|
|
254
|
+
if(saveLabel)saveLabel.textContent=english()?'Save image':'保存图片'
|
|
255
|
+
if(cancelLabel)cancelLabel.textContent=english()?'Cancel':'取消'
|
|
256
|
+
root.document.addEventListener('pointerdown',event=>{
|
|
257
|
+
if(event.button!==undefined&&event.button!==0)return
|
|
258
|
+
if(saveMenu&&!saveMenu.classList.contains('hidden'))return
|
|
259
|
+
const trigger=event.target?.closest?.('[data-chat-image]')
|
|
260
|
+
const inPreview=event.target===image
|
|
261
|
+
if(!trigger&&!inPreview)return
|
|
262
|
+
if(pressTimer){cancelPress();return}
|
|
263
|
+
const ref=inPreview?currentRef:descriptorFor(trigger)
|
|
264
|
+
if(!ref)return
|
|
265
|
+
pressPointer=event.pointerId
|
|
266
|
+
pressOrigin={x:event.clientX,y:event.clientY}
|
|
267
|
+
pressTimer=setTimeout(()=>{pressTimer=null;suppressClickUntil=Date.now()+900;openSaveMenu(ref)},520)
|
|
268
|
+
},true)
|
|
269
|
+
root.document.addEventListener('pointermove',event=>{
|
|
270
|
+
if(!pressTimer||!pressOrigin)return
|
|
271
|
+
if(Math.hypot(event.clientX-pressOrigin.x,event.clientY-pressOrigin.y)>10)cancelPress()
|
|
272
|
+
},true)
|
|
273
|
+
root.document.addEventListener('pointerup',cancelPress,true)
|
|
274
|
+
root.document.addEventListener('pointercancel',cancelPress,true)
|
|
275
|
+
root.document.addEventListener('contextmenu',event=>{
|
|
276
|
+
if(event.target?.closest?.('[data-chat-image]')||event.target===image)event.preventDefault?.()
|
|
277
|
+
})
|
|
180
278
|
// Chat images live inside rendered history: delegate instead of rebinding per message.
|
|
181
279
|
root.document.addEventListener('click',event=>{
|
|
280
|
+
if(Date.now()<suppressClickUntil)return
|
|
182
281
|
const trigger=event.target?.closest?.('[data-chat-image]')
|
|
183
282
|
if(!trigger)return
|
|
184
283
|
const img=trigger.querySelector?.('img')
|
|
185
|
-
if(img?.src)open(img.src,img.alt||'')
|
|
284
|
+
if(img?.src)open(img.src,img.alt||'',descriptorFor(trigger))
|
|
186
285
|
})
|
|
187
286
|
return lightbox
|
|
188
287
|
}
|
|
189
|
-
root.DshImagePreview={open,close,isOpen,zoom:toggleZoom,mount:elements,configure,hydrate,attachmentHtml,reset}
|
|
288
|
+
root.DshImagePreview={open,close,isOpen,zoom:toggleZoom,mount:elements,configure,hydrate,attachmentHtml,reset,closeSaveMenu}
|
|
190
289
|
root.document?.addEventListener('DOMContentLoaded',()=>{elements();hydrate(root.document)})
|
|
191
290
|
})(typeof window==='undefined'?globalThis:window)
|