2019-10-26 13:34:30 +00:00
|
|
|
import asyncdispatch, strutils, sequtils, uri, options
|
2019-09-20 12:10:10 +00:00
|
|
|
|
|
|
|
import jester
|
|
|
|
|
|
|
|
import router_utils
|
2019-09-20 23:08:30 +00:00
|
|
|
import ".."/[api, types, formatters, agents]
|
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
|
2019-09-20 13:03:18 +00:00
|
|
|
export api, formatters, agents
|
|
|
|
export status
|
2019-09-20 12:10:10 +00:00
|
|
|
|
|
|
|
proc createStatusRouter*(cfg: Config) =
|
|
|
|
router status:
|
|
|
|
get "/@name/status/@id":
|
|
|
|
cond '.' notin @"name"
|
|
|
|
let prefs = cookiePrefs()
|
|
|
|
|
2019-10-08 13:15:47 +00:00
|
|
|
let conversation = await getTweet(@"name", @"id", @"max_position", getAgent())
|
2019-10-10 16:22:14 +00:00
|
|
|
if conversation == nil or conversation.tweet.id == 0:
|
2019-10-07 14:47:53 +00:00
|
|
|
var error = "Tweet not found"
|
2019-09-20 12:10:10 +00:00
|
|
|
if conversation != nil and conversation.tweet.tombstone.len > 0:
|
2019-10-07 14:47:53 +00:00
|
|
|
error = conversation.tweet.tombstone
|
2019-10-21 05:59:22 +00:00
|
|
|
resp Http404, showError(error, cfg)
|
2019-09-20 12:10:10 +00:00
|
|
|
|
2019-09-20 20:56:27 +00:00
|
|
|
let
|
|
|
|
title = pageTitle(conversation.tweet.profile)
|
|
|
|
desc = conversation.tweet.text
|
2019-10-26 15:21:35 +00:00
|
|
|
html = renderConversation(conversation, prefs, getPath() & "#m")
|
2019-09-20 12:10:10 +00:00
|
|
|
|
|
|
|
if conversation.tweet.video.isSome():
|
|
|
|
let thumb = get(conversation.tweet.video).thumb
|
|
|
|
let vidUrl = getVideoEmbed(conversation.tweet.id)
|
2019-10-21 03:19:00 +00:00
|
|
|
resp renderMain(html, request, cfg, title, desc, images = @[thumb],
|
2019-09-20 12:10:10 +00:00
|
|
|
`type`="video", video=vidUrl)
|
|
|
|
elif conversation.tweet.gif.isSome():
|
|
|
|
let thumb = get(conversation.tweet.gif).thumb
|
2019-10-23 07:16:27 +00:00
|
|
|
let vidUrl = getGifUrl(get(conversation.tweet.gif).url)
|
2019-10-21 03:19:00 +00:00
|
|
|
resp renderMain(html, request, cfg, title, desc, images = @[thumb],
|
2019-09-20 12:10:10 +00:00
|
|
|
`type`="video", video=vidUrl)
|
|
|
|
else:
|
2019-10-21 03:19:00 +00:00
|
|
|
resp renderMain(html, request, cfg, title, desc,
|
2019-09-20 12:10:10 +00:00
|
|
|
images=conversation.tweet.photos, `type`="photo")
|
|
|
|
|
2019-09-30 20:07:41 +00:00
|
|
|
get "/@name/status/@id/photo/@i":
|
|
|
|
redirect("/$1/status/$2" % [@"name", @"id"])
|
|
|
|
|
2019-10-01 01:28:55 +00:00
|
|
|
get "/@name/status/@id/video/@i":
|
|
|
|
redirect("/$1/status/$2" % [@"name", @"id"])
|
|
|
|
|
2019-09-30 20:07:41 +00:00
|
|
|
get "/@name/statuses/@id":
|
2019-09-20 12:10:10 +00:00
|
|
|
redirect("/$1/status/$2" % [@"name", @"id"])
|
|
|
|
|
|
|
|
get "/i/web/status/@id":
|
|
|
|
redirect("/i/status/" & @"id")
|