mirror of
https://github.com/zedeus/nitter
synced 2024-11-25 11:09:32 +01:00
changed code to be not shit
This commit is contained in:
parent
7f15993a74
commit
0d3469df66
@ -32,23 +32,25 @@ proc getUrlPrefix*(cfg: Config): string =
|
|||||||
if cfg.useHttps: https & cfg.hostname
|
if cfg.useHttps: https & cfg.hostname
|
||||||
else: "http://" & cfg.hostname
|
else: "http://" & cfg.hostname
|
||||||
|
|
||||||
proc stripHtml*(text: string): string =
|
proc shortLink*(text: string; length=28): string =
|
||||||
|
result = text.replace(wwwRegex, "")
|
||||||
|
if result.len > length:
|
||||||
|
result = result[0 ..< length] & "…"
|
||||||
|
|
||||||
|
proc stripHtml*(text: string; shorten=false): string =
|
||||||
var html = parseHtml(text)
|
var html = parseHtml(text)
|
||||||
for el in html.findAll("a"):
|
for el in html.findAll("a"):
|
||||||
let link = el.attr("href")
|
let link = el.attr("href")
|
||||||
if "http" in link:
|
if "http" in link:
|
||||||
if el.len == 0: continue
|
if el.len == 0: continue
|
||||||
el[0].text = link
|
el[0].text =
|
||||||
|
if shorten: link.shortLink
|
||||||
|
else: link
|
||||||
html.innerText()
|
html.innerText()
|
||||||
|
|
||||||
proc sanitizeXml*(text: string): string =
|
proc sanitizeXml*(text: string): string =
|
||||||
text.replace(illegalXmlRegex, "")
|
text.replace(illegalXmlRegex, "")
|
||||||
|
|
||||||
proc shortLink*(text: string; length=28): string =
|
|
||||||
result = text.replace(wwwRegex, "")
|
|
||||||
if result.len > length:
|
|
||||||
result = result[0 ..< length] & "…"
|
|
||||||
|
|
||||||
proc replaceUrls*(body: string; prefs: Prefs; absolute=""): string =
|
proc replaceUrls*(body: string; prefs: Prefs; absolute=""): string =
|
||||||
result = body
|
result = body
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ import types, config, prefs, formatters, redis_cache, http_pool, tokens
|
|||||||
import views/[general, about]
|
import views/[general, about]
|
||||||
import routes/[
|
import routes/[
|
||||||
preferences, timeline, status, media, search, rss, list, debug,
|
preferences, timeline, status, media, search, rss, list, debug,
|
||||||
unsupported, embed, resolver, router_utils, embedtweet]
|
unsupported, embed, resolver, router_utils]
|
||||||
|
|
||||||
const instancesUrl = "https://github.com/zedeus/nitter/wiki/Instances"
|
const instancesUrl = "https://github.com/zedeus/nitter/wiki/Instances"
|
||||||
const issuesUrl = "https://github.com/zedeus/nitter/issues"
|
const issuesUrl = "https://github.com/zedeus/nitter/issues"
|
||||||
@ -51,7 +51,6 @@ createMediaRouter(cfg)
|
|||||||
createEmbedRouter(cfg)
|
createEmbedRouter(cfg)
|
||||||
createRssRouter(cfg)
|
createRssRouter(cfg)
|
||||||
createDebugRouter(cfg)
|
createDebugRouter(cfg)
|
||||||
createEmbedTweetRouter(cfg)
|
|
||||||
|
|
||||||
settings:
|
settings:
|
||||||
port = Port(cfg.port)
|
port = Port(cfg.port)
|
||||||
@ -102,4 +101,3 @@ routes:
|
|||||||
extend media, ""
|
extend media, ""
|
||||||
extend embed, ""
|
extend embed, ""
|
||||||
extend debug, ""
|
extend debug, ""
|
||||||
extend embedtweet, ""
|
|
||||||
|
@ -1,9 +1,12 @@
|
|||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
import asyncdispatch, strutils, options
|
import asyncdispatch, strutils, options
|
||||||
import jester
|
import jester, karax/vdom
|
||||||
import ".."/[types, api], ../views/embed
|
import ".."/[types, api], ../views/[embed, tweet, general]
|
||||||
|
import router_utils
|
||||||
|
|
||||||
export api, embed
|
export api, embed, vdom
|
||||||
|
export tweet, general
|
||||||
|
export router_utils
|
||||||
|
|
||||||
proc createEmbedRouter*(cfg: Config) =
|
proc createEmbedRouter*(cfg: Config) =
|
||||||
router embed:
|
router embed:
|
||||||
@ -13,3 +16,11 @@ proc createEmbedRouter*(cfg: Config) =
|
|||||||
resp Http404
|
resp Http404
|
||||||
|
|
||||||
resp renderVideoEmbed(cfg, convo.tweet)
|
resp renderVideoEmbed(cfg, convo.tweet)
|
||||||
|
|
||||||
|
get "/@user/status/@id/embedded":
|
||||||
|
let
|
||||||
|
tweet = (await getTweet(@"id")).tweet
|
||||||
|
prefs = cookiePrefs()
|
||||||
|
path = getPath()
|
||||||
|
|
||||||
|
resp $renderEmbeddedTweet(tweet, cfg, prefs, path)
|
||||||
|
@ -1,22 +0,0 @@
|
|||||||
import asyncdispatch, strutils, uri, options
|
|
||||||
import jester, karax/vdom
|
|
||||||
|
|
||||||
import router_utils
|
|
||||||
import ".."/views/[general, tweet]
|
|
||||||
import ".."/[types, api]
|
|
||||||
|
|
||||||
export vdom
|
|
||||||
export router_utils
|
|
||||||
export api, tweet, general
|
|
||||||
|
|
||||||
proc createEmbedTweetRouter*(cfg: Config) =
|
|
||||||
router embedtweet:
|
|
||||||
get "/embed/Tweet.html":
|
|
||||||
let
|
|
||||||
prefs = cookiePrefs()
|
|
||||||
t = (await getTweet(@"id")).tweet
|
|
||||||
|
|
||||||
resp ($renderHead(prefs, cfg) & $renderTweet(t, prefs, getPath(), mainTweet=true))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -4,12 +4,12 @@ from jester import Request, cookies
|
|||||||
|
|
||||||
import ../views/general
|
import ../views/general
|
||||||
import ".."/[utils, prefs, types]
|
import ".."/[utils, prefs, types]
|
||||||
export utils, prefs, types
|
export utils, prefs, types, uri
|
||||||
|
|
||||||
template savePref*(pref, value: string; req: Request; expire=false) =
|
template savePref*(pref, value: string; req: Request; expire=false) =
|
||||||
if not expire or pref in cookies(req):
|
if not expire or pref in cookies(req):
|
||||||
setCookie(pref, value, daysForward(when expire: -10 else: 360),
|
setCookie(pref, value, daysForward(when expire: -10 else: 360),
|
||||||
httpOnly=true, secure=cfg.useHttps)
|
httpOnly=true, secure=cfg.useHttps, sameSite=None)
|
||||||
|
|
||||||
template cookiePrefs*(): untyped {.dirty.} =
|
template cookiePrefs*(): untyped {.dirty.} =
|
||||||
getPrefs(cookies(request))
|
getPrefs(cookies(request))
|
||||||
|
@ -4,6 +4,7 @@ import karax/[karaxdsl, vdom, vstyles]
|
|||||||
|
|
||||||
import renderutils
|
import renderutils
|
||||||
import ".."/[types, utils, formatters]
|
import ".."/[types, utils, formatters]
|
||||||
|
import general
|
||||||
|
|
||||||
proc getSmallPic(url: string): string =
|
proc getSmallPic(url: string): string =
|
||||||
result = url
|
result = url
|
||||||
@ -275,6 +276,59 @@ proc renderLocation*(tweet: Tweet): string =
|
|||||||
text place
|
text place
|
||||||
return $node
|
return $node
|
||||||
|
|
||||||
|
proc renderEmbeddedTweet*(tweet: Tweet; cfg: Config; prefs: Prefs; path: string): VNode =
|
||||||
|
let fullTweet = tweet
|
||||||
|
var retweet: string
|
||||||
|
var tweet = fullTweet
|
||||||
|
if tweet.retweet.isSome:
|
||||||
|
tweet = tweet.retweet.get
|
||||||
|
retweet = fullTweet.profile.fullname
|
||||||
|
|
||||||
|
# handle unavailable
|
||||||
|
|
||||||
|
buildHtml(tdiv(class="timeline-item")):
|
||||||
|
renderHead(prefs, cfg)
|
||||||
|
tdiv(class="tweet-body"):
|
||||||
|
var views = ""
|
||||||
|
renderHeader(tweet, retweet, prefs)
|
||||||
|
|
||||||
|
var tweetClass = "tweet-content media-body"
|
||||||
|
if prefs.bidiSupport:
|
||||||
|
tweetClass &= " tweet-bidi"
|
||||||
|
|
||||||
|
tdiv(class=tweetClass, dir="auto"):
|
||||||
|
verbatim replaceUrls(tweet.text, prefs) & renderLocation(tweet)
|
||||||
|
|
||||||
|
if tweet.attribution.isSome:
|
||||||
|
renderAttribution(tweet.attribution.get(), prefs)
|
||||||
|
|
||||||
|
if tweet.card.isSome:
|
||||||
|
renderCard(tweet.card.get(), prefs, path)
|
||||||
|
|
||||||
|
if tweet.photos.len > 0:
|
||||||
|
renderAlbum(tweet)
|
||||||
|
elif tweet.video.isSome:
|
||||||
|
renderVideo(tweet.video.get(), prefs, path)
|
||||||
|
views = tweet.video.get().views
|
||||||
|
elif tweet.gif.isSome:
|
||||||
|
renderGif(tweet.gif.get(), prefs)
|
||||||
|
views = "GIF"
|
||||||
|
|
||||||
|
if tweet.poll.isSome:
|
||||||
|
renderPoll(tweet.poll.get())
|
||||||
|
|
||||||
|
if tweet.quote.isSome:
|
||||||
|
renderQuote(tweet.quote.get(), prefs, path)
|
||||||
|
|
||||||
|
p(class="tweet-published"): text getTime(tweet)
|
||||||
|
|
||||||
|
if tweet.mediaTags.len > 0:
|
||||||
|
renderMediaTags(tweet.mediaTags)
|
||||||
|
|
||||||
|
if not prefs.hideTweetStats:
|
||||||
|
renderStats(tweet.stats, views)
|
||||||
|
|
||||||
|
|
||||||
proc renderTweet*(tweet: Tweet; prefs: Prefs; path: string; class=""; index=0;
|
proc renderTweet*(tweet: Tweet; prefs: Prefs; path: string; class=""; index=0;
|
||||||
last=false; showThread=false; mainTweet=false; afterTweet=false): VNode =
|
last=false; showThread=false; mainTweet=false; afterTweet=false): VNode =
|
||||||
var divClass = class
|
var divClass = class
|
||||||
|
Loading…
Reference in New Issue
Block a user