nitter/src/routes/status.nim

70 lines
2.1 KiB
Nim
Raw Normal View History

2019-10-26 13:34:30 +00:00
import asyncdispatch, strutils, sequtils, uri, options
2019-09-20 12:10:10 +00:00
import jester, karax/vdom
2019-09-20 12:10:10 +00:00
import router_utils
2020-06-01 00:22:56 +00:00
import ".."/[types, formatters, api]
2019-09-20 13:03:18 +00:00
import ../views/[general, status]
2019-09-20 12:10:10 +00:00
2019-10-26 13:34:30 +00:00
export uri, sequtils, options
2019-09-20 12:10:10 +00:00
export router_utils
2020-06-01 00:22:56 +00:00
export api, formatters
2019-09-20 13:03:18 +00:00
export status
2019-09-20 12:10:10 +00:00
proc createStatusRouter*(cfg: Config) =
router status:
get "/@name/status/@id/?":
2019-09-20 12:10:10 +00:00
cond '.' notin @"name"
let prefs = cookiePrefs()
if @"scroll".len > 0:
2020-06-01 00:22:56 +00:00
let replies = await getReplies(@"id", getCursor())
if replies.content.len == 0:
2020-05-01 10:29:01 +00:00
resp Http404, ""
resp $renderReplies(replies, prefs, getPath())
2020-06-01 00:22:56 +00:00
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"
2020-06-01 00:22:56 +00:00
if conv != nil and conv.tweet != nil and conv.tweet.tombstone.len > 0:
error = conv.tweet.tombstone
2019-10-21 05:59:22 +00:00
resp Http404, showError(error, cfg)
2019-09-20 12:10:10 +00:00
2019-12-08 11:38:55 +00:00
var
2020-06-01 00:22:56 +00:00
title = pageTitle(conv.tweet)
ogTitle = pageTitle(conv.tweet.profile)
desc = conv.tweet.text
images = conv.tweet.photos
2019-12-08 11:38:55 +00:00
video = ""
2019-09-20 12:10:10 +00:00
2020-06-01 00:22:56 +00:00
if conv.tweet.video.isSome():
images = @[get(conv.tweet.video).thumb]
video = getVideoEmbed(cfg, conv.tweet.id)
elif conv.tweet.gif.isSome():
images = @[get(conv.tweet.gif).thumb]
video = getPicUrl(get(conv.tweet.gif).url)
2020-11-09 20:20:33 +00:00
elif conv.tweet.card.isSome():
let card = conv.tweet.card.get()
if card.image.len > 0:
images = @[card.image]
elif card.video.isSome():
video = getVideoEmbed(cfg, parseInt(card.video.get().videoId))
2020-06-01 00:22:56 +00:00
let html = renderConversation(conv, prefs, getPath() & "#m")
2020-06-09 14:45:21 +00:00
resp renderMain(html, request, cfg, prefs, title, desc, ogTitle,
images=images, video=video)
2019-10-01 01:28:55 +00:00
2019-12-08 11:38:55 +00:00
get "/@name/@s/@id/@m/?@i?":
cond @"s" in ["status", "statuses"]
cond @"m" in ["video", "photo"]
2019-09-20 12:10:10 +00:00
redirect("/$1/status/$2" % [@"name", @"id"])
get "/@name/statuses/@id/?":
redirect("/$1/status/$2" % [@"name", @"id"])
2019-09-20 12:10:10 +00:00
get "/i/web/status/@id":
redirect("/i/status/" & @"id")