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

Function api_users

Scripts/ButSystem.py:13659–13711  ·  view source on GitHub ↗

api_users. Route handler or application helper. This docstring was expanded to make future maintenance easier. Returns: Varies.

()

Source from the content-addressed store, hash-verified

13657 if not (mime == "image/gif" or mime.startswith("video/")):
13658 path = (u.path or "").lower()
13659 if not (path.endswith(".gif") or path.endswith(".mp4") or path.endswith(".webm")):
13660 raise ValueError(f"Unsupported GIF mime: {mime}")
13661 if path.endswith(".mp4"):
13662 mime = "video/mp4"
13663 elif path.endswith(".webm"):
13664 mime = "video/webm"
13665 else:
13666 mime = "image/gif"
13667
13668 if mime == "image/gif":
13669 filename = f"gif_{fid}.gif"
13670 elif mime == "video/mp4":
13671 filename = f"gif_{fid}.mp4"
13672 elif mime == "video/webm":
13673 filename = f"gif_{fid}.webm"
13674 else:
13675 filename = f"file_{fid}"
13676
13677 with open(stored_path, "wb") as f:
13678 while True:
13679 chunk = resp.read(64 * 1024)
13680 if not chunk:
13681 break
13682 size += len(chunk)
13683 if size > max_bytes:
13684 raise ValueError("GIF too large")
13685 f.write(chunk)
13686
13687 conn.execute("UPDATE dm_files SET stored_path=?, size=?, mime=?, filename=? WHERE id=?",
13688 (stored_path, int(size), mime, filename, fid))
13689 conn.execute("UPDATE dm_messages SET has_file=1 WHERE id=?", (dm_id,))
13690 return {"id": fid, "mime": mime, "filename": filename, "size": int(size), "stored_path": stored_path}
13691
13692def _dm_store_remote_gif(dm_id: int, gif_url: str) -> Dict[str, str]:
13693 """Download and store a remote GIF (or short MP4) as a DM attachment.
13694
13695 This enables an Instagram-like GIF picker that sends a URL rather than an uploaded file.
13696 We keep this intentionally strict for safety:
13697 - only http(s)
13698 - size cap
13699 """
13700 gif_url = (gif_url or "").strip()
13701 if not gif_url:
13702 raise ValueError("Empty gif url")
13703
13704 try:
13705 u = urllib.parse.urlparse(gif_url)
13706 except Exception as e:
13707 raise ValueError("Bad gif url") from e
13708 if u.scheme not in ("http", "https"):
13709 raise ValueError("GIF url must be http(s)")
13710
13711 # Insert DB row first so we have a deterministic stored_path.
13712 conn = db_connect()
13713 cur = conn.cursor()
13714 cur.execute(

Callers

nothing calls this directly

Calls 3

current_userFunction · 0.70
user_cardsFunction · 0.70
_story_active_usernamesFunction · 0.70

Tested by

no test coverage detected