2021-12-27 01:37:38 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
2022-01-23 06:04:50 +00:00
|
|
|
import asyncdispatch, strutils, sequtils, uri, options, sugar
|
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
|
|
|
|
2022-01-23 06:04:50 +00:00
|
|
|
export uri, sequtils, options, sugar
|
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"
|
2023-04-21 12:41:30 +00:00
|
|
|
let id = @"id"
|
|
|
|
|
|
|
|
if id.len > 19 or id.any(c => not c.isDigit):
|
|
|
|
resp Http404, showError("Invalid tweet ID", cfg)
|
|
|
|
|
2019-09-20 12:10:10 +00:00
|
|
|
let prefs = cookiePrefs()
|
|
|
|
|
2021-12-30 03:18:40 +00:00
|
|
|
# used for the infinite scroll feature
|
2020-04-29 16:09:13 +00:00
|
|
|
if @"scroll".len > 0:
|
2023-04-21 12:41:30 +00:00
|
|
|
let replies = await getReplies(id, getCursor())
|
2020-06-01 00:22:56 +00:00
|
|
|
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())
|
|
|
|
|
2023-04-21 12:41:30 +00:00
|
|
|
let conv = await getTweet(id, getCursor())
|
2020-06-01 00:22:56 +00:00
|
|
|
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
|
|
|
|
2021-12-30 03:18:40 +00:00
|
|
|
let
|
2020-06-01 00:22:56 +00:00
|
|
|
title = pageTitle(conv.tweet)
|
2022-01-23 06:04:50 +00:00
|
|
|
ogTitle = pageTitle(conv.tweet.user)
|
2020-06-01 00:22:56 +00:00
|
|
|
desc = conv.tweet.text
|
2021-12-30 03:18:40 +00:00
|
|
|
|
|
|
|
var
|
2020-06-01 00:22:56 +00:00
|
|
|
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")
|
2022-06-23 20:47:03 +00:00
|
|
|
|
|
|
|
get "/@name/thread/@id/?":
|
|
|
|
redirect("/$1/status/$2" % [@"name", @"id"])
|