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

Function api_group_since

Scripts/ButSystem.py:13859–13929  ·  view source on GitHub ↗

Return new group messages since a given id (AJAX polling). This endpoint lets group chats update in-place (no full page refresh) when messages are sent/received. Query params: id: Last seen group message id (integer). html: If '1', include pre-rendered HTML rows for eas

(gid: int)

Source from the content-addressed store, hash-verified

13857 row = conn.execute("""
13858 SELECT f.id, f.filename, f.mime, f.stored_path, m.sender, m.recipient
13859 FROM dm_files f
13860 JOIN dm_messages m ON m.id=f.dm_id
13861 WHERE f.id=?
13862 """, (fid,)).fetchone()
13863 conn.close()
13864 if not row or (me != row["sender"] and me != row["recipient"]):
13865 abort(404)
13866 peer = row["recipient"] if row["sender"] == me else row["sender"]
13867 if not _chat_lock_is_unlocked(me, "dm", peer):
13868 return redirect(url_for("chat_with", username=peer))
13869
13870 sp = row["stored_path"]
13871 if not sp or not os.path.exists(sp):
13872 abort(404)
13873
13874 filename = row["filename"] or f"file_{fid}"
13875 mime = row["mime"] or "application/octet-stream"
13876
13877 try:
13878 if is_encrypted_file(sp):
13879 gen = aesgcm_decrypt_generator(sp)
13880 headers = {"Content-Disposition": f'attachment; filename="{filename}"'}
13881 return Response(gen, mimetype=mime, headers=headers)
13882 except Exception:
13883 abort(404)
13884
13885 from flask import send_file
13886 return send_file(sp, mimetype=mime, as_attachment=True, download_name=filename)
13887
13888@app.route("/discussion/file/<int:fid>")
13889@login_required
13890def discussion_file_stream(fid: int):
13891 """Inline media stream for Discussion attachments."""
13892 _feature_tables_init()
13893 me = current_user()
13894 conn = db_connect()
13895 row = conn.execute("""
13896 SELECT f.id, f.filename, f.mime, f.stored_path
13897 FROM discussion_files f
13898 WHERE f.id=?
13899 """, (fid,)).fetchone()
13900 conn.close()
13901 if not row:
13902 abort(404)
13903 sp = row["stored_path"]
13904 if not sp or not os.path.exists(sp):
13905 abort(404)
13906
13907 filename = row["filename"] or f"discussion-file-{fid}"
13908 mime = row["mime"] or guess_mime(filename)
13909 inline_ok = is_inline_safe(mime, filename)
13910
13911 try:
13912 from flask import send_file
13913 if is_encrypted_file(sp):
13914 gen = aesgcm_decrypt_generator(sp)
13915 resp = Response(gen, mimetype=(mime if inline_ok else "application/octet-stream"))
13916 else:

Callers

nothing calls this directly

Calls 5

current_userFunction · 0.70
group_roleFunction · 0.70
db_connectFunction · 0.70
aesgcm_decrypt_textFunction · 0.70
_local_time_strFunction · 0.70

Tested by

no test coverage detected