nitter/src/routes/status.nim

57 lines
1.9 KiB
Nim
Raw Normal View History

2019-09-20 14:10:10 +02:00
import asyncdispatch, strutils, sequtils, uri
import jester
import router_utils
2019-09-21 01:08:30 +02:00
import ".."/[api, types, formatters, agents]
2019-09-20 15:03:18 +02:00
import ../views/[general, status]
2019-09-20 14:10:10 +02:00
export uri, sequtils
export router_utils
2019-09-20 15:03:18 +02:00
export api, formatters, agents
export status
2019-09-20 14:10:10 +02:00
proc createStatusRouter*(cfg: Config) =
router status:
get "/@name/status/@id":
cond '.' notin @"name"
let prefs = cookiePrefs()
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 14:10:10 +02:00
if conversation != nil and conversation.tweet.tombstone.len > 0:
error = conversation.tweet.tombstone
halt Http404, showError(error, cfg)
2019-09-20 14:10:10 +02:00
2019-09-20 22:56:27 +02:00
let
title = pageTitle(conversation.tweet.profile)
desc = conversation.tweet.text
html = renderConversation(conversation, prefs, getPath())
2019-09-20 14:10:10 +02:00
if conversation.tweet.video.isSome():
let thumb = get(conversation.tweet.video).thumb
let vidUrl = getVideoEmbed(conversation.tweet.id)
resp renderMain(html, request, cfg, title, desc, images = @[thumb],
2019-09-20 14:10:10 +02:00
`type`="video", video=vidUrl)
elif conversation.tweet.gif.isSome():
let thumb = get(conversation.tweet.gif).thumb
let vidUrl = getVideoEmbed(conversation.tweet.id)
resp renderMain(html, request, cfg, title, desc, images = @[thumb],
2019-09-20 14:10:10 +02:00
`type`="video", video=vidUrl)
else:
resp renderMain(html, request, cfg, title, desc,
2019-09-20 14:10:10 +02:00
images=conversation.tweet.photos, `type`="photo")
get "/@name/status/@id/photo/@i":
redirect("/$1/status/$2" % [@"name", @"id"])
2019-10-01 03:28:55 +02:00
get "/@name/status/@id/video/@i":
redirect("/$1/status/$2" % [@"name", @"id"])
get "/@name/statuses/@id":
2019-09-20 14:10:10 +02:00
redirect("/$1/status/$2" % [@"name", @"id"])
get "/i/web/status/@id":
redirect("/i/status/" & @"id")