fix direct video route
This commit is contained in:
parent
b3e35dba12
commit
5240ccff2a
2 changed files with 10 additions and 33 deletions
|
@ -86,7 +86,7 @@ proc createActivityPubRouter*(cfg: Config) =
|
|||
|
||||
mediaObj["id"] = %"150745989836308480"
|
||||
mediaObj["type"] = %"video"
|
||||
mediaObj["url"] = %gif.url
|
||||
mediaObj["url"] = %(getUrlPrefix(cfg) & getPicUrl(gif.thumb))
|
||||
mediaObj["preview_url"] = %(getUrlPrefix(cfg) & getPicUrl(gif.thumb))
|
||||
mediaObj["remote_url"] = newJNull()
|
||||
mediaObj["preview_remote_url"] = newJNull()
|
||||
|
|
|
@ -39,7 +39,11 @@ proc createStatusRouter*(cfg: Config) =
|
|||
|
||||
get "/@name/status/@id/?":
|
||||
cond '.' notin @"name"
|
||||
let id = @"id"
|
||||
var id = @"id"
|
||||
var rawFile = false
|
||||
if id.endsWith(".mp4"):
|
||||
rawFile = true
|
||||
id.removeSuffix(".mp4")
|
||||
|
||||
if request.headers.hasKey("Accept") and request.headers["Accept"] == "application/activity+json":
|
||||
if id.len > 19 or id.any(c => not c.isDigit):
|
||||
|
@ -126,7 +130,7 @@ proc createStatusRouter*(cfg: Config) =
|
|||
elif tweet.gif.isSome():
|
||||
let gif = get(tweet.gif)
|
||||
images = @[gif.thumb]
|
||||
video = getPicUrl(gif.url)
|
||||
video = getUrlPrefix(cfg) & getPicUrl(gif.url)
|
||||
#elif tweet.card.isSome():
|
||||
# let card = tweet.card.get()
|
||||
# if card.image.len > 0:
|
||||
|
@ -134,41 +138,14 @@ proc createStatusRouter*(cfg: Config) =
|
|||
# elif card.video.isSome():
|
||||
# images = @[card.video.get().thumb]
|
||||
|
||||
if rawFile:
|
||||
redirect(video)
|
||||
|
||||
let html = renderConversation(conv, prefs, getPath() & "#m")
|
||||
resp renderMain(html, request, cfg, prefs, title, desc, ogTitle,
|
||||
images=images, video=video, avatar=avatar, time=time,
|
||||
context=context, contextUrl=contextUrl, id=id)
|
||||
|
||||
get "/@name/status/@id.mp4":
|
||||
cond '.' notin @"name"
|
||||
let id = @"id"
|
||||
|
||||
if id.len > 19 or id.any(c => not c.isDigit):
|
||||
resp Http404, showError("Invalid tweet ID", cfg)
|
||||
|
||||
let conv = await getTweet(id, getCursor())
|
||||
if conv == nil:
|
||||
echo "nil conv"
|
||||
|
||||
if conv == nil or conv.tweet == nil or conv.tweet.id == 0:
|
||||
var error = "Tweet not found"
|
||||
if conv != nil and conv.tweet != nil and conv.tweet.tombstone.len > 0:
|
||||
error = conv.tweet.tombstone
|
||||
resp Http404, showError(error, cfg)
|
||||
|
||||
let tweet = conv.tweet
|
||||
|
||||
if tweet.video.isSome():
|
||||
let videoObj = get(tweet.video)
|
||||
let vars = videoObj.variants.filterIt(it.contentType == mp4)
|
||||
redirect(vars[^1].url)
|
||||
elif tweet.gif.isSome():
|
||||
let gif = get(tweet.gif)
|
||||
let url = getPicUrl(gif.url)
|
||||
redirect(url)
|
||||
|
||||
redirect("/$1/status/$2" % [@"name", @"id"])
|
||||
|
||||
get "/@name/@s/@id/@m/?@i?":
|
||||
cond @"s" in ["status", "statuses"]
|
||||
cond @"m" in ["video", "photo"]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue