Upload 2 files
Browse files
app.py
CHANGED
|
@@ -119,6 +119,7 @@ HTML_TEMPLATE = """
|
|
| 119 |
input[type="file"] { display: none; }
|
| 120 |
.btn { padding: 10px 20px; background: #007bff; color: white; border: none; border-radius: 4px; cursor: pointer; font-size: 14px; }
|
| 121 |
.btn:hover { background: #0056b3; }
|
|
|
|
| 122 |
.btn-danger { background: #dc3545; }
|
| 123 |
.btn-danger:hover { background: #c82333; }
|
| 124 |
.btn-success { background: #28a745; }
|
|
@@ -285,26 +286,54 @@ HTML_TEMPLATE = """
|
|
| 285 |
formData.append('images', file);
|
| 286 |
}
|
| 287 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 288 |
try {
|
| 289 |
const response = await fetch('/api/upload', {
|
| 290 |
method: 'POST',
|
| 291 |
body: formData
|
| 292 |
});
|
| 293 |
const result = await response.json();
|
| 294 |
-
|
| 295 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 296 |
|
| 297 |
if (result.success) {
|
| 298 |
-
let html = `成功上传 ${result.data.length} 张图片
|
| 299 |
result.data.forEach(img => {
|
| 300 |
html += `Hash: ${img.hash}\\nURL: ${img.url}\\n\\n`;
|
| 301 |
});
|
| 302 |
resultDiv.textContent = html;
|
|
|
|
|
|
|
|
|
|
| 303 |
} else {
|
| 304 |
-
resultDiv.
|
|
|
|
|
|
|
| 305 |
}
|
| 306 |
} catch (error) {
|
| 307 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 308 |
}
|
| 309 |
}
|
| 310 |
|
|
|
|
| 119 |
input[type="file"] { display: none; }
|
| 120 |
.btn { padding: 10px 20px; background: #007bff; color: white; border: none; border-radius: 4px; cursor: pointer; font-size: 14px; }
|
| 121 |
.btn:hover { background: #0056b3; }
|
| 122 |
+
.btn:disabled { background: #6c757d; cursor: not-allowed; opacity: 0.6; }
|
| 123 |
.btn-danger { background: #dc3545; }
|
| 124 |
.btn-danger:hover { background: #c82333; }
|
| 125 |
.btn-success { background: #28a745; }
|
|
|
|
| 286 |
formData.append('images', file);
|
| 287 |
}
|
| 288 |
|
| 289 |
+
// 显示上传中提示
|
| 290 |
+
const resultDiv = document.getElementById('uploadResult');
|
| 291 |
+
resultDiv.style.display = 'block';
|
| 292 |
+
resultDiv.style.background = '#fff3cd';
|
| 293 |
+
resultDiv.style.color = '#856404';
|
| 294 |
+
resultDiv.innerHTML = '<strong>⏳ 正在上传,请勿关闭页面...</strong><br>正在上传 ' + files.length + ' 张图片';
|
| 295 |
+
|
| 296 |
+
// 禁用上传按钮
|
| 297 |
+
const uploadBtn = event.target;
|
| 298 |
+
uploadBtn.disabled = true;
|
| 299 |
+
uploadBtn.textContent = '上传中...';
|
| 300 |
+
|
| 301 |
try {
|
| 302 |
const response = await fetch('/api/upload', {
|
| 303 |
method: 'POST',
|
| 304 |
body: formData
|
| 305 |
});
|
| 306 |
const result = await response.json();
|
| 307 |
+
|
| 308 |
+
// 恢复按钮状态
|
| 309 |
+
uploadBtn.disabled = false;
|
| 310 |
+
uploadBtn.textContent = '上传';
|
| 311 |
+
|
| 312 |
+
resultDiv.style.background = '#e7f3ff';
|
| 313 |
+
resultDiv.style.color = 'inherit';
|
| 314 |
|
| 315 |
if (result.success) {
|
| 316 |
+
let html = `<strong>✅ 成功上传 ${result.data.length} 张图片</strong>\\n\\n`;
|
| 317 |
result.data.forEach(img => {
|
| 318 |
html += `Hash: ${img.hash}\\nURL: ${img.url}\\n\\n`;
|
| 319 |
});
|
| 320 |
resultDiv.textContent = html;
|
| 321 |
+
|
| 322 |
+
// 清空文件选择
|
| 323 |
+
clearSelection();
|
| 324 |
} else {
|
| 325 |
+
resultDiv.style.background = '#f8d7da';
|
| 326 |
+
resultDiv.style.color = '#721c24';
|
| 327 |
+
resultDiv.textContent = '❌ 错误: ' + result.error;
|
| 328 |
}
|
| 329 |
} catch (error) {
|
| 330 |
+
// 恢复按钮状态
|
| 331 |
+
uploadBtn.disabled = false;
|
| 332 |
+
uploadBtn.textContent = '上传';
|
| 333 |
+
|
| 334 |
+
resultDiv.style.background = '#f8d7da';
|
| 335 |
+
resultDiv.style.color = '#721c24';
|
| 336 |
+
resultDiv.textContent = '❌ 上传失败: ' + error;
|
| 337 |
}
|
| 338 |
}
|
| 339 |
|