From 4064bd5c117ddac702274a8cd06aa4fb0b0ad386 Mon Sep 17 00:00:00 2001 From: Cynthia Foxwell Date: Wed, 9 Apr 2025 20:30:50 -0600 Subject: [PATCH] less breaking and better way to transmit query params in ids since discord will never have a fully compliant activitystream parser --- src/routes/activityspoof.nim | 24 ++++++++++++++++-------- src/views/general.nim | 12 ++++++++++-- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/routes/activityspoof.nim b/src/routes/activityspoof.nim index 6675131..30ef53e 100644 --- a/src/routes/activityspoof.nim +++ b/src/routes/activityspoof.nim @@ -38,10 +38,14 @@ proc createActivityPubRouter*(cfg: Config) = query = "" # stupid hack to trick discord lmao - if id.find("_") != -1: - let parts = id.split("_") - id = parts[0] - query = parts[1] + if id.startsWith("422209040515"): + query = "video" + id.removePrefix("422209040515") + elif id.startsWith("421608152015"): + query = "photo:" + id.removePrefix("421608152015") + query &= id[0] + id = id[1..^1] if id.len > 19 or id.any(c => not c.isDigit): resp Http404, {"Content-Type": "application/json"}, """{"error":"Invalid record ID"}""" @@ -215,10 +219,14 @@ proc createActivityPubRouter*(cfg: Config) = query = "" # stupid hack to trick discord lmao - if id.find("_") != -1: - let parts = id.split("_") - id = parts[0] - query = parts[1] + if id.startsWith("422209040515"): + query = "video" + id.removePrefix("422209040515") + elif id.startsWith("421608152015"): + query = "photo:" + id.removePrefix("421608152015") + query &= id[0] + id = id[1..^1] var mediaType = "" diff --git a/src/views/general.nim b/src/views/general.nim index 95768b7..6e96a0c 100644 --- a/src/views/general.nim +++ b/src/views/general.nim @@ -167,9 +167,17 @@ proc renderHead*(prefs: Prefs; cfg: Config; req: Request; titleText=""; desc=""; author = encodeUrl(context) link(rel="alternate", href=(&"{getUrlPrefix(cfg)}/oembed.json?type=video&provider={encodeUrl(siteName)}&title={title}&user={author}&url={encodeUrl(contextUrl)}"), type="application/json+oembed") - var fediUrl = &"{getUrlPrefix(cfg)}/users/i/statuses/{id}" + var fediUrl = &"{getUrlPrefix(cfg)}/users/i/statuses/" if media.len > 0: - fediUrl &= "_" & media + if media == "video": + fediUrl &= "422209040515" # 42 + "video" + else: + let parts = media.split(":") + fediUrl &= "421608152015" # 42 + "photo" + if parts.len == 2: + fediUrl &= parts[1] # + index + + fediUrl &= id link(rel="alternate", href=fediUrl, type="application/activity+json") # this is last so images are also preloaded