Deduplicate UserMedia requests for proxy caching

Fixes #1440
This commit is contained in:
Zed 2026-08-21 21:42:56 +07:00
commit 11d4eb9e39

View file

@ -23,10 +23,10 @@ proc cursorParam(after: string): string =
## variables object (same input-validation class as the #1411 media SSRF). ## variables object (same input-validation class as the #1411 media SSRF).
if after.len > 0: "\"cursor\":" & $(%after) & "," else: "" if after.len > 0: "\"cursor\":" & $(%after) & "," else: ""
proc mediaUrl(id, cursor: string; count=20): ApiReq = proc mediaUrl(id, cursor: string): ApiReq =
result = ApiReq( result = ApiReq(
cookie: apiUrl(graphUserMedia, userMediaVars % [id, cursor, $count]), cookie: apiUrl(graphUserMedia, userMediaVars % [id, cursor, "100"]),
oauth: apiUrl(graphUserMediaV2, restIdVars % [id, cursor, $count]) oauth: apiUrl(graphUserMediaV2, restIdVars % [id, cursor, "100"])
) )
proc userTweetsUrl(id: string; cursor: string): ApiReq = proc userTweetsUrl(id: string; cursor: string): ApiReq =
@ -108,7 +108,7 @@ proc getGraphUserTweets*(id: string; kind: TimelineKind; after=""): Future[Profi
url = case kind url = case kind
of TimelineKind.tweets: userTweetsUrl(id, cursor) of TimelineKind.tweets: userTweetsUrl(id, cursor)
of TimelineKind.replies: userTweetsAndRepliesUrl(id, cursor) of TimelineKind.replies: userTweetsAndRepliesUrl(id, cursor)
of TimelineKind.media: mediaUrl(id, cursor, 100) of TimelineKind.media: mediaUrl(id, cursor)
js = await fetch(url) js = await fetch(url)
result = parseGraphTimeline(js, after) result = parseGraphTimeline(js, after)
@ -333,7 +333,7 @@ proc getGraphListSearch*(query: Query; after=""): Future[Result[ListSearchResult
proc getPhotoRail*(id: string): Future[PhotoRail] {.async.} = proc getPhotoRail*(id: string): Future[PhotoRail] {.async.} =
if id.len == 0: return if id.len == 0: return
let js = await fetch(mediaUrl(id, "", 30)) let js = await fetch(mediaUrl(id, ""))
result = parseGraphPhotoRail(js) result = parseGraphPhotoRail(js)
proc getGraphArticle*(id: string): Future[Article] {.async.} = proc getGraphArticle*(id: string): Future[Article] {.async.} =