Use referer form data instead of relying on header
This commit is contained in:
@@ -5,7 +5,7 @@ import ../utils, ../types
|
||||
|
||||
const doctype = "<!DOCTYPE html>\n"
|
||||
|
||||
proc renderNavbar*(title: string): VNode =
|
||||
proc renderNavbar*(title, path: string): VNode =
|
||||
buildHtml(nav(id="nav", class="nav-bar container")):
|
||||
tdiv(class="inner-nav"):
|
||||
tdiv(class="item"):
|
||||
@@ -15,10 +15,10 @@ proc renderNavbar*(title: string): VNode =
|
||||
|
||||
tdiv(class="item right"):
|
||||
icon "info-circled", title="About", href="/about"
|
||||
icon "cog", title="Preferences", href="/settings"
|
||||
iconReferer "cog", "/settings", path, title="Preferences"
|
||||
|
||||
proc renderMain*(body: VNode; prefs: Prefs; title="Nitter"; titleText=""; desc="";
|
||||
`type`="article"; video=""; images: seq[string] = @[]): string =
|
||||
path="/"; `type`="article"; video=""; images: seq[string] = @[]): string =
|
||||
let node = buildHtml(html(lang="en")):
|
||||
head:
|
||||
link(rel="stylesheet", `type`="text/css", href="/css/style.css")
|
||||
@@ -47,7 +47,7 @@ proc renderMain*(body: VNode; prefs: Prefs; title="Nitter"; titleText=""; desc="
|
||||
meta(property="og:video:secure_url", content=video)
|
||||
|
||||
body:
|
||||
renderNavbar(title)
|
||||
renderNavbar(title, path)
|
||||
|
||||
tdiv(id="content", class="container"):
|
||||
body
|
||||
|
||||
@@ -63,5 +63,6 @@ proc renderPreferences*(prefs: Prefs; path: string): VNode =
|
||||
text "Save preferences"
|
||||
|
||||
form(`method`="post", action="/resetprefs", class="pref-reset"):
|
||||
verbatim "<input name=\"referer\" style=\"display: none\" value=\"$1\"/>" % path
|
||||
button(`type`="submit"):
|
||||
text "Reset preferences"
|
||||
|
||||
@@ -68,7 +68,7 @@ proc renderBanner(profile: Profile): VNode =
|
||||
genImg(profile.banner)
|
||||
|
||||
proc renderProfile*(profile: Profile; timeline: Timeline;
|
||||
photoRail: seq[GalleryPhoto]; prefs: Prefs): VNode =
|
||||
photoRail: seq[GalleryPhoto]; prefs: Prefs; path: string): VNode =
|
||||
buildHtml(tdiv(class="profile-tabs")):
|
||||
if not prefs.hideBanner:
|
||||
tdiv(class="profile-banner"):
|
||||
@@ -81,9 +81,10 @@ proc renderProfile*(profile: Profile; timeline: Timeline;
|
||||
renderPhotoRail(profile, photoRail)
|
||||
|
||||
tdiv(class="timeline-tab"):
|
||||
renderTimeline(timeline, profile.username, profile.protected, prefs)
|
||||
renderTimeline(timeline, profile.username, profile.protected, prefs, path)
|
||||
|
||||
proc renderMulti*(timeline: Timeline; usernames: string; prefs: Prefs): VNode =
|
||||
proc renderMulti*(timeline: Timeline; usernames: string;
|
||||
prefs: Prefs; path: string): VNode =
|
||||
buildHtml(tdiv(class="multi-timeline")):
|
||||
tdiv(class="timeline-tab"):
|
||||
renderTimeline(timeline, usernames, false, prefs, multi=true)
|
||||
renderTimeline(timeline, usernames, false, prefs, path, multi=true)
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import strutils
|
||||
import karax/[karaxdsl, vdom, vstyles]
|
||||
|
||||
import ../types, ../utils
|
||||
@@ -37,3 +38,9 @@ proc linkText*(text: string; class=""): VNode =
|
||||
let url = if "http" notin text: "http://" & text else: text
|
||||
buildHtml():
|
||||
a(href=url, class=class): text text
|
||||
|
||||
proc iconReferer*(icon, action, path: string, title=""): VNode =
|
||||
buildHtml(form(`method`="get", action=action, class="icon-button")):
|
||||
verbatim "<input name=\"referer\" style=\"display: none\" value=\"$1\"/>" % path
|
||||
button(`type`="submit"):
|
||||
icon icon, title=title
|
||||
|
||||
@@ -11,34 +11,34 @@ proc renderMoreReplies(thread: Thread): VNode =
|
||||
a(class="more-replies-text", title="Not implemented yet"):
|
||||
text $num & "more " & reply
|
||||
|
||||
proc renderReplyThread(thread: Thread; prefs: Prefs): VNode =
|
||||
proc renderReplyThread(thread: Thread; prefs: Prefs; path: string): VNode =
|
||||
buildHtml(tdiv(class="reply thread thread-line")):
|
||||
for i, tweet in thread.content:
|
||||
let last = (i == thread.content.high and thread.more == 0)
|
||||
renderTweet(tweet, prefs, index=i, last=last)
|
||||
renderTweet(tweet, prefs, path, index=i, last=last)
|
||||
|
||||
if thread.more != 0:
|
||||
renderMoreReplies(thread)
|
||||
|
||||
proc renderConversation*(conversation: Conversation; prefs: Prefs): VNode =
|
||||
proc renderConversation*(conversation: Conversation; prefs: Prefs; path: string): VNode =
|
||||
let hasAfter = conversation.after != nil
|
||||
buildHtml(tdiv(class="conversation", id="posts")):
|
||||
tdiv(class="main-thread"):
|
||||
if conversation.before != nil:
|
||||
tdiv(class="before-tweet thread-line"):
|
||||
for i, tweet in conversation.before.content:
|
||||
renderTweet(tweet, prefs, index=i)
|
||||
renderTweet(tweet, prefs, path, index=i)
|
||||
|
||||
tdiv(class="main-tweet"):
|
||||
let afterClass = if hasAfter: "thread thread-line" else: ""
|
||||
renderTweet(conversation.tweet, prefs, class=afterClass)
|
||||
renderTweet(conversation.tweet, prefs, path, class=afterClass)
|
||||
|
||||
if hasAfter:
|
||||
tdiv(class="after-tweet thread-line"):
|
||||
let total = conversation.after.content.high
|
||||
let more = conversation.after.more
|
||||
for i, tweet in conversation.after.content:
|
||||
renderTweet(tweet, prefs, index=i, last=(i == total and more == 0))
|
||||
renderTweet(tweet, prefs, path, index=i, last=(i == total and more == 0))
|
||||
|
||||
if more != 0:
|
||||
renderMoreReplies(conversation.after)
|
||||
@@ -46,4 +46,5 @@ proc renderConversation*(conversation: Conversation; prefs: Prefs): VNode =
|
||||
if conversation.replies.len > 0:
|
||||
tdiv(class="replies"):
|
||||
for thread in conversation.replies:
|
||||
renderReplyThread(thread, prefs)
|
||||
if thread == nil: continue
|
||||
renderReplyThread(thread, prefs, path)
|
||||
|
||||
@@ -54,28 +54,29 @@ proc renderProtected(username: string): VNode =
|
||||
h2: text "This account's tweets are protected."
|
||||
p: text &"Only confirmed followers have access to @{username}'s tweets."
|
||||
|
||||
proc renderThread(thread: seq[Tweet]; prefs: Prefs): VNode =
|
||||
proc renderThread(thread: seq[Tweet]; prefs: Prefs; path: string): VNode =
|
||||
buildHtml(tdiv(class="timeline-tweet thread-line")):
|
||||
for i, threadTweet in thread.sortedByIt(it.time):
|
||||
renderTweet(threadTweet, prefs, class="thread", index=i, total=thread.high)
|
||||
renderTweet(threadTweet, prefs, path, class="thread",
|
||||
index=i, total=thread.high)
|
||||
|
||||
proc threadFilter(it: Tweet; tweetThread: string): bool =
|
||||
it.retweet.isNone and it.reply.len == 0 and it.threadId == tweetThread
|
||||
|
||||
proc renderTweets(timeline: Timeline; prefs: Prefs): VNode =
|
||||
proc renderTweets(timeline: Timeline; prefs: Prefs; path: string): VNode =
|
||||
buildHtml(tdiv(id="posts")):
|
||||
var threads: seq[string]
|
||||
for tweet in timeline.content:
|
||||
if tweet.threadId in threads: continue
|
||||
let thread = timeline.content.filterIt(threadFilter(it, tweet.threadId))
|
||||
if thread.len < 2:
|
||||
renderTweet(tweet, prefs, class="timeline-tweet")
|
||||
renderTweet(tweet, prefs, path, class="timeline-tweet")
|
||||
else:
|
||||
renderThread(thread, prefs)
|
||||
renderThread(thread, prefs, path)
|
||||
threads &= tweet.threadId
|
||||
|
||||
proc renderTimeline*(timeline: Timeline; username: string; protected: bool;
|
||||
prefs: Prefs; multi=false): VNode =
|
||||
prefs: Prefs; path: string; multi=false): VNode =
|
||||
buildHtml(tdiv):
|
||||
if multi:
|
||||
tdiv(class="multi-header"):
|
||||
@@ -91,7 +92,7 @@ proc renderTimeline*(timeline: Timeline; username: string; protected: bool;
|
||||
elif timeline.content.len == 0:
|
||||
renderNoneFound()
|
||||
else:
|
||||
renderTweets(timeline, prefs)
|
||||
renderTweets(timeline, prefs, path)
|
||||
if timeline.hasMore or timeline.query.isSome:
|
||||
renderOlder(timeline, username)
|
||||
else:
|
||||
|
||||
@@ -50,7 +50,7 @@ proc isPlaybackEnabled(prefs: Prefs; video: Video): bool =
|
||||
of mp4: prefs.mp4Playback
|
||||
of m3u8, vmap: prefs.hlsPlayback
|
||||
|
||||
proc renderVideoDisabled(video: Video): VNode =
|
||||
proc renderVideoDisabled(video: Video; path: string): VNode =
|
||||
buildHtml(tdiv):
|
||||
img(src=video.thumb.getSigUrl("pic"))
|
||||
tdiv(class="video-overlay"):
|
||||
@@ -59,6 +59,7 @@ proc renderVideoDisabled(video: Video): VNode =
|
||||
p: text "mp4 playback disabled in preferences"
|
||||
of m3u8, vmap:
|
||||
form(`method`="post", action=("/enablehls")):
|
||||
verbatim "<input name=\"referer\" style=\"display: none\" value=\"$1\"/>" % path
|
||||
button(`type`="submit"):
|
||||
text "Enable hls playback"
|
||||
|
||||
@@ -72,7 +73,7 @@ proc renderVideoUnavailable(video: Video): VNode =
|
||||
else:
|
||||
p: text "This media is unavailable"
|
||||
|
||||
proc renderVideo(video: Video; prefs: Prefs): VNode =
|
||||
proc renderVideo(video: Video; prefs: Prefs; path: string): VNode =
|
||||
buildHtml(tdiv(class="attachments")):
|
||||
tdiv(class="gallery-video"):
|
||||
tdiv(class="attachment video-container"):
|
||||
@@ -80,7 +81,7 @@ proc renderVideo(video: Video; prefs: Prefs): VNode =
|
||||
if not video.available:
|
||||
renderVideoUnavailable(video)
|
||||
elif not prefs.isPlaybackEnabled(video):
|
||||
renderVideoDisabled(video)
|
||||
renderVideoDisabled(video, path)
|
||||
else:
|
||||
let source = video.url.getSigUrl("video")
|
||||
case video.playbackType
|
||||
@@ -137,7 +138,7 @@ proc renderCardContent(card: Card): VNode =
|
||||
p(class="card-description"): text card.text
|
||||
span(class="card-destination"): text card.dest
|
||||
|
||||
proc renderCard(card: Card; prefs: Prefs): VNode =
|
||||
proc renderCard(card: Card; prefs: Prefs; path: string): VNode =
|
||||
const largeCards = {summaryLarge, liveEvent, promoWebsite, promoVideo}
|
||||
let large = if card.kind in largeCards: " large" else: ""
|
||||
let url = replaceUrl(card.url, prefs)
|
||||
@@ -145,7 +146,7 @@ proc renderCard(card: Card; prefs: Prefs): VNode =
|
||||
buildHtml(tdiv(class=("card" & large))):
|
||||
if card.video.isSome:
|
||||
tdiv(class="card-container"):
|
||||
renderVideo(get(card.video), prefs)
|
||||
renderVideo(get(card.video), prefs, path)
|
||||
a(class="card-content-container", href=url):
|
||||
renderCardContent(card)
|
||||
else:
|
||||
@@ -215,7 +216,7 @@ proc renderQuote(quote: Quote; prefs: Prefs): VNode =
|
||||
a(class="show-thread", href=getLink(quote)):
|
||||
text "Show this thread"
|
||||
|
||||
proc renderTweet*(tweet: Tweet; prefs: Prefs; class="";
|
||||
proc renderTweet*(tweet: Tweet; prefs: Prefs; path: string; class="";
|
||||
index=0; total=(-1); last=false): VNode =
|
||||
var divClass = class
|
||||
if index == total or last:
|
||||
@@ -243,11 +244,11 @@ proc renderTweet*(tweet: Tweet; prefs: Prefs; class="";
|
||||
renderQuote(tweet.quote.get(), prefs)
|
||||
|
||||
if tweet.card.isSome:
|
||||
renderCard(tweet.card.get(), prefs)
|
||||
renderCard(tweet.card.get(), prefs, path)
|
||||
elif tweet.photos.len > 0:
|
||||
renderAlbum(tweet)
|
||||
elif tweet.video.isSome:
|
||||
renderVideo(tweet.video.get(), prefs)
|
||||
renderVideo(tweet.video.get(), prefs, path)
|
||||
views = tweet.video.get().views
|
||||
elif tweet.gif.isSome:
|
||||
renderGif(tweet.gif.get(), prefs)
|
||||
|
||||
Reference in New Issue
Block a user