2019-10-26 13:34:30 +00:00
|
|
|
import asyncdispatch, strutils, sequtils, uri, options
|
2019-09-20 12:10:10 +00:00
|
|
|
|
2020-04-29 16:09:13 +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:
|
2020-04-29 13:09:51 +00:00
|
|
|
get "/@name/status/@id/?":
|
2019-09-20 12:10:10 +00:00
|
|
|
cond '.' notin @"name"
|
|
|
|
let prefs = cookiePrefs()
|
|
|
|
|
2020-04-29 16:09:13 +00:00
|
|
|
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, ""
|
2020-04-29 16:09:13 +00:00
|
|
|
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:
|
2019-10-07 14:47:53 +00:00
|
|
|
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]
|
2020-06-06 02:39:22 +00:00
|
|
|
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():
|
2020-11-09 20:24:34 +00:00
|
|
|
images = @[card.video.get().thumb]
|
2019-09-30 20:07:41 +00:00
|
|
|
|
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"])
|
|
|
|
|
2020-04-29 13:09:51 +00:00
|
|
|
get "/@name/statuses/@id/?":
|
2019-12-30 09:58:15 +00:00
|
|
|
redirect("/$1/status/$2" % [@"name", @"id"])
|
|
|
|
|
2019-09-20 12:10:10 +00:00
|
|
|
get "/i/web/status/@id":
|
|
|
|
redirect("/i/status/" & @"id")
|