nitter/src/routes/status.nim

59 lines
1.9 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
2019-09-20 23:08:30 +00:00
import ".."/[api, types, formatters, agents]
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
2019-09-20 13:03:18 +00:00
export api, formatters, agents
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:
let replies = await getReplies(@"name", @"id", @"max_position", getAgent())
resp $renderReplies(replies, prefs, getPath())
let conversation = await getTweet(@"name", @"id", @"max_position", getAgent())
if conversation == nil or conversation.tweet.id == 0:
var error = "Tweet not found"
2019-09-20 12:10:10 +00:00
if conversation != nil and conversation.tweet.tombstone.len > 0:
error = conversation.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-03-29 07:15:05 +00:00
title = pageTitle(conversation.tweet)
2020-03-29 21:20:00 +00:00
ogTitle = pageTitle(conversation.tweet.profile)
2019-09-20 20:56:27 +00:00
desc = conversation.tweet.text
2019-12-08 11:38:55 +00:00
images = conversation.tweet.photos
video = ""
2019-09-20 12:10:10 +00:00
if conversation.tweet.video.isSome():
2019-12-08 11:38:55 +00:00
images = @[get(conversation.tweet.video).thumb]
video = getVideoEmbed(cfg, conversation.tweet.id)
2019-09-20 12:10:10 +00:00
elif conversation.tweet.gif.isSome():
2019-12-08 11:38:55 +00:00
images = @[get(conversation.tweet.gif).thumb]
video = getGifUrl(get(conversation.tweet.gif).url)
2019-12-08 11:38:55 +00:00
let html = renderConversation(conversation, prefs, getPath() & "#m")
2020-03-29 21:20:00 +00:00
resp renderMain(html, request, cfg, title, desc,
images=images, video=video, ogTitle=ogTitle)
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")