Add new endpoint for original resolution images
This change is to work around the issue that chromium based browsers have handling the "name=orig" parameter appended to URLs. This parameter is needed to retrieve the full resolution image from twitter, but causes those browsers to fill in "jpg_name=orig" as the extension on the filename. This change adds a new endpoint, "/pic/orig/<encoded media>". This new endpoint will internally fetch the URL with ":orig" appended on the end for the full res image. Externally, the endpoint will serve the image without the extra parameter to expose the real extension to the browser. This new endpoint is used when rendering tweets with attached images. The old endpoint is still in place for all other proxied images, and for any legacy links. I also updated the "?name=small" parameter to ":small" since that seems to be the new pattern for image sizing. This should fix issue #458.
This commit is contained in:
parent
adfd31c530
commit
4cdb8f78cb
3 changed files with 23 additions and 3 deletions
|
@ -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(":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:
|
||||||
|
|
|
@ -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:
|
||||||
|
|
|
@ -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 & ":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 =
|
||||||
|
|
Loading…
Reference in a new issue