dsh-bark-push 0.1.6 → 0.2.1
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/CHANGELOG.md +29 -0
- package/README.md +72 -23
- package/cordis.patch.yml +6 -0
- package/lib/channels.js +528 -0
- package/lib/client.js +363 -60
- package/lib/config.js +106 -1
- package/lib/http.js +127 -30
- package/lib/index.js +20 -5
- package/lib/notifier.js +106 -32
- package/lib/ui.js +627 -155
- package/package.json +8 -2
package/lib/ui.js
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Self-contained management page for
|
|
2
|
+
* Self-contained management page for notification configuration and mute state.
|
|
3
3
|
*
|
|
4
4
|
* The page is served by the authenticated host route, so it uses only
|
|
5
5
|
* same-origin fetch and no external assets. All dynamic values are written
|
|
6
6
|
* through `textContent` or form values; server data never becomes HTML.
|
|
7
7
|
*
|
|
8
|
+
* Design intent: this is a notification-routing console embedded inside DSH
|
|
9
|
+
* Settings. Hierarchy is status-first: a compact health strip, then sections
|
|
10
|
+
* separated by hairline rules (not nested rounded cards), and each extra
|
|
11
|
+
* channel is a single "lane" whose enabled state reads at a glance while its
|
|
12
|
+
* parameters stay collapsed until needed.
|
|
13
|
+
*
|
|
8
14
|
* @module dsh-bark-push/ui
|
|
9
15
|
*/
|
|
10
16
|
|
|
@@ -22,80 +28,165 @@ export function renderUiPage({ version, embedded = false }) {
|
|
|
22
28
|
<head>
|
|
23
29
|
<meta charset="utf-8">
|
|
24
30
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
25
|
-
<title
|
|
31
|
+
<title>推送通知 · DSH</title>
|
|
26
32
|
<style>
|
|
27
33
|
:root {
|
|
28
34
|
color-scheme: light dark;
|
|
29
35
|
--bg: #ffffff;
|
|
30
|
-
--fg: #
|
|
31
|
-
--muted: #
|
|
32
|
-
--line: #
|
|
33
|
-
--
|
|
36
|
+
--fg: #16181d;
|
|
37
|
+
--muted: #6b7280;
|
|
38
|
+
--line: #e5e7eb;
|
|
39
|
+
--line-strong: #d5d9e0;
|
|
40
|
+
--subtle: #f6f7f9;
|
|
34
41
|
--accent: #3b6ef6;
|
|
42
|
+
--on-accent: #ffffff;
|
|
35
43
|
--ok: #16894f;
|
|
36
|
-
--bad: #c0392b;
|
|
37
44
|
--warn: #a66a00;
|
|
45
|
+
--bad: #c0392b;
|
|
46
|
+
--radius: 10px;
|
|
38
47
|
}
|
|
39
48
|
@media (prefers-color-scheme: dark) {
|
|
40
49
|
:root {
|
|
41
|
-
--bg: #
|
|
50
|
+
--bg: #16171b;
|
|
42
51
|
--fg: #eceef3;
|
|
43
|
-
--muted: #
|
|
44
|
-
--line: #
|
|
45
|
-
--
|
|
52
|
+
--muted: #9aa1ad;
|
|
53
|
+
--line: #2b2e36;
|
|
54
|
+
--line-strong: #3a3e48;
|
|
55
|
+
--subtle: #22252c;
|
|
46
56
|
--accent: #7aa2ff;
|
|
57
|
+
--on-accent: #0e1116;
|
|
47
58
|
--ok: #5dd39e;
|
|
48
|
-
--bad: #ff7b72;
|
|
49
59
|
--warn: #e3b341;
|
|
60
|
+
--bad: #ff7b72;
|
|
50
61
|
}
|
|
51
62
|
}
|
|
52
63
|
* { box-sizing: border-box; }
|
|
64
|
+
html, body { margin: 0; }
|
|
53
65
|
body {
|
|
54
|
-
margin: 0;
|
|
55
66
|
background: var(--bg);
|
|
56
67
|
color: var(--fg);
|
|
57
|
-
font: 14px/1.
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
.
|
|
65
|
-
.
|
|
66
|
-
.
|
|
68
|
+
font: 14px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
|
|
69
|
+
font-feature-settings: "tnum" 1;
|
|
70
|
+
}
|
|
71
|
+
main { max-width: 860px; margin: 0 auto; padding: 30px 24px 72px; }
|
|
72
|
+
body.embedded main { padding: 14px 16px 48px; }
|
|
73
|
+
|
|
74
|
+
/* Page head: title, lead, health strip */
|
|
75
|
+
.page-head h1 { font-size: 20px; font-weight: 650; letter-spacing: -0.01em; margin: 0 0 6px; display: flex; align-items: center; gap: 8px; }
|
|
76
|
+
.page-head h1 svg { flex: none; }
|
|
77
|
+
.lead { color: var(--muted); font-size: 13px; margin: 0 0 14px; max-width: 62ch; }
|
|
78
|
+
.healthstrip { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 6px; }
|
|
79
|
+
.pill { display: inline-flex; align-items: center; gap: 5px; border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
|
|
80
|
+
.pill.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 42%, var(--line)); }
|
|
81
|
+
.pill.bad { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 42%, var(--line)); }
|
|
82
|
+
.pill.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 42%, var(--line)); }
|
|
83
|
+
.hint { color: var(--muted); font-size: 12px; margin: 6px 0 0; }
|
|
84
|
+
|
|
85
|
+
/* Sections: continuous surface, hairline separated, no nested cards */
|
|
86
|
+
.section { padding: 20px 0; border-top: 1px solid var(--line); }
|
|
87
|
+
.section:first-of-type { border-top: 0; padding-top: 14px; }
|
|
88
|
+
.section-head { display: flex; align-items: baseline; gap: 10px; margin: 0 0 4px; }
|
|
89
|
+
.section-head h2 { font-size: 15px; font-weight: 650; margin: 0; letter-spacing: -0.005em; }
|
|
90
|
+
.section-head .count { font-size: 12px; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 1px 8px; font-variant-numeric: tabular-nums; }
|
|
91
|
+
.section-sub { color: var(--muted); font-size: 12.5px; margin: 0 0 14px; max-width: 66ch; }
|
|
92
|
+
|
|
93
|
+
/* Field rows */
|
|
94
|
+
.row { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: 8px 16px; align-items: center; margin: 0 0 12px; }
|
|
95
|
+
.row > label:first-child { color: var(--muted); font-size: 13px; }
|
|
67
96
|
.row.wide { grid-template-columns: 1fr; }
|
|
68
|
-
input[type=text], input[type=number], select, textarea {
|
|
69
|
-
width: 100%; padding: 7px
|
|
70
|
-
background: var(--bg); color: var(--fg); font: inherit;
|
|
97
|
+
input[type=text], input[type=number], input[type=password], select, textarea {
|
|
98
|
+
width: 100%; padding: 7px 10px; border: 1px solid var(--line-strong); border-radius: 8px;
|
|
99
|
+
background: var(--bg); color: var(--fg); font: inherit; min-height: 34px;
|
|
100
|
+
}
|
|
101
|
+
textarea { min-height: 68px; resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
|
|
102
|
+
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible {
|
|
103
|
+
outline: 2px solid var(--accent); outline-offset: 1px;
|
|
71
104
|
}
|
|
72
|
-
textarea { min-height: 70px; resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
|
|
73
105
|
.checks { display: flex; flex-wrap: wrap; gap: 10px 18px; }
|
|
74
|
-
.checks label { display: inline-flex; align-items: center; gap: 6px;
|
|
106
|
+
.checks label { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
|
|
107
|
+
|
|
108
|
+
/* Rule grid (notification toggles) */
|
|
109
|
+
.rule-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 10px; }
|
|
110
|
+
.rule { display: flex; gap: 9px; align-items: flex-start; border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; background: var(--subtle); }
|
|
111
|
+
.rule input { margin-top: 2px; }
|
|
112
|
+
.rule .rt { display: flex; flex-direction: column; gap: 1px; }
|
|
113
|
+
.rule .rt b { font-weight: 550; font-size: 13px; }
|
|
114
|
+
.rule .rt small { color: var(--muted); font-size: 12px; }
|
|
115
|
+
|
|
116
|
+
/* Buttons */
|
|
75
117
|
button {
|
|
76
|
-
appearance: none; border: 1px solid var(--line); background: var(--bg); color: var(--fg);
|
|
77
|
-
border-radius: 8px; padding: 7px 12px; font: inherit; cursor: pointer;
|
|
118
|
+
appearance: none; border: 1px solid var(--line-strong); background: var(--bg); color: var(--fg);
|
|
119
|
+
border-radius: 8px; padding: 7px 12px; font: inherit; font-size: 13px; cursor: pointer; min-height: 32px;
|
|
78
120
|
}
|
|
79
|
-
button
|
|
121
|
+
button:hover { border-color: var(--muted); }
|
|
122
|
+
button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 550; }
|
|
123
|
+
button.primary:hover { filter: brightness(1.04); }
|
|
80
124
|
button.danger { color: var(--bad); }
|
|
125
|
+
button.danger:hover { border-color: var(--bad); }
|
|
81
126
|
button:disabled { opacity: .5; cursor: default; }
|
|
82
|
-
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top:
|
|
83
|
-
.status {
|
|
84
|
-
.
|
|
85
|
-
.
|
|
86
|
-
.
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
.keylist
|
|
90
|
-
.
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
.
|
|
94
|
-
.
|
|
127
|
+
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 14px; }
|
|
128
|
+
.save-status { font-size: 12px; margin-left: 4px; }
|
|
129
|
+
.save-status.ok { color: var(--ok); }
|
|
130
|
+
.save-status.bad { color: var(--bad); }
|
|
131
|
+
.save-status.warn { color: var(--warn); }
|
|
132
|
+
|
|
133
|
+
/* Key list */
|
|
134
|
+
.keylist { display: flex; flex-direction: column; gap: 3px; margin: 0 0 6px; color: var(--muted); }
|
|
135
|
+
.keylist code { color: var(--fg); font-variant-numeric: tabular-nums; }
|
|
136
|
+
|
|
137
|
+
/* Advanced disclosure */
|
|
138
|
+
details.advanced { margin: 14px 0 2px; border: 1px solid var(--line); border-radius: var(--radius); padding: 2px 14px 10px; background: var(--subtle); }
|
|
139
|
+
details.advanced > summary { cursor: pointer; color: var(--accent); font-weight: 600; font-size: 13px; padding: 9px 0; list-style: none; user-select: none; }
|
|
140
|
+
details.advanced > summary::-webkit-details-marker { display: none; }
|
|
141
|
+
details.advanced > summary::before { content: '▸ '; }
|
|
142
|
+
details.advanced[open] > summary::before { content: '▾ '; }
|
|
143
|
+
.advanced-group { margin: 8px 0 2px; }
|
|
144
|
+
.advanced-group h3 { font-size: 12px; font-weight: 600; color: var(--muted); margin: 10px 0 8px; }
|
|
145
|
+
|
|
146
|
+
/* Channel lanes */
|
|
147
|
+
.lane { border: 1px solid var(--line); border-radius: var(--radius); background: var(--subtle); margin: 0 0 10px; }
|
|
148
|
+
.lane-head { display: flex; align-items: center; gap: 10px; padding: 10px 12px; flex-wrap: wrap; }
|
|
149
|
+
.lane .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 18%, transparent); }
|
|
150
|
+
.lane[data-enabled="0"] .dot { background: transparent; border: 1.5px solid var(--muted); box-shadow: none; }
|
|
151
|
+
.lane[data-enabled="0"] .lane-name { color: var(--muted); }
|
|
152
|
+
.lane-name { font-size: 14px; font-weight: 600; }
|
|
153
|
+
.tag { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 6px; padding: 0 6px; }
|
|
154
|
+
.lane-grow { flex: 1; }
|
|
155
|
+
.switch { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
|
|
156
|
+
.lane-toggle { padding: 5px 10px; min-height: 28px; }
|
|
157
|
+
.lane-head button { padding: 5px 10px; min-height: 28px; }
|
|
158
|
+
.lane-fields { padding: 6px 12px 12px; border-top: 1px dashed var(--line); }
|
|
159
|
+
.channel-field { display: grid; grid-template-columns: 190px minmax(0, 1fr); gap: 8px 14px; align-items: center; margin: 0 0 9px; }
|
|
160
|
+
.channel-field > label { color: var(--muted); font-size: 13px; }
|
|
161
|
+
.channel-field .req { color: var(--bad); }
|
|
162
|
+
.channel-add { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 14px; }
|
|
163
|
+
.channel-add select { max-width: 260px; }
|
|
164
|
+
.empty-channel { border: 1px dashed var(--line-strong); border-radius: var(--radius); padding: 18px; color: var(--muted); font-size: 13px; text-align: center; }
|
|
165
|
+
|
|
166
|
+
/* Test result breakdown */
|
|
167
|
+
.test-result { margin-top: 10px; border-top: 1px dashed var(--line); padding-top: 10px; display: flex; flex-direction: column; gap: 5px; }
|
|
168
|
+
.test-result .tr-title { font-size: 12.5px; font-weight: 600; }
|
|
169
|
+
.test-result .tr-row { display: flex; align-items: center; gap: 8px; font-size: 12.5px; }
|
|
170
|
+
.test-result .tr-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
171
|
+
.test-result .tr-msg { color: var(--muted); font-size: 12px; }
|
|
172
|
+
|
|
173
|
+
/* Mute lists */
|
|
174
|
+
.lists { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
|
|
175
|
+
@media (max-width: 720px) { .lists { grid-template-columns: 1fr; } .row { grid-template-columns: 1fr; } .channel-field { grid-template-columns: 1fr; } }
|
|
176
|
+
.list-title { font-size: 12.5px; color: var(--muted); margin: 0 0 8px; }
|
|
177
|
+
.list { max-height: 320px; overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); padding: 6px; }
|
|
178
|
+
.item { display: flex; gap: 9px; align-items: flex-start; padding: 6px; border-radius: 8px; }
|
|
179
|
+
.item:hover { background: var(--subtle); }
|
|
95
180
|
.item .meta { min-width: 0; }
|
|
96
|
-
.item .title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
181
|
+
.item .title { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
97
182
|
.item .sub { color: var(--muted); font-size: 12px; line-height: 1.45; overflow-wrap: anywhere; word-break: break-word; }
|
|
98
|
-
.empty { color: var(--muted); padding:
|
|
183
|
+
.empty { color: var(--muted); padding: 10px; font-size: 13px; }
|
|
184
|
+
|
|
185
|
+
.page-foot { color: var(--muted); font-size: 12px; margin-top: 30px; }
|
|
186
|
+
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
|
|
187
|
+
|
|
188
|
+
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
|
|
189
|
+
|
|
99
190
|
#toast {
|
|
100
191
|
position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
|
|
101
192
|
background: var(--fg); color: var(--bg); padding: 8px 14px; border-radius: 999px;
|
|
@@ -104,104 +195,146 @@ export function renderUiPage({ version, embedded = false }) {
|
|
|
104
195
|
}
|
|
105
196
|
#toast.show { opacity: 1; }
|
|
106
197
|
#toast.bad { background: var(--bad); color: #fff; }
|
|
107
|
-
.hint { color: var(--muted); font-size: 12px; margin: 4px 0 0; }
|
|
108
|
-
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
|
|
109
198
|
</style>
|
|
110
199
|
</head>
|
|
111
200
|
<body class="${embedded ? 'embedded' : ''}">
|
|
112
201
|
<main>
|
|
113
|
-
<
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
<div class="status" id="status"><span class="pill">读取中…</span></div>
|
|
202
|
+
<header class="page-head">
|
|
203
|
+
<h1><svg xmlns="http://www.w3.org/2000/svg" width="21" height="21" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M10.268 21a2 2 0 0 0 3.464 0"/><path d="M3.262 15.326A1 1 0 0 0 4 17h16a1 1 0 0 0 .74-1.673C19.41 13.956 18 12.499 18 8A6 6 0 0 0 6 8c0 4.499-1.411 5.956-2.738 7.326"/></svg>推送通知</h1>
|
|
204
|
+
<p class="lead">把 DSH 的回复、审批和选择请求推送到手机。默认使用 Bark,也可同时接入更多渠道;配置只保存在本机。</p>
|
|
205
|
+
<div class="healthstrip" id="status"><span class="pill">读取中…</span></div>
|
|
118
206
|
<p class="hint" id="warnings" hidden></p>
|
|
119
|
-
</
|
|
207
|
+
</header>
|
|
120
208
|
|
|
121
|
-
<
|
|
122
|
-
<h2
|
|
209
|
+
<section class="section" id="section-default">
|
|
210
|
+
<div class="section-head"><h2>默认渠道 · Bark</h2></div>
|
|
211
|
+
<p class="section-sub">Bark 是内置的第一渠道。填入服务器与 Device Key 即可使用;其余按需展开「高级选项」。</p>
|
|
123
212
|
<div class="row"><label for="server">Bark Server</label><input id="server" type="text" placeholder="https://api.day.app"></div>
|
|
124
|
-
<div class="row"><label>已配置 Device Key</label><div><div class="keylist" id="keylist"></div><p class="hint"
|
|
213
|
+
<div class="row"><label>已配置 Device Key</label><div><div class="keylist" id="keylist"></div><p class="hint">页面只显示掩码;新增密钥逐行粘贴,保存后不再显示完整值。</p></div></div>
|
|
125
214
|
<div class="row"><label for="newKeys">新增 Device Key</label><textarea id="newKeys" placeholder="每行一个"></textarea></div>
|
|
126
|
-
|
|
127
|
-
<
|
|
128
|
-
|
|
129
|
-
<
|
|
130
|
-
|
|
131
|
-
<
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
<
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
<
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
<
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
215
|
+
|
|
216
|
+
<details class="advanced" id="barkAdvanced">
|
|
217
|
+
<summary>高级选项(分组、级别与铃声、标题、长度、超时、跳转)</summary>
|
|
218
|
+
<p class="hint">以下为可选设置,保持默认即可;需要时再展开调整。</p>
|
|
219
|
+
|
|
220
|
+
<div class="advanced-group">
|
|
221
|
+
<h3>分组与图标</h3>
|
|
222
|
+
<div class="row"><label for="group">通知分组 Group</label><input id="group" type="text" placeholder="DSH"></div>
|
|
223
|
+
<div class="row"><label for="icon">图标 Icon(可选)</label><input id="icon" type="text" placeholder="https://…"></div>
|
|
224
|
+
</div>
|
|
225
|
+
|
|
226
|
+
<div class="advanced-group">
|
|
227
|
+
<h3>通知级别与铃声</h3>
|
|
228
|
+
<div class="row"><label for="levelReply">回复级别</label><select id="levelReply">
|
|
229
|
+
<option value="active">主动通知(active)</option>
|
|
230
|
+
<option value="timeSensitive">时效性通知(timeSensitive)</option>
|
|
231
|
+
<option value="passive">静默通知(passive)</option>
|
|
232
|
+
<option value="critical">紧急通知(critical)</option>
|
|
233
|
+
</select></div>
|
|
234
|
+
<div class="row"><label for="soundReply">回复铃声(可选)</label><input id="soundReply" type="text" placeholder="bell;留空用系统默认"></div>
|
|
235
|
+
<div class="row"><label for="levelApproval">审批级别</label><select id="levelApproval">
|
|
236
|
+
<option value="active">主动通知(active)</option>
|
|
237
|
+
<option value="timeSensitive">时效性通知(timeSensitive)</option>
|
|
238
|
+
<option value="passive">静默通知(passive)</option>
|
|
239
|
+
<option value="critical">紧急通知(critical)</option>
|
|
240
|
+
</select></div>
|
|
241
|
+
<div class="row"><label for="soundApproval">审批铃声(可选)</label><input id="soundApproval" type="text" placeholder="alarm;留空用系统默认"></div>
|
|
242
|
+
<div class="row"><label for="levelQuestion">选择级别</label><select id="levelQuestion">
|
|
243
|
+
<option value="active">主动通知(active)</option>
|
|
244
|
+
<option value="timeSensitive">时效性通知(timeSensitive)</option>
|
|
245
|
+
<option value="passive">静默通知(passive)</option>
|
|
246
|
+
<option value="critical">紧急通知(critical)</option>
|
|
247
|
+
</select></div>
|
|
248
|
+
<div class="row"><label for="soundQuestion">选择铃声(可选)</label><input id="soundQuestion" type="text" placeholder="bell;留空用系统默认"></div>
|
|
249
|
+
<p class="hint"><strong>级别说明</strong> 主动通知会亮屏提醒;时效性通知可在专注模式显示;静默通知只进通知中心;紧急通知可突破静音并在 Bark App 授权「重要警告」后生效(iOS 15+,未授权则降级为普通通知,铃声音量由 volume 控制)。</p>
|
|
250
|
+
</div>
|
|
251
|
+
|
|
252
|
+
<div class="advanced-group">
|
|
253
|
+
<h3>标题与长度</h3>
|
|
254
|
+
<div class="row"><label for="titleMode">回复标题来源</label><select id="titleMode">
|
|
255
|
+
<option value="session">会话标题</option>
|
|
256
|
+
<option value="session-summary">会话标题 + 回复摘要</option>
|
|
257
|
+
<option value="summary">回复摘要</option>
|
|
258
|
+
</select></div>
|
|
259
|
+
<div class="row"><label for="titlePrefix">标题前缀(可选)</label><input id="titlePrefix" type="text" placeholder="留空则只用所选标题"></div>
|
|
260
|
+
<div class="row"><label for="maxTitleLength">标题最大长度</label><input id="maxTitleLength" type="number" min="8" max="200"></div>
|
|
261
|
+
<div class="row"><label for="maxBodyLength">正文最大长度</label><input id="maxBodyLength" type="number" min="32" max="4000"></div>
|
|
262
|
+
</div>
|
|
263
|
+
|
|
264
|
+
<div class="advanced-group">
|
|
265
|
+
<h3>网络与重试</h3>
|
|
266
|
+
<div class="row"><label for="timeoutMs">请求超时(毫秒)</label><input id="timeoutMs" type="number" min="1000" max="30000"></div>
|
|
267
|
+
<div class="row"><label for="maxRetries">最大重试次数</label><input id="maxRetries" type="number" min="0" max="5"></div>
|
|
268
|
+
<div class="row"><label for="retryDelayMs">重试基础间隔(毫秒)</label><input id="retryDelayMs" type="number" min="50" max="10000"></div>
|
|
269
|
+
</div>
|
|
270
|
+
|
|
271
|
+
<div class="advanced-group">
|
|
272
|
+
<h3>跳转与调试</h3>
|
|
273
|
+
<div class="row"><label>点击通知跳转</label><div class="checks">
|
|
274
|
+
<label><input id="linkToSession" type="checkbox"> 打开对应会话</label>
|
|
275
|
+
<label><input id="trace" type="checkbox"> 调试日志</label>
|
|
276
|
+
</div></div>
|
|
277
|
+
<div class="row"><label for="publicBaseUrl">公共访问地址(可选)</label><input id="publicBaseUrl" type="text" placeholder="https://dsh.example.com/"></div>
|
|
278
|
+
<p class="hint">公共访问地址留空时使用 DSH 的 advertised URL;点击跳转依赖浏览器已登录(有 DSH 会话 Cookie)。</p>
|
|
279
|
+
</div>
|
|
280
|
+
</details>
|
|
281
|
+
|
|
179
282
|
<div class="actions">
|
|
180
|
-
<button class="primary" id="save"
|
|
181
|
-
<button id="test"
|
|
283
|
+
<button class="primary" id="save">保存全部更改</button>
|
|
284
|
+
<button id="test">测试默认渠道</button>
|
|
182
285
|
<button id="reset" class="danger">恢复默认</button>
|
|
183
286
|
<button id="addKeys">追加密钥</button>
|
|
184
287
|
<button id="clearKeys" class="danger">清空密钥</button>
|
|
288
|
+
<span id="barkSaveStatus" class="save-status" role="status" aria-live="polite"></span>
|
|
185
289
|
</div>
|
|
186
|
-
|
|
290
|
+
<div class="test-result" id="barkTestResult" hidden></div>
|
|
291
|
+
</section>
|
|
187
292
|
|
|
188
|
-
<
|
|
189
|
-
<h2
|
|
190
|
-
<p class="
|
|
293
|
+
<section class="section" id="section-rules">
|
|
294
|
+
<div class="section-head"><h2>通知规则</h2></div>
|
|
295
|
+
<p class="section-sub">选择哪些事件需要推送。总开关关闭后不发送任何通知。</p>
|
|
296
|
+
<div class="rule-grid">
|
|
297
|
+
<label class="rule"><input id="enabled" type="checkbox"><span class="rt"><b>总开关</b><small>关闭后暂停全部推送</small></span></label>
|
|
298
|
+
<label class="rule"><input id="notifyOnReply" type="checkbox"><span class="rt"><b>Agent 回复</b><small>一轮结束后推送最后回复</small></span></label>
|
|
299
|
+
<label class="rule"><input id="notifyOnApproval" type="checkbox"><span class="rt"><b>需要批准</b><small>工具请求授权时推送</small></span></label>
|
|
300
|
+
<label class="rule"><input id="notifyOnQuestion" type="checkbox"><span class="rt"><b>等待选择</b><small>等待你回答选择时推送</small></span></label>
|
|
301
|
+
<label class="rule"><input id="includeSubagents" type="checkbox"><span class="rt"><b>包含子代理</b><small>子代理会话也推送</small></span></label>
|
|
302
|
+
</div>
|
|
303
|
+
<div class="actions">
|
|
304
|
+
<button id="saveRules">保存全部更改</button>
|
|
305
|
+
<span id="rulesSaveStatus" class="save-status" role="status" aria-live="polite"></span>
|
|
306
|
+
</div>
|
|
307
|
+
</section>
|
|
308
|
+
|
|
309
|
+
<section class="section" id="section-channels">
|
|
310
|
+
<div class="section-head"><h2>渠道</h2><span class="count" id="channelCount">0</span></div>
|
|
311
|
+
<p class="section-sub">Bark 之外可同时启用多个渠道,互不影响;点「参数」展开填写,点「测试」单独验证该渠道。</p>
|
|
312
|
+
<div id="channelList"></div>
|
|
313
|
+
<div class="channel-add">
|
|
314
|
+
<select id="channelTypeSelect" aria-label="渠道类型"></select>
|
|
315
|
+
<button id="addChannel">添加渠道</button>
|
|
316
|
+
<button id="saveChannels">保存全部更改</button>
|
|
317
|
+
<span id="channelsSaveStatus" class="save-status" role="status" aria-live="polite"></span>
|
|
318
|
+
</div>
|
|
319
|
+
</section>
|
|
320
|
+
|
|
321
|
+
<section class="section" id="section-mute">
|
|
322
|
+
<div class="section-head"><h2>静音管理</h2></div>
|
|
323
|
+
<p class="section-sub">工作区静音优先于会话静音;任一层级静音即停止推送,状态持久化。</p>
|
|
191
324
|
<div class="lists">
|
|
192
325
|
<div>
|
|
193
|
-
<
|
|
326
|
+
<p class="list-title">工作区</p>
|
|
194
327
|
<div class="list" id="workspaces"><div class="empty">读取中…</div></div>
|
|
195
328
|
</div>
|
|
196
329
|
<div>
|
|
197
|
-
<
|
|
198
|
-
<input id="sessionSearch" type="text" placeholder="按标题或 ID 过滤" style="margin-bottom:
|
|
330
|
+
<p class="list-title">会话</p>
|
|
331
|
+
<input id="sessionSearch" type="text" placeholder="按标题或 ID 过滤" style="margin-bottom:8px">
|
|
199
332
|
<div class="list" id="sessions"><div class="empty">读取中…</div></div>
|
|
200
333
|
</div>
|
|
201
334
|
</div>
|
|
202
|
-
</
|
|
335
|
+
</section>
|
|
203
336
|
|
|
204
|
-
<
|
|
337
|
+
<footer class="page-foot">dsh-bark-push v${safeVersion} · 只向这里配置的推送渠道发送内容。</footer>
|
|
205
338
|
</main>
|
|
206
339
|
<div id="toast" role="status" aria-live="polite"></div>
|
|
207
340
|
<script>
|
|
@@ -212,21 +345,57 @@ export function renderUiPage({ version, embedded = false }) {
|
|
|
212
345
|
config: '/api/bark-push/config',
|
|
213
346
|
mute: '/api/bark-push/mute',
|
|
214
347
|
toggle: '/api/bark-push/toggle',
|
|
215
|
-
test: '/api/bark-push/test'
|
|
348
|
+
test: '/api/bark-push/test',
|
|
349
|
+
testChannel: '/api/bark-push/test-channel'
|
|
216
350
|
};
|
|
217
351
|
const $ = (id) => document.getElementById(id);
|
|
218
352
|
let current = null;
|
|
219
353
|
let toastTimer = null;
|
|
354
|
+
let channelTypes = [];
|
|
355
|
+
let channelDraft = [];
|
|
220
356
|
|
|
221
357
|
function toast(message, bad) {
|
|
358
|
+
const text = message == null ? '' : String(message);
|
|
359
|
+
// Embedded in the DSH Settings iframe the page has no scroll viewport of
|
|
360
|
+
// its own, so hand the notice to the parent which renders it in the
|
|
361
|
+
// frame-wide shell.overlay layer; also show a local toast when standalone.
|
|
362
|
+
if (window.parent && window.parent !== window) {
|
|
363
|
+
try {
|
|
364
|
+
window.parent.postMessage(
|
|
365
|
+
{ type: 'dsh-bark-push:toast', message: text, kind: bad ? 'bad' : 'ok' },
|
|
366
|
+
window.location.origin,
|
|
367
|
+
);
|
|
368
|
+
return;
|
|
369
|
+
} catch (_) { /* fall back to local toast */ }
|
|
370
|
+
}
|
|
222
371
|
const node = $('toast');
|
|
223
|
-
node
|
|
372
|
+
if (!node) return;
|
|
373
|
+
node.textContent = text;
|
|
224
374
|
node.className = 'show' + (bad ? ' bad' : '');
|
|
225
375
|
clearTimeout(toastTimer);
|
|
226
376
|
toastTimer = setTimeout(() => { node.className = ''; }, 3200);
|
|
227
377
|
}
|
|
228
378
|
|
|
229
|
-
|
|
379
|
+
function text(node, value) { node.textContent = value == null ? '' : String(value); }
|
|
380
|
+
|
|
381
|
+
function setSaveStatus(targetId, message, kind) {
|
|
382
|
+
const node = $(targetId);
|
|
383
|
+
if (!node) return;
|
|
384
|
+
node.textContent = message || '';
|
|
385
|
+
node.className = 'save-status' + (kind ? ' ' + kind : '');
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
function nowStamp() {
|
|
389
|
+
const d = new Date();
|
|
390
|
+
const pad = (n) => String(n).padStart(2, '0');
|
|
391
|
+
return pad(d.getHours()) + ':' + pad(d.getMinutes()) + ':' + pad(d.getSeconds());
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
function markChannelsDirty() {
|
|
395
|
+
setSaveStatus('channelsSaveStatus', '有未保存的更改,点“保存全部更改”生效', 'warn');
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
async function requestAllowFail(path, body) {
|
|
230
399
|
const response = await fetch(path, {
|
|
231
400
|
method: body === undefined ? 'GET' : 'POST',
|
|
232
401
|
credentials: 'same-origin',
|
|
@@ -237,13 +406,279 @@ export function renderUiPage({ version, embedded = false }) {
|
|
|
237
406
|
});
|
|
238
407
|
let payload = null;
|
|
239
408
|
try { payload = await response.json(); } catch (_) { payload = null; }
|
|
240
|
-
if (!response.ok || !payload
|
|
409
|
+
if (!response.ok || !payload) {
|
|
241
410
|
throw new Error((payload && payload.error) || ('HTTP ' + response.status));
|
|
242
411
|
}
|
|
243
412
|
return payload;
|
|
244
413
|
}
|
|
245
414
|
|
|
246
|
-
function
|
|
415
|
+
async function request(path, body) {
|
|
416
|
+
const payload = await requestAllowFail(path, body);
|
|
417
|
+
if (payload.ok === false) throw new Error(payload.error || '请求被拒绝');
|
|
418
|
+
return payload;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
function typeInfo(type) { return channelTypes.find((entry) => entry.type === type); }
|
|
422
|
+
function typeLabel(type) { const info = typeInfo(type); return info ? info.name : type; }
|
|
423
|
+
|
|
424
|
+
function genChannelId() {
|
|
425
|
+
return 'ch_' + Math.random().toString(36).slice(2, 10) + Date.now().toString(36).slice(-3);
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
function cloneChannel(channel) {
|
|
429
|
+
return {
|
|
430
|
+
id: channel.id,
|
|
431
|
+
type: channel.type,
|
|
432
|
+
label: channel.label || '',
|
|
433
|
+
enabled: channel.enabled !== false,
|
|
434
|
+
config: Object.assign({}, channel.config || {}),
|
|
435
|
+
secretsSet: Object.assign({}, channel.secretsSet || {})
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
function fillChannels(config) {
|
|
440
|
+
channelDraft = (Array.isArray(config.channels) ? config.channels : []).map(cloneChannel);
|
|
441
|
+
renderChannels();
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
// Pull current input values back into the channel draft so a re-render (add /
|
|
445
|
+
// remove / structural change) does not discard edits. An empty secret stays
|
|
446
|
+
// empty and the host keeps the stored value.
|
|
447
|
+
function syncChannels() {
|
|
448
|
+
const lanes = $('channelList') ? $('channelList').querySelectorAll('.channel') : [];
|
|
449
|
+
for (const lane of lanes) {
|
|
450
|
+
const index = Number(lane.dataset.index);
|
|
451
|
+
const channel = channelDraft[index];
|
|
452
|
+
if (!channel) continue;
|
|
453
|
+
const enabledBox = lane.querySelector('[data-role="enabled"]');
|
|
454
|
+
if (enabledBox) channel.enabled = enabledBox.checked;
|
|
455
|
+
const config = {};
|
|
456
|
+
lane.querySelectorAll('[data-field]').forEach((input) => {
|
|
457
|
+
const key = input.dataset.field;
|
|
458
|
+
if (input.dataset.kind === 'checkbox') config[key] = input.checked;
|
|
459
|
+
else config[key] = input.value;
|
|
460
|
+
});
|
|
461
|
+
channel.config = config;
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
function collectChannels() {
|
|
466
|
+
syncChannels();
|
|
467
|
+
return channelDraft.map((channel) => ({
|
|
468
|
+
id: channel.id, type: channel.type, label: channel.label || '',
|
|
469
|
+
enabled: channel.enabled !== false, config: Object.assign({}, channel.config)
|
|
470
|
+
}));
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
function channelButton(label, cls, onClick) {
|
|
474
|
+
const button = document.createElement('button');
|
|
475
|
+
button.type = 'button';
|
|
476
|
+
button.textContent = label;
|
|
477
|
+
if (cls) button.className = cls;
|
|
478
|
+
button.addEventListener('click', onClick);
|
|
479
|
+
return button;
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
function renderChannels() {
|
|
483
|
+
const box = $('channelList');
|
|
484
|
+
if (!box) return;
|
|
485
|
+
box.replaceChildren();
|
|
486
|
+
if (!channelDraft.length) {
|
|
487
|
+
const empty = document.createElement('div');
|
|
488
|
+
empty.className = 'empty-channel';
|
|
489
|
+
text(empty, '还没有额外渠道。选下面的类型,点“添加渠道”即可接入。');
|
|
490
|
+
box.append(empty);
|
|
491
|
+
}
|
|
492
|
+
channelDraft.forEach((channel, index) => box.append(channelCard(channel, index)));
|
|
493
|
+
const select = $('channelTypeSelect');
|
|
494
|
+
if (select && select.options.length === 0) {
|
|
495
|
+
for (const entry of channelTypes) {
|
|
496
|
+
const option = document.createElement('option');
|
|
497
|
+
option.value = entry.type;
|
|
498
|
+
option.textContent = entry.name;
|
|
499
|
+
select.append(option);
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
function channelCard(channel, index) {
|
|
505
|
+
const info = typeInfo(channel.type);
|
|
506
|
+
const lane = document.createElement('div');
|
|
507
|
+
lane.className = 'lane channel';
|
|
508
|
+
lane.dataset.index = String(index);
|
|
509
|
+
lane.dataset.id = channel.id;
|
|
510
|
+
lane.dataset.enabled = channel.enabled !== false ? '1' : '0';
|
|
511
|
+
|
|
512
|
+
const head = document.createElement('div');
|
|
513
|
+
head.className = 'lane-head';
|
|
514
|
+
const dot = document.createElement('span');
|
|
515
|
+
dot.className = 'dot';
|
|
516
|
+
dot.setAttribute('aria-hidden', 'true');
|
|
517
|
+
const name = document.createElement('span');
|
|
518
|
+
name.className = 'lane-name';
|
|
519
|
+
text(name, channel.label || (info ? info.name : channel.type));
|
|
520
|
+
const tag = document.createElement('span');
|
|
521
|
+
tag.className = 'tag';
|
|
522
|
+
text(tag, info ? info.name : channel.type);
|
|
523
|
+
const grow = document.createElement('span');
|
|
524
|
+
grow.className = 'lane-grow';
|
|
525
|
+
|
|
526
|
+
const sw = document.createElement('label');
|
|
527
|
+
sw.className = 'switch';
|
|
528
|
+
const enabledBox = document.createElement('input');
|
|
529
|
+
enabledBox.type = 'checkbox';
|
|
530
|
+
enabledBox.checked = channel.enabled !== false;
|
|
531
|
+
enabledBox.dataset.role = 'enabled';
|
|
532
|
+
enabledBox.addEventListener('change', () => {
|
|
533
|
+
channel.enabled = enabledBox.checked;
|
|
534
|
+
lane.dataset.enabled = channel.enabled ? '1' : '0';
|
|
535
|
+
markChannelsDirty();
|
|
536
|
+
toast((channel.label || (info ? info.name : '渠道')) + (channel.enabled ? ' 已启用,点保存生效' : ' 已停用,点保存生效'));
|
|
537
|
+
});
|
|
538
|
+
sw.append(enabledBox, document.createTextNode('启用'));
|
|
539
|
+
|
|
540
|
+
const toggle = channelButton('参数', 'lane-toggle', () => {
|
|
541
|
+
const fields = lane.querySelector('.lane-fields');
|
|
542
|
+
const opening = fields.hidden;
|
|
543
|
+
fields.hidden = !opening;
|
|
544
|
+
toggle.textContent = opening ? '收起' : '参数';
|
|
545
|
+
toggle.setAttribute('aria-expanded', opening ? 'true' : 'false');
|
|
546
|
+
});
|
|
547
|
+
toggle.setAttribute('aria-expanded', 'false');
|
|
548
|
+
|
|
549
|
+
const testBtn = channelButton('测试', '', () => testChannel(channel.id, testBtn, info));
|
|
550
|
+
const removeBtn = channelButton('删除', 'danger', () => {
|
|
551
|
+
syncChannels();
|
|
552
|
+
channelDraft = channelDraft.filter((entry) => entry.id !== channel.id);
|
|
553
|
+
renderChannels();
|
|
554
|
+
markChannelsDirty();
|
|
555
|
+
toast('已移除渠道「' + (channel.label || (info ? info.name : channel.type)) + '」,点保存生效');
|
|
556
|
+
});
|
|
557
|
+
head.append(dot, name, tag, grow, sw, toggle, testBtn, removeBtn);
|
|
558
|
+
lane.append(head);
|
|
559
|
+
|
|
560
|
+
const fields = document.createElement('div');
|
|
561
|
+
fields.className = 'lane-fields';
|
|
562
|
+
fields.hidden = true;
|
|
563
|
+
for (const field of (info ? info.fields : [])) {
|
|
564
|
+
const row = document.createElement('div');
|
|
565
|
+
row.className = 'channel-field';
|
|
566
|
+
const label = document.createElement('label');
|
|
567
|
+
text(label, field.label);
|
|
568
|
+
if (field.required) {
|
|
569
|
+
const star = document.createElement('span');
|
|
570
|
+
star.className = 'req';
|
|
571
|
+
text(star, ' *');
|
|
572
|
+
label.append(star);
|
|
573
|
+
}
|
|
574
|
+
let input;
|
|
575
|
+
if (field.kind === 'select') {
|
|
576
|
+
input = document.createElement('select');
|
|
577
|
+
for (const option of field.options || []) {
|
|
578
|
+
const opt = document.createElement('option');
|
|
579
|
+
opt.value = option.value;
|
|
580
|
+
opt.textContent = option.label;
|
|
581
|
+
input.append(opt);
|
|
582
|
+
}
|
|
583
|
+
input.value = channel.config && channel.config[field.key] !== undefined ? channel.config[field.key] : (field.default || '');
|
|
584
|
+
} else if (field.kind === 'textarea') {
|
|
585
|
+
input = document.createElement('textarea');
|
|
586
|
+
input.value = channel.config && channel.config[field.key] != null ? channel.config[field.key] : '';
|
|
587
|
+
if (field.placeholder) input.placeholder = field.placeholder;
|
|
588
|
+
} else if (field.kind === 'checkbox') {
|
|
589
|
+
input = document.createElement('input');
|
|
590
|
+
input.type = 'checkbox';
|
|
591
|
+
input.checked = channel.config ? channel.config[field.key] === true : field.default === true;
|
|
592
|
+
} else {
|
|
593
|
+
input = document.createElement('input');
|
|
594
|
+
input.type = field.kind === 'secret' ? 'password' : field.kind === 'number' ? 'number' : 'text';
|
|
595
|
+
const stored = channel.config ? channel.config[field.key] : undefined;
|
|
596
|
+
const alreadySet = field.kind === 'secret' && channel.secretsSet && channel.secretsSet[field.key];
|
|
597
|
+
input.value = alreadySet ? '' : (stored != null ? stored : (field.default || ''));
|
|
598
|
+
if (alreadySet) input.placeholder = '已设置,留空保持不变';
|
|
599
|
+
else if (field.placeholder) input.placeholder = field.placeholder;
|
|
600
|
+
}
|
|
601
|
+
input.dataset.field = field.key;
|
|
602
|
+
input.dataset.kind = field.kind;
|
|
603
|
+
input.addEventListener('input', markChannelsDirty);
|
|
604
|
+
row.append(label, input);
|
|
605
|
+
fields.append(row);
|
|
606
|
+
}
|
|
607
|
+
lane.append(fields);
|
|
608
|
+
|
|
609
|
+
const result = document.createElement('div');
|
|
610
|
+
result.className = 'test-result channel-result';
|
|
611
|
+
result.hidden = true;
|
|
612
|
+
lane.append(result);
|
|
613
|
+
return lane;
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
async function testChannel(id, button, info) {
|
|
617
|
+
button.disabled = true;
|
|
618
|
+
try {
|
|
619
|
+
const saved = await request(api.config, collect());
|
|
620
|
+
current = saved;
|
|
621
|
+
if (Array.isArray(saved.channelTypes)) channelTypes = saved.channelTypes;
|
|
622
|
+
fill(saved.config);
|
|
623
|
+
status(saved);
|
|
624
|
+
renderMutes(saved);
|
|
625
|
+
const data = await requestAllowFail(api.testChannel, { id });
|
|
626
|
+
const detail = (data.result && data.result.results && data.result.results[0]) || {};
|
|
627
|
+
renderChannelTestResult(id, data.result || {});
|
|
628
|
+
if (data.ok) toast((info ? info.name : '渠道') + ' 测试成功');
|
|
629
|
+
else toast((info ? info.name : '渠道') + ' 测试失败:' + (detail.message || detail.reason || '未知错误'), true);
|
|
630
|
+
} catch (error) {
|
|
631
|
+
toast('测试失败:' + error.message, true);
|
|
632
|
+
} finally {
|
|
633
|
+
button.disabled = false;
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
function renderResultInto(box, result) {
|
|
638
|
+
if (!box) return;
|
|
639
|
+
const results = (result && Array.isArray(result.results)) ? result.results : [];
|
|
640
|
+
box.replaceChildren();
|
|
641
|
+
if (!results.length) { box.hidden = true; return; }
|
|
642
|
+
const title = document.createElement('div');
|
|
643
|
+
title.className = 'tr-title';
|
|
644
|
+
const okCount = results.filter((entry) => entry.ok === true).length;
|
|
645
|
+
text(title, '测试结果:' + okCount + ' 成功 / ' + (results.length - okCount) + ' 失败');
|
|
646
|
+
box.append(title);
|
|
647
|
+
for (const entry of results) {
|
|
648
|
+
const row = document.createElement('div');
|
|
649
|
+
row.className = 'tr-row';
|
|
650
|
+
const name = document.createElement('span');
|
|
651
|
+
name.className = 'tr-name';
|
|
652
|
+
text(name, entry.channelType ? (entry.label || typeLabel(entry.channelType)) : ('Bark ' + (entry.maskedKey || '设备')));
|
|
653
|
+
const pill = document.createElement('span');
|
|
654
|
+
if (entry.ok === true) { pill.className = 'pill ok'; text(pill, '成功'); }
|
|
655
|
+
else if (entry.skipped === true) { pill.className = 'pill warn'; text(pill, '未发送'); }
|
|
656
|
+
else { pill.className = 'pill bad'; text(pill, '失败'); }
|
|
657
|
+
row.append(name, pill);
|
|
658
|
+
const reason = entry.message || entry.reason || '';
|
|
659
|
+
if (reason && entry.ok !== true) {
|
|
660
|
+
const msg = document.createElement('span');
|
|
661
|
+
msg.className = 'tr-msg';
|
|
662
|
+
text(msg, reason);
|
|
663
|
+
row.append(msg);
|
|
664
|
+
}
|
|
665
|
+
box.append(row);
|
|
666
|
+
}
|
|
667
|
+
box.hidden = false;
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
function renderBarkTestResult(result) { renderResultInto($('barkTestResult'), result); }
|
|
671
|
+
|
|
672
|
+
function findChannelCard(id) {
|
|
673
|
+
const lanes = $('channelList') ? $('channelList').querySelectorAll('.channel') : [];
|
|
674
|
+
for (const lane of lanes) if (lane.dataset && lane.dataset.id === id) return lane;
|
|
675
|
+
return null;
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
function renderChannelTestResult(id, result) {
|
|
679
|
+
const lane = findChannelCard(id);
|
|
680
|
+
renderResultInto(lane ? lane.querySelector('.channel-result') : null, result);
|
|
681
|
+
}
|
|
247
682
|
|
|
248
683
|
function fill(config) {
|
|
249
684
|
$('server').value = config.server || '';
|
|
@@ -287,9 +722,12 @@ export function renderUiPage({ version, embedded = false }) {
|
|
|
287
722
|
list.append(line);
|
|
288
723
|
}
|
|
289
724
|
}
|
|
725
|
+
fillChannels(config);
|
|
290
726
|
}
|
|
291
727
|
|
|
292
728
|
function status(data) {
|
|
729
|
+
if (Array.isArray(data.channelTypes) && data.channelTypes.length > 0) channelTypes = data.channelTypes;
|
|
730
|
+
const cfg = data.config || {};
|
|
293
731
|
const node = $('status');
|
|
294
732
|
node.replaceChildren();
|
|
295
733
|
const add = (label, cls) => {
|
|
@@ -298,11 +736,19 @@ export function renderUiPage({ version, embedded = false }) {
|
|
|
298
736
|
text(pill, label);
|
|
299
737
|
node.append(pill);
|
|
300
738
|
};
|
|
301
|
-
add(
|
|
302
|
-
add((
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
739
|
+
add(cfg.enabled ? '已启用' : '已停用', cfg.enabled ? 'ok' : 'warn');
|
|
740
|
+
add((cfg.deviceKeyCount || 0) + ' 台设备', cfg.deviceKeyCount ? '' : 'warn');
|
|
741
|
+
const channelCount = Array.isArray(cfg.channels) ? cfg.channels.length : 0;
|
|
742
|
+
add(channelCount + ' 个渠道');
|
|
743
|
+
const recent = [];
|
|
744
|
+
if (data.lastTest) recent.push('测试' + (data.lastTest.ok ? ' ✓' : ' ✗'));
|
|
745
|
+
if (data.lastDelivery) {
|
|
746
|
+
const d = data.lastDelivery;
|
|
747
|
+
recent.push(labelOf(d.kind) + (d.ok ? ' ✓' : d.skipped ? ' –' : ' ✗'));
|
|
748
|
+
}
|
|
749
|
+
if (recent.length) add('最近 ' + recent.join(' · '), data.lastDelivery && data.lastDelivery.ok === false ? 'warn' : '');
|
|
750
|
+
const countEl = $('channelCount');
|
|
751
|
+
if (countEl) text(countEl, String(channelCount));
|
|
306
752
|
|
|
307
753
|
const warnings = $('warnings');
|
|
308
754
|
if (data.warnings && data.warnings.length) {
|
|
@@ -343,11 +789,7 @@ export function renderUiPage({ version, embedded = false }) {
|
|
|
343
789
|
sessionBox.append(empty);
|
|
344
790
|
}
|
|
345
791
|
for (const session of rows) {
|
|
346
|
-
const subLines = [
|
|
347
|
-
session.id,
|
|
348
|
-
session.workspaceId ? ('工作区 ' + session.workspaceId) : '',
|
|
349
|
-
session.offline ? '离线' : '',
|
|
350
|
-
].filter(Boolean);
|
|
792
|
+
const subLines = [session.id, session.workspaceId ? ('工作区 ' + session.workspaceId) : '', session.offline ? '离线' : ''].filter(Boolean);
|
|
351
793
|
sessionBox.append(muteRow('session', session.id, session.title || '未命名会话', subLines, mutedSessions.has(session.id)));
|
|
352
794
|
}
|
|
353
795
|
}
|
|
@@ -379,8 +821,8 @@ export function renderUiPage({ version, embedded = false }) {
|
|
|
379
821
|
const titleNode = document.createElement('div');
|
|
380
822
|
titleNode.className = 'title';
|
|
381
823
|
text(titleNode, title);
|
|
382
|
-
const subLines = Array.isArray(sub) ? sub : [sub];
|
|
383
824
|
meta.append(titleNode);
|
|
825
|
+
const subLines = Array.isArray(sub) ? sub : [sub];
|
|
384
826
|
for (const line of subLines) {
|
|
385
827
|
if (!line) continue;
|
|
386
828
|
const subNode = document.createElement('div');
|
|
@@ -392,9 +834,6 @@ export function renderUiPage({ version, embedded = false }) {
|
|
|
392
834
|
return item;
|
|
393
835
|
}
|
|
394
836
|
|
|
395
|
-
// The Settings shell embeds this page in an iframe. Report the content
|
|
396
|
-
// height so the host can grow the iframe and leave only one scrollbar
|
|
397
|
-
// (the Settings modal's), instead of nesting two vertical scrollbars.
|
|
398
837
|
function postHeight() {
|
|
399
838
|
if (window.parent === window) return;
|
|
400
839
|
const height = Math.max(
|
|
@@ -402,23 +841,19 @@ export function renderUiPage({ version, embedded = false }) {
|
|
|
402
841
|
document.documentElement ? document.documentElement.scrollHeight : 0,
|
|
403
842
|
);
|
|
404
843
|
if (!Number.isFinite(height) || height <= 0) return;
|
|
405
|
-
window.parent.postMessage(
|
|
406
|
-
{ type: 'dsh-bark-push:height', height },
|
|
407
|
-
window.location.origin,
|
|
408
|
-
);
|
|
844
|
+
window.parent.postMessage({ type: 'dsh-bark-push:height', height }, window.location.origin);
|
|
409
845
|
}
|
|
410
846
|
|
|
411
847
|
if (window.parent !== window) {
|
|
412
848
|
window.addEventListener('load', postHeight);
|
|
413
|
-
if (typeof ResizeObserver !== 'undefined')
|
|
414
|
-
new ResizeObserver(postHeight).observe(document.body);
|
|
415
|
-
}
|
|
849
|
+
if (typeof ResizeObserver !== 'undefined') new ResizeObserver(postHeight).observe(document.body);
|
|
416
850
|
setTimeout(postHeight, 50);
|
|
417
851
|
setTimeout(postHeight, 400);
|
|
418
852
|
}
|
|
419
853
|
|
|
420
854
|
function collect() {
|
|
421
855
|
return {
|
|
856
|
+
channels: collectChannels(),
|
|
422
857
|
server: $('server').value,
|
|
423
858
|
group: $('group').value,
|
|
424
859
|
icon: $('icon').value,
|
|
@@ -450,6 +885,7 @@ export function renderUiPage({ version, embedded = false }) {
|
|
|
450
885
|
try {
|
|
451
886
|
const data = await request(api.state);
|
|
452
887
|
current = data;
|
|
888
|
+
if (Array.isArray(data.channelTypes)) channelTypes = data.channelTypes;
|
|
453
889
|
fill(data.config);
|
|
454
890
|
status(data);
|
|
455
891
|
renderMutes(data);
|
|
@@ -458,22 +894,50 @@ export function renderUiPage({ version, embedded = false }) {
|
|
|
458
894
|
}
|
|
459
895
|
}
|
|
460
896
|
|
|
461
|
-
|
|
462
|
-
|
|
897
|
+
const STATUS_BY_BUTTON = { saveChannels: 'channelsSaveStatus', saveRules: 'rulesSaveStatus', save: 'barkSaveStatus' };
|
|
898
|
+
|
|
899
|
+
// Single save path shared by every section's "保存全部更改" button. It always
|
|
900
|
+
// persists the whole config; only the inline status location differs.
|
|
901
|
+
async function persistConfig(button) {
|
|
902
|
+
const statusId = (button && STATUS_BY_BUTTON[button.id]) || 'barkSaveStatus';
|
|
903
|
+
if (button) button.disabled = true;
|
|
904
|
+
setSaveStatus(statusId, '保存中…', '');
|
|
463
905
|
try {
|
|
464
906
|
const data = await request(api.config, collect());
|
|
465
907
|
current = data;
|
|
908
|
+
if (Array.isArray(data.channelTypes) && data.channelTypes.length > 0) channelTypes = data.channelTypes;
|
|
466
909
|
fill(data.config);
|
|
467
910
|
status(data);
|
|
468
911
|
renderMutes(data);
|
|
912
|
+
setSaveStatus(statusId, '已保存 ' + nowStamp(), 'ok');
|
|
469
913
|
toast('配置已保存');
|
|
914
|
+
return true;
|
|
470
915
|
} catch (error) {
|
|
916
|
+
setSaveStatus(statusId, '保存失败:' + (error.message || '未知错误'), 'bad');
|
|
471
917
|
toast('保存失败:' + error.message, true);
|
|
918
|
+
return false;
|
|
472
919
|
} finally {
|
|
473
|
-
|
|
920
|
+
if (button) button.disabled = false;
|
|
474
921
|
}
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
$('addChannel').addEventListener('click', () => {
|
|
925
|
+
syncChannels();
|
|
926
|
+
const type = $('channelTypeSelect').value;
|
|
927
|
+
const info = typeInfo(type);
|
|
928
|
+
if (!info) { toast('请选择渠道类型', true); return; }
|
|
929
|
+
const config = {};
|
|
930
|
+
for (const field of info.fields) if (field.default !== undefined) config[field.key] = field.default;
|
|
931
|
+
channelDraft.push({ id: genChannelId(), type, label: '', enabled: true, config, secretsSet: {} });
|
|
932
|
+
renderChannels();
|
|
933
|
+
markChannelsDirty();
|
|
934
|
+
toast('已添加 ' + info.name + ',展开“参数”填写后保存');
|
|
475
935
|
});
|
|
476
936
|
|
|
937
|
+
$('save').addEventListener('click', () => { void persistConfig($('save')); });
|
|
938
|
+
$('saveChannels').addEventListener('click', () => { void persistConfig($('saveChannels')); });
|
|
939
|
+
$('saveRules').addEventListener('click', () => { void persistConfig($('saveRules')); });
|
|
940
|
+
|
|
477
941
|
$('addKeys').addEventListener('click', async () => {
|
|
478
942
|
const raw = $('newKeys').value.trim();
|
|
479
943
|
if (!raw) { toast('请先粘贴至少一个 Device Key', true); return; }
|
|
@@ -486,6 +950,7 @@ export function renderUiPage({ version, embedded = false }) {
|
|
|
486
950
|
fill(data.config);
|
|
487
951
|
status(data);
|
|
488
952
|
renderMutes(data);
|
|
953
|
+
setSaveStatus('barkSaveStatus', '已追加 ' + keys.length + ' 个密钥', 'ok');
|
|
489
954
|
toast('已追加 ' + keys.length + ' 个密钥');
|
|
490
955
|
} catch (error) {
|
|
491
956
|
toast('保存失败:' + error.message, true);
|
|
@@ -502,6 +967,7 @@ export function renderUiPage({ version, embedded = false }) {
|
|
|
502
967
|
fill(data.config);
|
|
503
968
|
status(data);
|
|
504
969
|
renderMutes(data);
|
|
970
|
+
setSaveStatus('barkSaveStatus', '已清空 Device Key', 'ok');
|
|
505
971
|
toast('已清空 Device Key');
|
|
506
972
|
} catch (error) {
|
|
507
973
|
toast('保存失败:' + error.message, true);
|
|
@@ -509,13 +975,14 @@ export function renderUiPage({ version, embedded = false }) {
|
|
|
509
975
|
});
|
|
510
976
|
|
|
511
977
|
$('reset').addEventListener('click', async () => {
|
|
512
|
-
if (!window.confirm('
|
|
978
|
+
if (!window.confirm('恢复默认配置?静音状态、Device Key 与已配置渠道不会被清除。')) return;
|
|
513
979
|
try {
|
|
514
980
|
const data = await request(api.config, { reset: true });
|
|
515
981
|
current = data;
|
|
516
982
|
fill(data.config);
|
|
517
983
|
status(data);
|
|
518
984
|
renderMutes(data);
|
|
985
|
+
setSaveStatus('barkSaveStatus', '已恢复默认', 'ok');
|
|
519
986
|
toast('已恢复默认配置');
|
|
520
987
|
} catch (error) {
|
|
521
988
|
toast('恢复失败:' + error.message, true);
|
|
@@ -525,7 +992,7 @@ export function renderUiPage({ version, embedded = false }) {
|
|
|
525
992
|
$('test').addEventListener('click', async () => {
|
|
526
993
|
$('test').disabled = true;
|
|
527
994
|
try {
|
|
528
|
-
const data = await
|
|
995
|
+
const data = await requestAllowFail(api.test, {});
|
|
529
996
|
if (data.state) {
|
|
530
997
|
current = data.state;
|
|
531
998
|
fill(data.state.config);
|
|
@@ -533,9 +1000,14 @@ export function renderUiPage({ version, embedded = false }) {
|
|
|
533
1000
|
renderMutes(data.state);
|
|
534
1001
|
}
|
|
535
1002
|
const result = data.result || {};
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
1003
|
+
renderBarkTestResult(result);
|
|
1004
|
+
const results = Array.isArray(result.results) ? result.results : [];
|
|
1005
|
+
if (result.skipped) toast('未发送:' + (result.reason || '尚未配置 Device Key'), true);
|
|
1006
|
+
else if (results.length > 0) {
|
|
1007
|
+
const okCount = results.filter((entry) => entry.ok === true).length;
|
|
1008
|
+
if (okCount === results.length) toast('测试推送成功(' + okCount + ' 台设备)');
|
|
1009
|
+
else toast('测试完成:' + okCount + ' 成功 / ' + (results.length - okCount) + ' 失败(详见下方结果)', true);
|
|
1010
|
+
} else toast(result.ok ? '测试推送成功' : '测试推送失败', result.ok !== true);
|
|
539
1011
|
} catch (error) {
|
|
540
1012
|
toast('测试失败:' + error.message, true);
|
|
541
1013
|
} finally {
|