Merge branch 'original-image-urls'

This commit is contained in:
Zed 2022-06-04 00:47:56 +02:00
commit 90135d44e1
3 changed files with 23 additions and 3 deletions

View file

@ -88,6 +88,20 @@ proc createMediaRouter*(cfg: Config) =
get "/pic/?": get "/pic/?":
resp Http404 resp Http404
get re"^\/pic\/orig\/(enc)?\/?(.+)":
var url = decoded(request, 1)
if "twimg.com" notin url:
url.insert(twimg)
if not url.startsWith(https):
url.insert(https)
url.add("?name=orig")
let uri = parseUri(url)
cond isTwitterUrl(uri) == true
let code = await proxyMedia(request, url)
check code
get re"^\/pic\/(enc)?\/?(.+)": get re"^\/pic\/(enc)?\/?(.+)":
var url = decoded(request, 1) var url = decoded(request, 1)
if "twimg.com" notin url: if "twimg.com" notin url:

View file

@ -42,6 +42,12 @@ proc getPicUrl*(link: string): string =
else: else:
&"/pic/{encodeUrl(link)}" &"/pic/{encodeUrl(link)}"
proc getOrigPicUrl*(link: string): string =
if base64Media:
&"/pic/orig/enc/{encode(link, safe=true)}"
else:
&"/pic/orig/{encodeUrl(link)}"
proc filterParams*(params: Table): seq[(string, string)] = proc filterParams*(params: Table): seq[(string, string)] =
for p in params.pairs(): for p in params.pairs():
if p[1].len > 0 and p[0] notin nitterParams: if p[1].len > 0 and p[0] notin nitterParams:

View file

@ -10,7 +10,7 @@ import general
proc getSmallPic(url: string): string = proc getSmallPic(url: string): string =
result = url result = url
if "?" notin url and not url.endsWith("placeholder.png"): if "?" notin url and not url.endsWith("placeholder.png"):
result &= ":small" result &= "?name=small"
result = getPicUrl(result) result = getPicUrl(result)
proc renderMiniAvatar(user: User; prefs: Prefs): VNode = proc renderMiniAvatar(user: User; prefs: Prefs): VNode =
@ -57,9 +57,9 @@ proc renderAlbum(tweet: Tweet): VNode =
tdiv(class="attachment image"): tdiv(class="attachment image"):
let let
named = "name=" in photo named = "name=" in photo
orig = if named: photo else: photo & "?name=orig" orig = photo
small = if named: photo else: photo & "?name=small" small = if named: photo else: photo & "?name=small"
a(href=getPicUrl(orig), class="still-image", target="_blank"): a(href=getOrigPicUrl(orig), class="still-image", target="_blank"):
genImg(small) genImg(small)
proc isPlaybackEnabled(prefs: Prefs; video: Video): bool = proc isPlaybackEnabled(prefs: Prefs; video: Video): bool =