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

Function _discussion_store_voice_tx

Scripts/ButSystem.py:12510–12527  ·  view source on GitHub ↗

Store a discussion voice message atomically within an existing DB transaction.

(conn, msg_id: int, file_storage)

Source from the content-addressed store, hash-verified

12508 if conflict == "cancel": return jsonify({"ok": False, "error": "exists"}), 409
12509 destination = original if conflict == "replace" else _unique_destination(dest_dir, filename)
12510 else: destination = original
12511 if not _disk_allows_upload(dest_dir, total_size): return jsonify({"ok": False, "error": "storage_full"}), 507
12512 upload_id = secrets.token_urlsafe(24)
12513 meta = {"u": current_user(), "p": rel, "filename": os.path.basename(destination), "destination": destination, "replace": conflict == "replace", "total_chunks": total, "total_size": total_size, "received": 0, "created_at": now_z()}
12514 os.makedirs(TMP_UPLOAD_DIR, exist_ok=True)
12515 temp_meta = _upload_meta_path(upload_id) + ".tmp"
12516 with open(temp_meta, "w", encoding="utf-8") as fh: json.dump(meta, fh)
12517 os.replace(temp_meta, _upload_meta_path(upload_id))
12518 return jsonify({"ok": True, "upload_id": upload_id, "filename": meta["filename"]})
12519
12520
12521@app.route("/api/upload/cancel", methods=["POST"])
12522@login_required
12523def api_upload_cancel():
12524 data = request.get_json(silent=True) or {}
12525 upload_id = (data.get("upload_id") or "").strip()
12526 if not re.fullmatch(r"[A-Za-z0-9_-]{20,128}", upload_id):
12527 return jsonify({"ok": False, "error": "bad_request"}), 400
12528 meta_path = _upload_meta_path(upload_id)
12529 with UPLOAD_LOCK:
12530 try:

Callers 1

discussion_sendFunction · 0.70

Calls 3

now_zFunction · 0.70
_save_plain_uploadFunction · 0.70

Tested by

no test coverage detected