Remove VM upload layer; keep file picker only
This commit is contained in:
+1
-9
@@ -1,18 +1,15 @@
|
||||
import json
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
from flask import Flask, render_template, send_from_directory
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
if str(ROOT) not in sys.path:
|
||||
sys.path.insert(0, str(ROOT))
|
||||
with (ROOT / "config.json").open(encoding="utf-8") as config_file:
|
||||
CONFIG = json.load(config_file)
|
||||
|
||||
|
||||
VERSION = "0.1.2"
|
||||
VERSION = "0.1.3"
|
||||
|
||||
app = Flask(__name__, template_folder="templates", static_folder="static")
|
||||
|
||||
@@ -32,10 +29,5 @@ def upload_frontend(filename):
|
||||
return send_from_directory(ROOT / "upload" / "frontend", filename)
|
||||
|
||||
|
||||
from routes.api_bp import register_api
|
||||
|
||||
register_api(app, CONFIG)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(debug=False, host="0.0.0.0", port=5000)
|
||||
@@ -1 +0,0 @@
|
||||
"""Маршруты демо-обёртки."""
|
||||
@@ -1,26 +0,0 @@
|
||||
"""Демо API: переиспользуемый upload_refs и заглушка обработки."""
|
||||
|
||||
from flask import Blueprint, jsonify, request
|
||||
|
||||
from upload.backend.session import get_files
|
||||
from upload.backend.upload_refs import create_upload_refs_blueprint
|
||||
|
||||
|
||||
def register_api(app, cfg):
|
||||
app.register_blueprint(create_upload_refs_blueprint(cfg))
|
||||
demo = Blueprint("demo_api", __name__, url_prefix=cfg.get("apiPrefix", "/api"))
|
||||
|
||||
@demo.post("/process")
|
||||
def process():
|
||||
data = request.get_json(silent=True) or {}
|
||||
sid = data.get("session", "")
|
||||
files = get_files(sid)
|
||||
if files is None:
|
||||
return jsonify({"ok": False, "error": "Session not found"}), 404
|
||||
return jsonify({
|
||||
"ok": True,
|
||||
"session": sid,
|
||||
"files": [{"name": name, "size": len(content)} for name, content in files],
|
||||
})
|
||||
|
||||
app.register_blueprint(demo)
|
||||
@@ -18,7 +18,6 @@
|
||||
<input id="folder-input" type="file" webkitdirectory directory multiple hidden>
|
||||
<button id="files-btn" type="button">Выбрать файлы</button>
|
||||
<button id="folder-btn" type="button" class="secondary">Выбрать папку</button>
|
||||
<button id="upload-btn" type="button" disabled>Загрузить</button>
|
||||
<button id="clear-btn" type="button" class="quiet">Очистить</button>
|
||||
</section>
|
||||
<p id="status" class="status" role="status"></p>
|
||||
@@ -29,15 +28,10 @@
|
||||
</table>
|
||||
</div>
|
||||
<p id="count" class="count"></p>
|
||||
<section id="result" class="result" hidden>
|
||||
<h2>Файлы в сессии</h2>
|
||||
<ul id="result-list"></ul>
|
||||
</section>
|
||||
</main>
|
||||
<script src="{{ url_for('static', filename='vendor/fflate.min.js') }}"></script>
|
||||
<script type="module">
|
||||
import { initUploadTable } from "/upload-frontend/table/init_upload_table.js";
|
||||
import { uploadViaVM } from "/upload-frontend/upload/upload_via_vm.js";
|
||||
|
||||
const cfg = {{ config|tojson }};
|
||||
const table = initUploadTable({
|
||||
@@ -46,43 +40,11 @@
|
||||
folderInputEl: document.querySelector('#folder-input'),
|
||||
tableBodyEl: document.querySelector('#table-body'),
|
||||
countEl: document.querySelector('#count'),
|
||||
uploadBtnEl: document.querySelector('#upload-btn'),
|
||||
});
|
||||
const status = document.querySelector('#status');
|
||||
document.querySelector('#files-btn').onclick = () => table.pickFiles();
|
||||
document.querySelector('#folder-btn').onclick = () => table.pickFolder();
|
||||
document.querySelector('#clear-btn').onclick = () => table.clear();
|
||||
document.querySelector('#upload-btn').onclick = async () => {
|
||||
const files = table.getFiles().map((item) => item.file);
|
||||
table.setBusy(true);
|
||||
status.textContent = 'Загрузка...';
|
||||
const result = await uploadViaVM(files, cfg.vmUploadUrl, {
|
||||
onUploadStatus: (text) => { status.textContent = text; },
|
||||
onStatus: (name, text) => {
|
||||
const item = table.getFiles().find((entry) => entry.name === name);
|
||||
if (item) table.setStatus(item.path, text);
|
||||
},
|
||||
});
|
||||
if (!result.ok) {
|
||||
status.textContent = result.error;
|
||||
table.setBusy(false);
|
||||
return;
|
||||
}
|
||||
const response = await fetch('/api/process', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ session: result.session }),
|
||||
});
|
||||
const processed = await response.json();
|
||||
status.textContent = `Готово: ${processed.files.length} файлов`;
|
||||
document.querySelector('#result').hidden = false;
|
||||
const resultList = document.querySelector('#result-list');
|
||||
resultList.replaceChildren(...processed.files.map((file) => {
|
||||
const item = document.createElement('li');
|
||||
item.textContent = `${file.name} — ${file.size} B`;
|
||||
return item;
|
||||
}));
|
||||
};
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user