nitter/src/routes/status.nim

75 lines
2.3 KiB
Nim
Raw Normal View History

2021-12-27 02:37:38 +01:00
# SPDX-License-Identifier: AGPL-3.0-only
import asyncdispatch, strutils, sequtils, uri, options, sugar
2019-09-20 14:10:10 +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
export uri, sequtils, options, sugar
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:
get "/@name/status/@id/?":
2019-09-20 14:10:10 +02:00
cond '.' notin @"name"
cond not @"id".any(c => not c.isDigit)
2019-09-20 14:10:10 +02:00
let prefs = cookiePrefs()
2021-12-30 04:18:40 +01:00
# used for the infinite scroll feature
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, ""
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:
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
2021-12-30 04:18:40 +01:00
let
2020-06-01 02:22:56 +02:00
title = pageTitle(conv.tweet)
ogTitle = pageTitle(conv.tweet.user)
2020-06-01 02:22:56 +02:00
desc = conv.tweet.text
2021-12-30 04:18:40 +01:00
var
2020-06-01 02:22:56 +02:00
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]
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]
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"])
get "/@name/statuses/@id/?":
redirect("/$1/status/$2" % [@"name", @"id"])
2019-09-20 14:10:10 +02:00
get "/i/web/status/@id":
redirect("/i/status/" & @"id")