From fd20fcf3ee3e297b55bffa74d6b6b20e145e2f03 Mon Sep 17 00:00:00 2001 From: Zed Date: Fri, 20 Sep 2019 14:10:10 +0200 Subject: [PATCH] Support /photo/1 endpoint Fixes #43 --- src/nitter.nim | 4 +++- src/routes/status.nim | 52 +++++++++++++++++++++++++++++++++++++++++ src/routes/timeline.nim | 2 -- 3 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 src/routes/status.nim diff --git a/src/nitter.nim b/src/nitter.nim index 41dc3b9..cece195 100644 --- a/src/nitter.nim +++ b/src/nitter.nim @@ -5,13 +5,14 @@ import jester import types, config, prefs import views/[general, about] -import routes/[preferences, timeline, media, search, rss] +import routes/[preferences, timeline, status, media, search, rss] const configPath {.strdefine.} = "./nitter.conf" let cfg = getConfig(configPath) createPrefRouter(cfg) createTimelineRouter(cfg) +createStatusRouter(cfg) createSearchRouter(cfg) createMediaRouter(cfg) createRssRouter(cfg) @@ -32,6 +33,7 @@ routes: extend rss, "" extend search, "" extend timeline, "" + extend status, "" extend media, "" runForever() diff --git a/src/routes/status.nim b/src/routes/status.nim new file mode 100644 index 0000000..cdeaca4 --- /dev/null +++ b/src/routes/status.nim @@ -0,0 +1,52 @@ +import asyncdispatch, strutils, sequtils, uri + +import jester + +import router_utils +import ".."/[api, prefs, types, utils, cache, formatters, agents, query] +import ../views/[general, profile, timeline, status, search] + +export uri, sequtils +export router_utils +export api, cache, formatters, query, agents +export profile, status + +proc createStatusRouter*(cfg: Config) = + setProfileCacheTime(cfg.profileCacheTime) + + router status: + get "/@name/status/@id": + cond '.' notin @"name" + let prefs = cookiePrefs() + + let conversation = await getTweet(@"name", @"id", getAgent()) + if conversation == nil or conversation.tweet.id.len == 0: + if conversation != nil and conversation.tweet.tombstone.len > 0: + resp Http404, showError(conversation.tweet.tombstone, cfg.title) + else: + resp Http404, showError("Tweet not found", cfg.title) + + let path = getPath() + let title = pageTitle(conversation.tweet.profile) + let desc = conversation.tweet.text + let html = renderConversation(conversation, prefs, path) + + if conversation.tweet.video.isSome(): + let thumb = get(conversation.tweet.video).thumb + let vidUrl = getVideoEmbed(conversation.tweet.id) + resp renderMain(html, prefs, cfg.title, title, desc, path, images = @[thumb], + `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, prefs, cfg.title, title, desc, path, images = @[thumb], + `type`="video", video=vidUrl) + else: + resp renderMain(html, prefs, cfg.title, title, desc, path, + images=conversation.tweet.photos, `type`="photo") + + get "/@name/status/@id/photo/1": + redirect("/$1/status/$2" % [@"name", @"id"]) + + get "/i/web/status/@id": + redirect("/i/status/" & @"id") diff --git a/src/routes/timeline.nim b/src/routes/timeline.nim index 41f3742..285d31b 100644 --- a/src/routes/timeline.nim +++ b/src/routes/timeline.nim @@ -6,8 +6,6 @@ import router_utils import ".."/[api, prefs, types, utils, cache, formatters, agents, query] import ../views/[general, profile, timeline, status, search] -include "../views/rss.nimf" - export uri, sequtils export router_utils export api, cache, formatters, query, agents