whistle.mock-plugins 1.3.1 → 1.4.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/VERSION.md +15 -0
- package/app/cgi-bin/settings.js +1 -0
- package/app/cgi-bin/webdav.js +56 -0
- package/app/public/js/index.js +1 -1
- package/app/public/js/index.js.LICENSE.txt +12 -0
- package/lib/routes/settings.js +1 -0
- package/lib/webdav-sync.js +806 -0
- package/package.json +1 -1
- package/test/api-error.test.js +29 -0
- package/test/webdav-sync.test.js +428 -0
- package/ui/src/components/WebDavSyncModal.js +516 -0
- package/ui/src/pages/MockDataV2.js +35 -2
- package/ui/src/pages/Settings.js +43 -1
- package/ui/src/styles/webdav-sync.css +408 -0
- package/ui/src/utils/api-error.js +57 -0
|
@@ -0,0 +1,408 @@
|
|
|
1
|
+
.webdav-sync-modal .ant-modal-content {
|
|
2
|
+
display: flex;
|
|
3
|
+
max-height: calc(100vh - 24px);
|
|
4
|
+
flex-direction: column;
|
|
5
|
+
overflow: hidden;
|
|
6
|
+
padding: 0;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.webdav-sync-modal {
|
|
10
|
+
top: 12px;
|
|
11
|
+
max-width: calc(100vw - 32px);
|
|
12
|
+
padding-bottom: 0;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.webdav-sync-modal-wrap {
|
|
16
|
+
overflow: hidden;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.webdav-sync-modal .ant-modal-body {
|
|
20
|
+
min-height: 0;
|
|
21
|
+
overflow-y: auto;
|
|
22
|
+
overscroll-behavior: contain;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.webdav-sync-modal .ant-modal-close {
|
|
26
|
+
top: 12px;
|
|
27
|
+
color: rgba(255, 255, 255, 0.86);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.webdav-sync-hero {
|
|
31
|
+
display: grid;
|
|
32
|
+
grid-template-columns: auto minmax(0, 1fr) auto;
|
|
33
|
+
align-items: center;
|
|
34
|
+
gap: 12px;
|
|
35
|
+
padding: 14px 20px;
|
|
36
|
+
color: #fff;
|
|
37
|
+
background:
|
|
38
|
+
radial-gradient(circle at 85% 0%, rgba(56, 189, 248, 0.32), transparent 38%),
|
|
39
|
+
linear-gradient(135deg, #102a43 0%, #0b7285 100%);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.webdav-sync-hero .ant-typography {
|
|
43
|
+
margin: 0;
|
|
44
|
+
color: inherit;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.webdav-sync-hero .ant-typography.ant-typography-secondary {
|
|
48
|
+
color: rgba(255, 255, 255, 0.68);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.webdav-sync-hero-copy {
|
|
52
|
+
min-width: 0;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.webdav-sync-hero-copy .ant-typography:last-child {
|
|
56
|
+
font-size: 13px;
|
|
57
|
+
white-space: nowrap;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.webdav-sync-hero-icon {
|
|
61
|
+
display: flex;
|
|
62
|
+
width: 40px;
|
|
63
|
+
height: 40px;
|
|
64
|
+
align-items: center;
|
|
65
|
+
justify-content: center;
|
|
66
|
+
border: 1px solid rgba(255, 255, 255, 0.25);
|
|
67
|
+
border-radius: 11px;
|
|
68
|
+
background: rgba(255, 255, 255, 0.12);
|
|
69
|
+
font-size: 20px;
|
|
70
|
+
box-shadow: inset 0 1px rgba(255, 255, 255, 0.18);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
.webdav-sync-kicker {
|
|
74
|
+
display: block;
|
|
75
|
+
margin-bottom: 1px !important;
|
|
76
|
+
color: #67e8f9 !important;
|
|
77
|
+
font-size: 9px;
|
|
78
|
+
font-weight: 700;
|
|
79
|
+
letter-spacing: 0.18em;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.webdav-sync-grid {
|
|
83
|
+
display: grid;
|
|
84
|
+
grid-template-columns: minmax(0, 1.55fr) minmax(260px, 0.65fr);
|
|
85
|
+
gap: 12px;
|
|
86
|
+
padding: 12px;
|
|
87
|
+
background: #f3f6f8;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
.webdav-sync-error {
|
|
91
|
+
margin: 10px 12px 0;
|
|
92
|
+
padding: 8px 12px;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
.webdav-sync-error .ant-alert-description {
|
|
96
|
+
overflow-wrap: anywhere;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
.webdav-sync-modal .ant-descriptions-item-label {
|
|
100
|
+
width: 82px;
|
|
101
|
+
white-space: nowrap;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
.webdav-sync-modal .ant-descriptions-item-content {
|
|
105
|
+
min-width: 0;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
.webdav-sync-card,
|
|
109
|
+
.webdav-sync-note,
|
|
110
|
+
.webdav-sync-status-card,
|
|
111
|
+
.webdav-sync-connection-card,
|
|
112
|
+
.webdav-sync-module-card {
|
|
113
|
+
border-radius: 10px;
|
|
114
|
+
box-shadow: 0 5px 18px rgba(15, 42, 67, 0.06);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
.webdav-sync-card .ant-card-body,
|
|
118
|
+
.webdav-sync-note .ant-card-body {
|
|
119
|
+
padding: 16px;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
.webdav-sync-modal .ant-form-item {
|
|
123
|
+
margin-bottom: 14px;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
.webdav-sync-connected {
|
|
127
|
+
display: grid;
|
|
128
|
+
gap: 10px;
|
|
129
|
+
padding: 12px;
|
|
130
|
+
background: #f3f6f8;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
.webdav-sync-connection-card .ant-card-body {
|
|
134
|
+
display: grid;
|
|
135
|
+
grid-template-columns: minmax(0, 1fr) auto;
|
|
136
|
+
align-items: end;
|
|
137
|
+
gap: 12px;
|
|
138
|
+
padding: 12px 16px;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
.webdav-sync-connection-card .ant-descriptions {
|
|
142
|
+
min-width: 0;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
.webdav-sync-connection-card .ant-descriptions-header {
|
|
146
|
+
margin-bottom: 8px;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
.webdav-sync-connection-card .ant-descriptions-row > th,
|
|
150
|
+
.webdav-sync-connection-card .ant-descriptions-row > td {
|
|
151
|
+
padding-bottom: 6px;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
.webdav-sync-form-row {
|
|
155
|
+
display: grid;
|
|
156
|
+
grid-template-columns: 1fr 1fr;
|
|
157
|
+
gap: 12px;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
.webdav-sync-form-actions,
|
|
161
|
+
.webdav-sync-form-actions .ant-space-item {
|
|
162
|
+
display: flex;
|
|
163
|
+
width: 100%;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
.webdav-sync-form-actions .ant-btn {
|
|
167
|
+
flex: 1;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
.webdav-sync-note {
|
|
171
|
+
color: #475569;
|
|
172
|
+
background: linear-gradient(160deg, #ecfeff, #f8fafc 62%);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
.webdav-sync-note-icon {
|
|
176
|
+
display: block;
|
|
177
|
+
margin-bottom: 10px;
|
|
178
|
+
color: #0891b2;
|
|
179
|
+
font-size: 24px;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
.webdav-sync-file-tree,
|
|
183
|
+
.webdav-sync-file-name {
|
|
184
|
+
padding: 8px 10px;
|
|
185
|
+
border-radius: 7px;
|
|
186
|
+
color: #d8f3f5;
|
|
187
|
+
background: #102a43;
|
|
188
|
+
font-family: SFMono-Regular, Consolas, "Liberation Mono", monospace;
|
|
189
|
+
font-size: 12px;
|
|
190
|
+
line-height: 1.6;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
.webdav-sync-break-all {
|
|
194
|
+
white-space: normal;
|
|
195
|
+
overflow-wrap: anywhere;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
.webdav-sync-actions {
|
|
199
|
+
display: grid;
|
|
200
|
+
grid-template-columns: 1fr 1fr;
|
|
201
|
+
gap: 10px;
|
|
202
|
+
margin-top: 22px;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
.webdav-sync-actions .ant-btn {
|
|
206
|
+
white-space: nowrap;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
.webdav-sync-pull-button {
|
|
210
|
+
border-color: #059669 !important;
|
|
211
|
+
background: #059669 !important;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
.webdav-sync-disconnect {
|
|
215
|
+
padding-inline: 0;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
.webdav-sync-module-grid {
|
|
219
|
+
display: grid;
|
|
220
|
+
grid-template-columns: repeat(2, minmax(0, 1fr));
|
|
221
|
+
gap: 12px;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
.webdav-sync-module-card .ant-card-body {
|
|
225
|
+
display: flex;
|
|
226
|
+
height: min(440px, calc(100vh - 300px));
|
|
227
|
+
min-height: 280px;
|
|
228
|
+
flex-direction: column;
|
|
229
|
+
padding: 14px;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
.webdav-sync-module-header,
|
|
233
|
+
.webdav-sync-select-all {
|
|
234
|
+
display: flex;
|
|
235
|
+
align-items: center;
|
|
236
|
+
justify-content: space-between;
|
|
237
|
+
gap: 8px;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
.webdav-sync-module-header {
|
|
241
|
+
align-items: flex-start;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
.webdav-sync-module-header .ant-typography {
|
|
245
|
+
margin: 0;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
.webdav-sync-module-eyebrow {
|
|
249
|
+
font-size: 10px;
|
|
250
|
+
font-weight: 700;
|
|
251
|
+
letter-spacing: 0.14em;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
.webdav-sync-select-all {
|
|
255
|
+
margin-top: 8px;
|
|
256
|
+
padding: 7px 10px;
|
|
257
|
+
border-radius: 7px;
|
|
258
|
+
background: #f8fafc;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
.webdav-sync-module-list {
|
|
262
|
+
min-height: 0;
|
|
263
|
+
flex: 1;
|
|
264
|
+
margin: 8px 0 10px;
|
|
265
|
+
overflow: auto;
|
|
266
|
+
overscroll-behavior: contain;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
.webdav-sync-module-list .ant-checkbox-group {
|
|
270
|
+
display: grid;
|
|
271
|
+
gap: 5px;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
.webdav-sync-module-option.ant-checkbox-wrapper {
|
|
275
|
+
display: grid;
|
|
276
|
+
grid-template-columns: auto minmax(0, 1fr) auto;
|
|
277
|
+
align-items: center;
|
|
278
|
+
gap: 8px;
|
|
279
|
+
margin-inline-start: 0;
|
|
280
|
+
padding: 7px 9px;
|
|
281
|
+
border: 1px solid #e6edf2;
|
|
282
|
+
border-radius: 7px;
|
|
283
|
+
background: #fff;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
.webdav-sync-module-option .ant-checkbox + span {
|
|
287
|
+
display: contents;
|
|
288
|
+
padding-inline-start: 0;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
.webdav-sync-module-name {
|
|
292
|
+
min-width: 0;
|
|
293
|
+
font-weight: 500;
|
|
294
|
+
overflow-wrap: anywhere;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
.webdav-sync-module-count {
|
|
298
|
+
color: #94a3b8;
|
|
299
|
+
font-size: 12px;
|
|
300
|
+
white-space: nowrap;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
.webdav-sync-manual-note {
|
|
304
|
+
padding: 8px 12px;
|
|
305
|
+
border-radius: 8px;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
.webdav-sync-manual-note .ant-alert-message {
|
|
309
|
+
margin-bottom: 1px;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
.webdav-sync-manual-note .ant-alert-description {
|
|
313
|
+
font-size: 12px;
|
|
314
|
+
line-height: 1.5;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
.webdav-sync-status-title {
|
|
318
|
+
display: flex;
|
|
319
|
+
align-items: flex-start;
|
|
320
|
+
justify-content: space-between;
|
|
321
|
+
gap: 12px;
|
|
322
|
+
margin-bottom: 16px;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
.webdav-sync-status-title .ant-typography {
|
|
326
|
+
margin: 0;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
.webdav-sync-status-title > div > .ant-typography:first-child {
|
|
330
|
+
font-size: 10px;
|
|
331
|
+
font-weight: 700;
|
|
332
|
+
letter-spacing: 0.14em;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
.webdav-sync-file-name {
|
|
336
|
+
margin-bottom: 16px;
|
|
337
|
+
line-height: 1.5;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
body.cyber-theme .webdav-sync-grid {
|
|
341
|
+
background: #071116;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
body.cyber-theme .webdav-sync-connected {
|
|
345
|
+
background: #071116;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
body.cyber-theme .webdav-sync-card,
|
|
349
|
+
body.cyber-theme .webdav-sync-note,
|
|
350
|
+
body.cyber-theme .webdav-sync-status-card,
|
|
351
|
+
body.cyber-theme .webdav-sync-connection-card,
|
|
352
|
+
body.cyber-theme .webdav-sync-module-card {
|
|
353
|
+
border: 1px solid rgba(0, 240, 255, 0.2);
|
|
354
|
+
background: #0b1c24;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
body.cyber-theme .webdav-sync-select-all,
|
|
358
|
+
body.cyber-theme .webdav-sync-module-option.ant-checkbox-wrapper {
|
|
359
|
+
border-color: rgba(0, 240, 255, 0.18);
|
|
360
|
+
background: #102730;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
body.earth-theme .webdav-sync-grid {
|
|
364
|
+
background: #f0ebe3;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
body.earth-theme .webdav-sync-connected {
|
|
368
|
+
background: #f0ebe3;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
body.earth-theme .webdav-sync-hero {
|
|
372
|
+
background:
|
|
373
|
+
radial-gradient(circle at 85% 0%, rgba(212, 160, 23, 0.3), transparent 38%),
|
|
374
|
+
linear-gradient(135deg, #3d3630 0%, #8b5e3c 100%);
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
@media (max-width: 720px) {
|
|
378
|
+
.webdav-sync-hero {
|
|
379
|
+
grid-template-columns: auto 1fr;
|
|
380
|
+
padding: 12px 14px;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
.webdav-sync-hero > .ant-tag {
|
|
384
|
+
grid-column: 2;
|
|
385
|
+
justify-self: start;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
.webdav-sync-hero-copy .ant-typography:last-child {
|
|
389
|
+
white-space: normal;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
.webdav-sync-grid,
|
|
393
|
+
.webdav-sync-form-row,
|
|
394
|
+
.webdav-sync-actions,
|
|
395
|
+
.webdav-sync-module-grid,
|
|
396
|
+
.webdav-sync-connection-card .ant-card-body {
|
|
397
|
+
grid-template-columns: 1fr;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
.webdav-sync-module-card .ant-card-body {
|
|
401
|
+
height: auto;
|
|
402
|
+
min-height: 300px;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
.webdav-sync-module-list {
|
|
406
|
+
max-height: 240px;
|
|
407
|
+
}
|
|
408
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
const normalizeMessage = (value) => {
|
|
2
|
+
if (typeof value != 'string') return '';
|
|
3
|
+
return value
|
|
4
|
+
.replace(/<style[\s\S]*?<\/style>/gi, ' ')
|
|
5
|
+
.replace(/<script[\s\S]*?<\/script>/gi, ' ')
|
|
6
|
+
.replace(/<[^>]+>/g, ' ')
|
|
7
|
+
.replace(/\s+/g, ' ')
|
|
8
|
+
.trim()
|
|
9
|
+
.slice(0, 300);
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const parseResponseData = (data) => {
|
|
13
|
+
if (!data) return {};
|
|
14
|
+
if (typeof data == 'object') {
|
|
15
|
+
return {
|
|
16
|
+
message: normalizeMessage(data.message || data.error || data.detail),
|
|
17
|
+
conflict: data.conflict || null,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
if (typeof data != 'string') return {};
|
|
21
|
+
|
|
22
|
+
const text = data.trim();
|
|
23
|
+
if (!text) return {};
|
|
24
|
+
try {
|
|
25
|
+
return parseResponseData(JSON.parse(text));
|
|
26
|
+
} catch (error) {
|
|
27
|
+
return { message: normalizeMessage(text), conflict: null };
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const getApiError = (error, fallback) => {
|
|
32
|
+
const safeFallback = normalizeMessage(fallback) || 'WebDAV 操作失败';
|
|
33
|
+
const response = error && error.response;
|
|
34
|
+
const responseError = parseResponseData(response && response.data);
|
|
35
|
+
if (responseError.message) return responseError;
|
|
36
|
+
|
|
37
|
+
const status = response && response.status;
|
|
38
|
+
if (status) {
|
|
39
|
+
const statusText = normalizeMessage(response.statusText);
|
|
40
|
+
return {
|
|
41
|
+
message: `${safeFallback}(HTTP ${status}${statusText ? ` ${statusText}` : ''})`,
|
|
42
|
+
conflict: responseError.conflict || null,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (error && error.code == 'ECONNABORTED') {
|
|
47
|
+
return { message: `${safeFallback}:请求超时,请检查 WebDAV 地址和网络`, conflict: null };
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const message = normalizeMessage(error && error.message);
|
|
51
|
+
if (message && message != 'Network Error') {
|
|
52
|
+
return { message, conflict: null };
|
|
53
|
+
}
|
|
54
|
+
return { message: `${safeFallback}:网络请求失败,请检查 Whistle 服务日志`, conflict: null };
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
module.exports = { getApiError, normalizeMessage, parseResponseData };
|