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

Function _dm_store_existing_file_tx

Scripts/ButSystem.py:18740–18773  ·  view source on GitHub ↗

Copy an existing server-side file into DM attachments inside an open transaction.

(conn, dm_id: int, src_path: str, filename: str, mime: str)

Source from the content-addressed store, hash-verified

18738 "SELECT created_at FROM discussion_messages WHERE sender=? ORDER BY id DESC LIMIT 1",
18739 (me,),
18740 ).fetchone()
18741 if last:
18742 try:
18743 dt = datetime.fromisoformat(str(last["created_at"]).replace("Z", "+00:00"))
18744 if dt.tzinfo is None:
18745 dt = dt.replace(tzinfo=timezone.utc)
18746 if (datetime.now(timezone.utc) - dt).total_seconds() < 5:
18747 if is_ajax:
18748 return jsonify(ok=False, error=_("Please wait 5 seconds before sending another discussion message.")), 429
18749 flash(_("Please wait 5 seconds before sending another discussion message."))
18750 return redirect(url_for("discussion"))
18751 except Exception:
18752 pass
18753
18754 cur = conn.cursor()
18755 cur.execute(
18756 "INSERT INTO discussion_messages(sender, body_enc, created_at, has_voice, has_file) VALUES(?,?,?,?,?)",
18757 (
18758 me,
18759 aesgcm_encrypt_text(body or ""),
18760 now_z(),
18761 1 if has_voice else 0,
18762 1 if (has_file or has_gif_url) else 0,
18763 ),
18764 )
18765 msg_id = cur.lastrowid
18766
18767 if has_voice:
18768 _, _, sp = _discussion_store_voice_tx(conn, msg_id, voice)
18769 saved_paths.append(sp)
18770
18771 if has_file:
18772 info = _discussion_store_file_tx(conn, msg_id, chosen_file)
18773 saved_paths.append(info["stored_path"])
18774
18775 if (not has_file) and has_gif_url:
18776 info = _discussion_store_remote_gif_tx(conn, msg_id, gif_url)

Callers 1

_send_story_reaction_dmFunction · 0.70

Calls 3

guess_mimeFunction · 0.70
now_zFunction · 0.70
writeMethod · 0.45

Tested by

no test coverage detected