mirror of
https://github.com/ClovertaTheTrilobita/cellpose-web.git
synced 2026-04-01 23:14:50 +00:00
feature(frontend): 前端新增跳转至预览
TODO: 获取的文件发送给cellpose,将cellpose的运行状态、预览发送给前端
This commit is contained in:
parent
03c484aa07
commit
92a89f856a
2 changed files with 7 additions and 3 deletions
|
|
@ -1,5 +1,5 @@
|
|||
from flask import Flask, send_from_directory, request, jsonify
|
||||
import os, shutil, time, threading
|
||||
import os, shutil, time, threading, datetime
|
||||
from werkzeug.utils import secure_filename
|
||||
from flask_cors import CORS
|
||||
from pathlib import Path
|
||||
|
|
@ -33,12 +33,14 @@ def download(timestamp):
|
|||
|
||||
@app.post("/upload")
|
||||
def upload():
|
||||
ts = datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
|
||||
os.makedirs(UPLOAD_DIR / ts, exist_ok=True)
|
||||
files = request.files.getlist("files")
|
||||
saved = []
|
||||
for f in files:
|
||||
if not f or f.filename == "":
|
||||
continue
|
||||
name = secure_filename(f.filename)
|
||||
f.save(os.path.join(UPLOAD_DIR, name))
|
||||
f.save(os.path.join(UPLOAD_DIR / ts, name))
|
||||
saved.append(name)
|
||||
return jsonify({"ok": True, "count": len(saved), "files": saved})
|
||||
return jsonify({"ok": True, "count": len(saved), "files": saved, "id": ts})
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
<meta charset="UTF-8" />
|
||||
<input id="fileInput" type="file" multiple />
|
||||
<button id="uploadBtn">Upload</button>
|
||||
<progress id="bar" max="100" value="0" style="width:300px;"></progress>
|
||||
|
|
@ -22,6 +23,7 @@ document.getElementById("uploadBtn").addEventListener("click", async () => {
|
|||
// 不要显式设置 Content-Type
|
||||
});
|
||||
alert("上传成功:" + JSON.stringify(res.data));
|
||||
window.location.href = `preview.html?id=${encodeURIComponent(res.data['id'])}`;
|
||||
} catch (e) {
|
||||
alert("上传失败:" + (e.response?.data?.message || e.message));
|
||||
} finally {
|
||||
|
|
|
|||
Loading…
Reference in a new issue