-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
358 lines (347 loc) · 13 KB
/
index.html
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
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>企业文件管理器</title>
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
<style>
body {
font-family: 'Roboto', sans-serif;
line-height: 1.6;
color: #333;
max-width: 1000px;
margin: 0 auto;
padding: 20px;
background-color: #f4f4f4;
}
.container {
background-color: #fff;
padding: 30px;
border-radius: 8px;
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}
h1, h2 {
color: #2c3e50;
border-bottom: 2px solid #3498db;
padding-bottom: 10px;
margin-top: 0;
}
form {
margin-bottom: 20px;
}
input[type="file"], input[type="text"], input[type="password"] {
margin-right: 10px;
padding: 8px;
border: 1px solid #ddd;
border-radius: 4px;
font-size: 14px;
}
input[type="submit"], button {
background-color: #3498db;
color: #fff;
border: none;
padding: 10px 15px;
cursor: pointer;
border-radius: 4px;
font-size: 14px;
transition: background-color 0.3s;
}
input[type="submit"]:hover, button:hover {
background-color: #2980b9;
}
ul {
list-style-type: none;
padding: 0;
}
li {
background-color: #f8f9fa;
margin-bottom: 8px;
padding: 12px;
border-radius: 4px;
display: flex;
justify-content: space-between;
align-items: center;
transition: background-color 0.3s;
}
li:hover {
background-color: #e9ecef;
}
a {
color: #2980b9;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
#progress-bar {
width: 100%;
background-color: #f0f0f0;
padding: 3px;
border-radius: 3px;
box-shadow: inset 0 1px 3px rgba(0, 0, 0, .2);
margin-top: 10px;
}
#progress-bar-fill {
display: block;
height: 22px;
background-color: #3498db;
border-radius: 3px;
transition: width 500ms ease-in-out;
}
.breadcrumb {
margin-bottom: 20px;
background-color: #e9ecef;
padding: 10px;
border-radius: 4px;
}
.breadcrumb a {
margin-right: 5px;
}
.file-icon {
margin-right: 10px;
}
.custom-file-upload {
border: 1px solid #ccc;
display: inline-block;
padding: 6px 12px;
cursor: pointer;
background-color: #f8f9fa;
border-radius: 4px;
}
#file-input {
display: none;
}
</style>
</head>
<body>
<div class="container">
<h1>企业文件管理器</h1>
<div class="breadcrumb" id="breadcrumb"></div>
<form id="upload-form" enctype="multipart/form-data">
<label for="file-input" class="custom-file-upload">
<i class="fas fa-cloud-upload-alt"></i> 选择文件
</label>
<input type="file" name="file" id="file-input">
<input type="submit" value="上传文件">
</form>
<div id="progress-bar" style="display:none;">
<span id="progress-bar-fill" style="width: 0%"></span>
</div>
<form id="create-folder-form">
<input type="text" id="folder-name" placeholder="新文件夹名称">
<button type="button" onclick="createFolder()"><i class="fas fa-folder-plus"></i> 创建文件夹</button>
</form>
<h2>当前目录内容:</h2>
<ul id="file-list"></ul>
<h2>密码保护:</h2>
<form id="password-form">
<input type="password" id="password" placeholder="设置新密码">
<button type="button" onclick="setPassword()"><i class="fas fa-key"></i> 设置密码</button>
</form>
<button onclick="toggleProtection()"><i class="fas fa-shield-alt"></i> 切换密码保护</button>
</div>
<script>
let currentPath = '';
function updateBreadcrumb() {
const parts = currentPath.split('/').filter(p => p);
let html = '<a href="#" onclick="changePath(\'\')"><i class="fas fa-home"></i> 根目录</a>';
let path = '';
for (const part of parts) {
path += '/' + part;
html += ` > <a href="#" onclick="changePath('${path}')">${part}</a>`;
}
document.getElementById('breadcrumb').innerHTML = html;
}
function changePath(path) {
currentPath = path;
updateBreadcrumb();
listFiles();
}
function listFiles() {
fetch(`/list?dir=${encodeURIComponent(currentPath)}`)
.then(response => response.json())
.then(files => {
const fileList = document.getElementById('file-list');
fileList.innerHTML = '';
files.forEach(file => {
const li = document.createElement('li');
if (file.isDir) {
li.innerHTML = `
<div>
<i class="fas fa-folder file-icon"></i>
<a href="#" onclick="changePath('${currentPath}/${file.name}')">${file.name}</a>
</div>
<div>
<input type="text" id="new-name-${file.name}" placeholder="新名称">
<button onclick="renameFile('${file.name}')"><i class="fas fa-edit"></i></button>
<button onclick="deleteFile('${file.name}')"><i class="fas fa-trash-alt"></i></button>
</div>
`;
} else {
li.innerHTML = `
<div>
<i class="fas fa-file file-icon"></i>
<a href="/files${currentPath}/${file.name}" target="_blank">${file.name}</a>
</div>
<div>
<input type="text" id="new-name-${file.name}" placeholder="新名称">
<button onclick="renameFile('${file.name}')"><i class="fas fa-edit"></i></button>
<button onclick="deleteFile('${file.name}')"><i class="fas fa-trash-alt"></i></button>
</div>
`;
}
fileList.appendChild(li);
});
})
.catch(error => console.error('Error:', error));
}
document.getElementById('upload-form').addEventListener('submit', function(e) {
e.preventDefault();
var formData = new FormData(this);
formData.append('dir', currentPath);
var xhr = new XMLHttpRequest();
xhr.open('POST', '/upload', true);
xhr.upload.onprogress = function(e) {
if (e.lengthComputable) {
var percentComplete = (e.loaded / e.total) * 100;
document.getElementById('progress-bar').style.display = 'block';
document.getElementById('progress-bar-fill').style.width = percentComplete + '%';
}
};
xhr.onload = function() {
if (xhr.status === 200) {
listFiles();
document.getElementById('progress-bar').style.display = 'none';
} else {
alert('Upload failed. Please try again.');
}
};
xhr.send(formData);
});
function renameFile(oldName) {
var newName = document.getElementById('new-name-' + oldName).value;
if (!newName) {
alert('Please enter a new name');
return;
}
fetch('/rename', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({oldPath: `${currentPath}/${oldName}`, newPath: `${currentPath}/${newName}`}),
})
.then(response => response.json())
.then(data => {
if (data.success) {
listFiles();
} else {
alert('Rename failed: ' + data.error);
}
})
.catch((error) => {
console.error('Error:', error);
alert('An error occurred while renaming the file');
});
}
function setPassword() {
var password = document.getElementById('password').value;
fetch('/set-password', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({password: password}),
})
.then(response => response.json())
.then(data => {
if (data.success) {
alert('Password set successfully');
} else {
alert('Failed to set password: ' + data.error);
}
})
.catch((error) => {
console.error('Error:', error);
alert('An error occurred while setting the password');
});
}
function toggleProtection() {
fetch('/toggle-protection', {
method: 'POST',
})
.then(response => response.json())
.then(data => {
if (data.success) {
alert('Password protection ' + (data.isProtected ? 'enabled' : 'disabled'));
} else {
alert('Failed to toggle protection: ' + data.error);
}
})
.catch((error) => {
console.error('Error:', error);
alert('An error occurred while toggling protection');
});
}
function deleteFile(name) {
if (confirm('确定要删除这个文件/文件夹吗?')) {
fetch('/delete', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({path: `${currentPath}/${name}`}),
})
.then(response => response.json())
.then(data => {
if (data.success) {
listFiles();
} else {
alert('删除失败: ' + data.error);
}
})
.catch((error) => {
console.error('Error:', error);
alert('删除文件/文件夹时发生错误');
});
}
}
function createFolder() {
var folderName = document.getElementById('folder-name').value;
if (!folderName) {
alert('请输入文件夹名称');
return;
}
fetch('/create-folder', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({path: `${currentPath}/${folderName}`}),
})
.then(response => response.json())
.then(data => {
if (data.success) {
listFiles();
} else {
alert('创建文件夹失败: ' + data.error);
}
})
.catch((error) => {
console.error('Error:', error);
alert('创建文件夹时发生错误');
});
}
// 初始化
updateBreadcrumb();
listFiles();
// 显示选择的文件名
document.getElementById('file-input').addEventListener('change', function() {
var fileName = this.files[0].name;
document.querySelector('.custom-file-upload').innerHTML = '<i class="fas fa-file"></i> ' + fileName;
});
</script>
</body>
</html>