-
Notifications
You must be signed in to change notification settings - Fork 285
Expand file tree
/
Copy pathindex.html
More file actions
373 lines (327 loc) · 11.9 KB
/
index.html
File metadata and controls
373 lines (327 loc) · 11.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>系统备份与恢复</title>
<style>
:root {
--primary-color: #2196F3;
--success-color: #4CAF50;
--warning-color: #FF9800;
--danger-color: #f44336;
--text-color: #333;
--bg-color: #f4f7f6;
--card-bg: #ffffff;
--code-bg: #f5f5f5;
}
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
margin: 0;
padding: 20px;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
background-color: var(--bg-color);
color: var(--text-color);
box-sizing: border-box;
}
.container {
width: 100%;
max-width: 600px;
padding: 30px;
background: var(--card-bg);
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.05);
border-radius: 12px;
text-align: center;
transition: transform 0.3s ease;
}
h2 {
margin-top: 0;
margin-bottom: 25px;
color: #2c3e50;
font-weight: 600;
}
.description {
margin-bottom: 30px;
color: #555;
line-height: 1.6;
text-align: left;
background: #fff;
padding: 0;
}
.description p {
margin: 10px 0;
}
.info-box {
background: #e3f2fd;
border-left: 4px solid var(--primary-color);
padding: 15px;
border-radius: 4px;
margin-bottom: 20px;
font-size: 14px;
}
.file-list-container {
margin-top: 20px;
border: 1px solid #eee;
border-radius: 8px;
overflow: hidden;
}
.file-list-header {
background: #f8f9fa;
padding: 10px 15px;
font-weight: 600;
border-bottom: 1px solid #eee;
font-size: 14px;
display: flex;
justify-content: space-between;
align-items: center;
}
.status-text {
font-size: 12px;
color: #777;
text-align: right;
margin-top: 6px;
}
#fileList {
font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
background: #2d3436;
color: #dfe6e9;
padding: 15px;
max-height: 150px;
overflow-y: auto;
text-align: left;
font-size: 12px;
line-height: 1.5;
}
.button-group {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 20px;
margin-bottom: 25px;
}
button {
padding: 12px 20px;
font-size: 16px;
border: none;
border-radius: 8px;
cursor: pointer;
transition: all 0.2s ease;
color: white;
font-weight: 500;
display: flex;
align-items: center;
justify-content: center;
gap: 8px;
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}
button:active {
transform: translateY(1px);
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
button:disabled {
opacity: 0.7;
cursor: not-allowed;
}
.backup-btn {
background: linear-gradient(135deg, #4CAF50 0%, #45a049 100%);
}
.backup-btn:hover {
background: linear-gradient(135deg, #45a049 0%, #388E3C 100%);
transform: translateY(-2px);
box-shadow: 0 6px 12px rgba(76, 175, 80, 0.2);
}
.restore-btn {
background: linear-gradient(135deg, #FF9800 0%, #F57C00 100%);
}
.restore-btn:hover {
background: linear-gradient(135deg, #F57C00 0%, #E65100 100%);
transform: translateY(-2px);
box-shadow: 0 6px 12px rgba(255, 152, 0, 0.2);
}
.log-area {
width: 100%;
height: 200px;
overflow-y: auto;
padding: 15px;
border: 1px solid #eee;
border-radius: 8px;
background-color: #f8f9fa;
box-sizing: border-box;
text-align: left;
font-family: monospace;
font-size: 13px;
box-shadow: inset 0 2px 4px rgba(0,0,0,0.05);
}
.log-entry {
margin-bottom: 6px;
padding-bottom: 6px;
border-bottom: 1px dashed #eee;
display: flex;
align-items: flex-start;
}
.log-time {
color: #999;
margin-right: 10px;
min-width: 70px;
font-size: 12px;
}
.log-content {
flex: 1;
word-break: break-all;
}
.log-success .log-content { color: var(--success-color); }
.log-error .log-content { color: var(--danger-color); }
.log-info .log-content { color: var(--text-color); }
.log-warning .log-content { color: var(--warning-color); }
.path-display {
background: #e8f5e9;
padding: 8px;
border-radius: 4px;
color: #2e7d32;
font-weight: 500;
}
/* Mobile Responsiveness */
@media (max-width: 480px) {
.container {
padding: 20px;
}
.button-group {
grid-template-columns: 1fr;
gap: 15px;
}
h2 {
font-size: 20px;
}
.log-area {
height: 150px;
}
}
</style>
</head>
<body>
<div class="container">
<h2>📂 系统备份与恢复</h2>
<div class="description">
<div class="info-box">
<p><strong>备份说明:</strong> 点击“立即备份”将系统配置、插件及脚本备份到同级 <code>backup</code> 目录。</p>
<p style="margin-bottom: 0;"><strong>恢复说明:</strong> 点击“恢复备份”将从 <code>backup</code> 目录恢复文件覆盖当前系统。</p>
</div>
<div class="file-list-container">
<div class="file-list-header">
<span>涉及文件清单</span>
<small>只读</small>
</div>
<div id="fileList">
加载中...
</div>
<div class="status-text">
<div>上次备份:<span id="lastBackupAt">--</span></div>
<div>上次恢复:<span id="lastRestoreAt">--</span></div>
</div>
</div>
</div>
<div class="button-group">
<button class="backup-btn" onclick="performAction('backup')" id="btn-backup">
<span>⬇️ 立即备份</span>
</button>
<button class="restore-btn" onclick="performAction('restore')" id="btn-restore">
<span>⬆️ 恢复备份</span>
</button>
</div>
<div class="log-area" id="logArea">
<div class="log-entry log-info"><span class="log-time">系统</span><span class="log-content">准备就绪,等待操作...</span></div>
</div>
</div>
<script>
// 加载配置文件列表
window.onload = async function() {
try {
const response = await fetch('/admin/backup/config');
if (response.ok) {
const data = await response.json();
if (data.success && data.paths) {
const fileListDiv = document.getElementById('fileList');
fileListDiv.innerHTML = data.paths.join('<br>');
if (data.lastBackupAt) {
document.getElementById('lastBackupAt').textContent = new Date(data.lastBackupAt).toLocaleString();
}
if (data.lastRestoreAt) {
document.getElementById('lastRestoreAt').textContent = new Date(data.lastRestoreAt).toLocaleString();
}
}
}
} catch (e) {
console.error('Failed to load backup config', e);
document.getElementById('fileList').textContent = '加载配置失败';
}
};
function log(message, type = 'info') {
const logArea = document.getElementById('logArea');
const entry = document.createElement('div');
entry.className = `log-entry log-${type}`;
const timeSpan = document.createElement('span');
timeSpan.className = 'log-time';
timeSpan.textContent = new Date().toLocaleTimeString();
const contentSpan = document.createElement('span');
contentSpan.className = 'log-content';
contentSpan.textContent = message;
entry.appendChild(timeSpan);
entry.appendChild(contentSpan);
logArea.prepend(entry);
}
function displayPath(path) {
const logArea = document.getElementById('logArea');
const entry = document.createElement('div');
entry.className = `log-entry log-info path-display`;
entry.style.display = 'block'; // Override flex
entry.textContent = `📁 备份路径: ${path}`;
logArea.prepend(entry);
}
async function performAction(action) {
const actionName = action === 'backup' ? '备份' : '恢复';
const btnId = action === 'backup' ? 'btn-backup' : 'btn-restore';
const btn = document.getElementById(btnId);
if (!confirm(`⚠️ 确定要执行${actionName}操作吗?\n此操作不可撤销,请谨慎进行。`)) return;
// UI State Loading
const originalText = btn.innerHTML;
btn.disabled = true;
btn.innerHTML = '<span>⏳ 处理中...</span>';
log(`开始执行${actionName}...`, 'info');
try {
const response = await fetch(`/admin/${action}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({})
});
let result;
try {
result = await response.json();
} catch (e) {
throw new Error(`响应解析失败: ${response.statusText}`);
}
if (response.ok && result.success) {
log(`${actionName}成功: ${result.message}`, 'success');
if (result.backupDir) {
displayPath(result.backupDir);
}
if (result.details && result.details.length > 0) {
result.details.forEach(detail => log(`- ${detail}`, 'info'));
}
} else {
log(`${actionName}失败: ${result.message || response.statusText}`, 'error');
}
} catch (error) {
log(`${actionName}出错: ${error.message}`, 'error');
} finally {
// Restore UI State
btn.disabled = false;
btn.innerHTML = originalText;
}
}
</script>
</body>
</html>