Repository navigation
Expand file tree
/
Copy pathindex.html
More file actions
178 lines (161 loc) · 5.35 KB
/
Copy pathindex.html
File metadata and controls
178 lines (161 loc) · 5.35 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
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>NAS文件管理器</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 800px;
margin: 0 auto;
padding: 20px;
line-height: 1.6;
}
h1 {
text-align: center;
color: #333;
margin-bottom: 20px;
}
.file-list {
border: 1px solid #ddd;
border-radius: 5px;
padding: 15px;
margin-bottom: 20px;
max-height: 400px;
overflow-y: auto;
background: #f9f9f9;
}
.file-item {
display: flex;
justify-content: space-between;
align-items: center;
padding: 10px;
border-bottom: 1px solid #eee;
}
.file-item:last-child {
border-bottom: none;
}
.file-name {
flex-grow: 1;
}
.btn-download {
background: #4CAF50;
color: white;
padding: 5px 10px;
border-radius: 3px;
text-decoration: none;
font-size: 14px;
}
.upload-form {
background: #f5f5f5;
padding: 15px;
border-radius: 5px;
margin-bottom: 20px;
}
#fileInput {
margin-bottom: 10px;
width: 100%;
}
.btn-upload {
background: #2196F3;
color: white;
padding: 8px 15px;
width: 100%;
border: none;
border-radius: 3px;
cursor: pointer;
}
.status {
margin-top: 15px;
padding: 10px;
border-radius: 4px;
text-align: center;
}
.success {
background: #e8f5e9;
color: #2e7d32;
}
.error {
background: #ffebee;
color: #c62828;
}
</style>
</head>
<body>
<h1>NAS 文件管理器</h1>
<div class="file-list" id="file-container">
<p>正在加载文件列表...</p>
</div>
<form id="uploadForm" class="upload-form" enctype="multipart/form-data">
<input type="file" name="file" id="fileInput" required>
<button type="submit" class="btn-upload">上传文件</button>
</form>
<div id="statusMessage" class="status"></div>
<script>
// 加载文件列表
async function loadFileList() {
try {
const response = await fetch('/api/list');
if (!response.ok) throw new Error('获取文件列表失败');
const files = await response.json();
let html = '';
if (files.length === 0) {
html = '<p>当前目录为空</p>';
} else {
files.forEach(file => {
html += `
<div class="file-item">
<div class="file-name">${file.name}</div>
<a href="${file.path}" download class="btn-download">下载</a>
</div>
`;
});
}
document.getElementById('file-container').innerHTML = html;
} catch (error) {
document.getElementById('file-container').innerHTML = `
<div style="color:red;">
<p>加载失败: ${error.message}</p>
<button onclick="loadFileList()">重试</button>
</div>
`;
}
}
// 处理文件上传
document.getElementById('uploadForm').addEventListener('submit', async (e) => {
e.preventDefault();
const fileInput = document.getElementById('fileInput');
if (!fileInput.files.length) {
showStatus('请选择文件', 'error');
return;
}
try {
showStatus('上传中...');
const formData = new FormData();
formData.append('file', fileInput.files[0]);
const response = await fetch('/upload', {
method: 'POST',
body: formData
});
const result = await response.json();
if (result.error) throw new Error(result.error);
showStatus(`上传成功: ${result.filename}`, 'success');
fileInput.value = '';
loadFileList();
} catch (error) {
showStatus(`上传失败: ${error.message}`, 'error');
}
});
// 显示状态信息
function showStatus(message, type) {
const el = document.getElementById('statusMessage');
el.textContent = message;
el.className = `status ${type || ''}`;
setTimeout(() => el.textContent = '', 5000);
}
// 页面加载时初始化
window.addEventListener('load', loadFileList);
</script>
</body>
</html>