MCPcopy Create free account
hub / github.com/dedsec1121fk/DedSec / _discussion_store_file_tx

Function _discussion_store_file_tx

Scripts/ButSystem.py:12530–12552  ·  view source on GitHub ↗

Store a discussion file attachment atomically within an existing DB transaction.

(conn, msg_id: int, file_storage)

Source from the content-addressed store, hash-verified

12528 meta_path = _upload_meta_path(upload_id)
12529 with UPLOAD_LOCK:
12530 try:
12531 meta = json.loads(open(meta_path, "r", encoding="utf-8").read())
12532 except Exception:
12533 meta = None
12534 if meta and meta.get("u") != current_user():
12535 return jsonify({"ok": False, "error": "forbidden"}), 403
12536 for fp in (_upload_tmp_path(upload_id), meta_path, meta_path + ".tmp"):
12537 try:
12538 if os.path.exists(fp):
12539 os.remove(fp)
12540 except Exception:
12541 pass
12542 return jsonify({"ok": True})
12543
12544
12545@app.route("/api/upload/chunk", methods=["POST"])
12546@login_required
12547def api_upload_chunk():
12548 upload_id = (request.form.get("upload_id") or "").strip()
12549 try: idx = int(request.form.get("index") or 0); total = int(request.form.get("total") or 0)
12550 except Exception: return jsonify({"ok": False, "error": "bad_request"}), 400
12551 chunk = request.files.get("chunk")
12552 if not re.fullmatch(r"[A-Za-z0-9_-]{20,128}", upload_id or "") or chunk is None: return jsonify({"ok": False, "error": "bad_request"}), 400
12553 meta_path = _upload_meta_path(upload_id)
12554 with UPLOAD_LOCK:
12555 try: meta = json.loads(open(meta_path, "r", encoding="utf-8").read())

Callers 1

discussion_sendFunction · 0.70

Calls 3

now_zFunction · 0.70
_save_plain_uploadFunction · 0.70

Tested by

no test coverage detected