v0.0.2: split api_bp into upload/process/download modules, Connection: close, upload tests (13 new, 106 total)
Deploy drhider / validate (push) Waiting to run
Deploy drhider / validate (push) Waiting to run
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
"""
|
||||
POST /api/upload — загрузить ОДИН файл.
|
||||
|
||||
Каждый вызов — новое соединение, передал → закрыл.
|
||||
Сессия связывает файлы через session_id.
|
||||
"""
|
||||
|
||||
from flask import Blueprint, request, jsonify
|
||||
from session import create_session, add_file, file_count
|
||||
|
||||
upload_bp = Blueprint("upload", __name__, url_prefix="/api")
|
||||
|
||||
|
||||
@upload_bp.route("/upload", methods=["POST"])
|
||||
def upload():
|
||||
sid = request.form.get("session", "")
|
||||
if not sid:
|
||||
sid = create_session()
|
||||
uploaded = request.files.getlist("files")
|
||||
if not uploaded:
|
||||
return jsonify({"ok": False, "error": "No file"}), 400
|
||||
f = uploaded[0]
|
||||
if not f.filename:
|
||||
return jsonify({"ok": False, "error": "No filename"}), 400
|
||||
ok = add_file(sid, f.filename, f.read())
|
||||
if not ok:
|
||||
return jsonify({"ok": False, "error": "Session not found"}), 404
|
||||
return jsonify({"ok": True, "session": sid, "count": file_count(sid)})
|
||||
Reference in New Issue
Block a user