fix same origin urls in mastoapi

This commit is contained in:
Cynthia Foxwell 2025-04-18 21:37:39 -06:00
parent a943767f42
commit 3445b183cd
No known key found for this signature in database

View File

@ -3,7 +3,7 @@ import strutils, strformat, options, json, sequtils, times, math
import ".."/[types, formatters, utils] import ".."/[types, formatters, utils]
proc formatTweetForMastoAPI*(tweet: Tweet, cfg: Config, prefs: Prefs): string = proc formatTweetForMastoAPI*(tweet: Tweet, cfg: Config, prefs: Prefs): string =
var content = replaceUrls(tweet.text, prefs, absolute=getUrlPrefix(cfg)) var content = replaceUrls(tweet.text, prefs, absolute=getUrlPrefix(cfg)).replace("href=\"//", "href=\"http://")
if tweet.poll.isSome(): if tweet.poll.isSome():
let poll = get(tweet.poll) let poll = get(tweet.poll)
@ -24,7 +24,7 @@ proc formatTweetForMastoAPI*(tweet: Tweet, cfg: Config, prefs: Prefs): string =
if tweet.quote.isSome(): if tweet.quote.isSome():
let let
quote = get(tweet.quote) quote = get(tweet.quote)
quoteContent = replaceUrls(quote.text, prefs).replace("href=\"/", &"href=\"{getUrlPrefix(cfg)}/") quoteContent = replaceUrls(quote.text, prefs, absolute=getUrlPrefix(cfg)).replace("href=\"//", "href=\"http://")
quoteUrl = &"{getUrlPrefix(cfg)}/i/status/{quote.id}" quoteUrl = &"{getUrlPrefix(cfg)}/i/status/{quote.id}"
content &= &"\n\n<blockquote><b>↘ <a href=\"{quoteUrl}\">{quote.user.fullName} (@{quote.user.username})</a></b>\n{quoteContent}" content &= &"\n\n<blockquote><b>↘ <a href=\"{quoteUrl}\">{quote.user.fullName} (@{quote.user.username})</a></b>\n{quoteContent}"
@ -42,7 +42,7 @@ proc formatTweetForMastoAPI*(tweet: Tweet, cfg: Config, prefs: Prefs): string =
if tweet.birdwatch.isSome(): if tweet.birdwatch.isSome():
let let
note = get(tweet.birdwatch) note = get(tweet.birdwatch)
noteContent = replaceUrls(note.text, prefs) noteContent = replaceUrls(note.text, prefs, absolute=getUrlPrefix(cfg)).replace("href=\"//", "href=\"http://")
content &= &"\n\n<blockquote><b>ⓘ {note.title}</b>\n{noteContent}</blockquote>" content &= &"\n\n<blockquote><b>ⓘ {note.title}</b>\n{noteContent}</blockquote>"
result = content.replace("\n", "<br>") result = content.replace("\n", "<br>")