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