mirror of
https://github.com/zedeus/nitter
synced 2026-11-22 21:07:19 +00:00
commit
6b437d5f87
44 changed files with 964 additions and 476 deletions
|
|
@ -65,8 +65,6 @@ Then enable and run the service:
|
|||
|
||||
## Todo (roughly in this order)
|
||||
|
||||
- Search (images/videos, hashtags, etc.)
|
||||
- Custom timeline filter
|
||||
- More caching (waiting for [moigagoo/norm#19](https://github.com/moigagoo/norm/pull/19))
|
||||
- Simple account system with customizable feed
|
||||
- Json API endpoints
|
||||
|
|
|
|||
BIN
screenshot.png
BIN
screenshot.png
Binary file not shown.
|
Before Width: | Height: | Size: 910 KiB After Width: | Height: | Size: 912 KiB |
|
|
@ -1,2 +1,2 @@
|
|||
import api/[media, profile, timeline, tweet, search]
|
||||
import api/[profile, timeline, tweet, search, media]
|
||||
export profile, timeline, tweet, search, media
|
||||
|
|
|
|||
|
|
@ -89,10 +89,10 @@ proc getVideoFetch(tweet: Tweet; agent, token: string) {.async.} =
|
|||
return
|
||||
|
||||
if tweet.card.isNone:
|
||||
tweet.video = some(parseVideo(json, tweet.id))
|
||||
tweet.video = some parseVideo(json, tweet.id)
|
||||
else:
|
||||
get(tweet.card).video = some(parseVideo(json, tweet.id))
|
||||
tweet.video = none(Video)
|
||||
get(tweet.card).video = some parseVideo(json, tweet.id)
|
||||
tweet.video = none Video
|
||||
tokenUses.inc
|
||||
|
||||
proc getVideoVar(tweet: Tweet): var Option[Video] =
|
||||
|
|
@ -104,7 +104,7 @@ proc getVideoVar(tweet: Tweet): var Option[Video] =
|
|||
proc getVideo*(tweet: Tweet; agent, token: string; force=false) {.async.} =
|
||||
withCustomDb("cache.db", "", "", ""):
|
||||
try:
|
||||
getVideoVar(tweet) = some(Video.getOne("videoId = ?", tweet.id))
|
||||
getVideoVar(tweet) = some Video.getOne("videoId = ?", tweet.id)
|
||||
except KeyError:
|
||||
await getVideoFetch(tweet, agent, token)
|
||||
var video = getVideoVar(tweet)
|
||||
|
|
@ -126,7 +126,7 @@ proc getPoll*(tweet: Tweet; agent: string) {.async.} =
|
|||
let html = await fetchHtml(url, headers)
|
||||
if html == nil: return
|
||||
|
||||
tweet.poll = some(parsePoll(html))
|
||||
tweet.poll = some parsePoll(html)
|
||||
|
||||
proc getCard*(tweet: Tweet; agent: string) {.async.} =
|
||||
if tweet.card.isNone(): return
|
||||
|
|
|
|||
|
|
@ -1,32 +1,56 @@
|
|||
import httpclient, asyncdispatch, htmlparser
|
||||
import sequtils, strutils, json, xmltree, uri
|
||||
import strutils, json, xmltree, uri
|
||||
|
||||
import ".."/[types, parser, parserutils, formatters, search]
|
||||
import utils, consts, media, timeline
|
||||
import ".."/[types, parser, parserutils, query]
|
||||
import utils, consts, timeline
|
||||
|
||||
proc getTimelineSearch*(query: Query; after, agent: string): Future[Timeline] {.async.} =
|
||||
let queryParam = genQueryParam(query)
|
||||
let queryEncoded = encodeUrl(queryParam, usePlus=false)
|
||||
proc getResult[T](json: JsonNode; query: Query; after: string): Result[T] =
|
||||
Result[T](
|
||||
hasMore: json["has_more_items"].to(bool),
|
||||
maxId: json.getOrDefault("max_position").getStr(""),
|
||||
minId: json.getOrDefault("min_position").getStr("").cleanPos(),
|
||||
query: query,
|
||||
beginning: after.len == 0
|
||||
)
|
||||
|
||||
let headers = newHttpHeaders({
|
||||
"Accept": jsonAccept,
|
||||
"Referer": $(base / ("search?f=tweets&vertical=default&q=$1&src=typd" % queryEncoded)),
|
||||
"User-Agent": agent,
|
||||
"X-Requested-With": "XMLHttpRequest",
|
||||
"Authority": "twitter.com",
|
||||
"Accept-Language": lang
|
||||
})
|
||||
proc getSearch*[T](query: Query; after, agent: string): Future[Result[T]] {.async.} =
|
||||
let
|
||||
kind = if query.kind == users: "users" else: "tweets"
|
||||
pos = when T is Tweet: genPos(after) else: after
|
||||
|
||||
let params = {
|
||||
"f": "tweets",
|
||||
"vertical": "default",
|
||||
"q": queryParam,
|
||||
"src": "typd",
|
||||
"include_available_features": "1",
|
||||
"include_entities": "1",
|
||||
"max_position": if after.len > 0: genPos(after) else: "0",
|
||||
"reset_error_state": "false"
|
||||
}
|
||||
param = genQueryParam(query)
|
||||
encoded = encodeUrl(param, usePlus=false)
|
||||
|
||||
headers = newHttpHeaders({
|
||||
"Accept": jsonAccept,
|
||||
"Referer": $(base / ("search?f=$1&q=$2&src=typd" % [kind, encoded])),
|
||||
"User-Agent": agent,
|
||||
"X-Requested-With": "XMLHttpRequest",
|
||||
"Authority": "twitter.com",
|
||||
"Accept-Language": lang
|
||||
})
|
||||
|
||||
params = {
|
||||
"f": kind,
|
||||
"vertical": "default",
|
||||
"q": param,
|
||||
"src": "typd",
|
||||
"include_available_features": "1",
|
||||
"include_entities": "1",
|
||||
"max_position": if pos.len > 0: pos else: "0",
|
||||
"reset_error_state": "false"
|
||||
}
|
||||
|
||||
let json = await fetchJson(base / searchUrl ? params, headers)
|
||||
result = await finishTimeline(json, some(query), after, agent)
|
||||
if json == nil: return Result[T](query: query, beginning: true)
|
||||
|
||||
result = getResult[T](json, query, after)
|
||||
if not json.hasKey("items_html"): return
|
||||
let html = parseHtml(json["items_html"].to(string))
|
||||
|
||||
when T is Tweet:
|
||||
result = await finishTimeline(json, query, after, agent)
|
||||
elif T is Profile:
|
||||
result.hasMore = json["items_html"].to(string) != "\n"
|
||||
for p in html.selectAll(".js-stream-item"):
|
||||
result.content.add parsePopupProfile(p, ".ProfileCard")
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
import httpclient, asyncdispatch, htmlparser
|
||||
import sequtils, strutils, json, xmltree, uri
|
||||
|
||||
import ".."/[types, parser, parserutils, formatters, search]
|
||||
import ".."/[types, parser, parserutils, formatters, query]
|
||||
import utils, consts, media
|
||||
|
||||
proc finishTimeline*(json: JsonNode; query: Option[Query]; after, agent: string): Future[Timeline] {.async.} =
|
||||
if json == nil: return Timeline()
|
||||
proc finishTimeline*(json: JsonNode; query: Query; after, agent: string): Future[Timeline] {.async.} =
|
||||
if json == nil: return Timeline(beginning: true, query: query)
|
||||
|
||||
result = Timeline(
|
||||
hasMore: json["has_more_items"].to(bool),
|
||||
|
|
@ -49,7 +49,7 @@ proc getTimeline*(username, after, agent: string): Future[Timeline] {.async.} =
|
|||
params.add {"max_position": after}
|
||||
|
||||
let json = await fetchJson(base / (timelineUrl % username) ? params, headers)
|
||||
result = await finishTimeline(json, none(Query), after, agent)
|
||||
result = await finishTimeline(json, Query(), after, agent)
|
||||
|
||||
proc getProfileAndTimeline*(username, agent, after: string): Future[(Profile, Timeline)] {.async.} =
|
||||
let headers = newHttpHeaders({
|
||||
|
|
|
|||
|
|
@ -29,9 +29,9 @@ proc hasCachedProfile*(username: string): Option[Profile] =
|
|||
try:
|
||||
let p = Profile.getOne("lower(username) = ?", toLower(username))
|
||||
doAssert not p.isOutdated
|
||||
result = some(p)
|
||||
result = some p
|
||||
except AssertionError, KeyError:
|
||||
result = none(Profile)
|
||||
result = none Profile
|
||||
|
||||
proc getCachedProfile*(username, agent: string; force=false): Future[Profile] {.async.} =
|
||||
withDb:
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import strutils, strformat, htmlgen, xmltree, times
|
||||
import strutils, strformat, sequtils, htmlgen, xmltree, times, uri
|
||||
import regex
|
||||
|
||||
import types, utils
|
||||
|
|
@ -8,9 +8,10 @@ from unicode import Rune, `$`
|
|||
const
|
||||
urlRegex = re"((https?|ftp)://(-\.)?([^\s/?\.#]+\.?)+([/\?][^\s\)]*)?)"
|
||||
emailRegex = re"([a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+)"
|
||||
usernameRegex = re"(^|[^A-z0-9_?])@([A-z0-9_]+)"
|
||||
usernameRegex = re"(^|[^A-z0-9_?\/])@([A-z0-9_]+)"
|
||||
picRegex = re"pic.twitter.com/[^ ]+"
|
||||
ellipsisRegex = re" ?…"
|
||||
hashtagRegex = re"([^\S])?([#$][A-z0-9]+)"
|
||||
ytRegex = re"(www.|m.)?youtu(be.com|.be)"
|
||||
twRegex = re"(www.|mobile.)?twitter.com"
|
||||
nbsp = $Rune(0x000A0)
|
||||
|
|
@ -40,6 +41,15 @@ proc reEmailToLink*(m: RegexMatch; s: string): string =
|
|||
let url = s[m.group(0)[0]]
|
||||
toLink("mailto://" & url, url)
|
||||
|
||||
proc reHashtagToLink*(m: RegexMatch; s: string): string =
|
||||
result = if m.group(0).len > 0: s[m.group(0)[0]] else: ""
|
||||
let hash = s[m.group(1)[0]]
|
||||
let link = toLink("/search?text=" & encodeUrl(hash), hash)
|
||||
if hash.any(isAlphaAscii):
|
||||
result &= link
|
||||
else:
|
||||
result &= hash
|
||||
|
||||
proc reUsernameToLink*(m: RegexMatch; s: string): string =
|
||||
var username = ""
|
||||
var pretext = ""
|
||||
|
|
@ -67,7 +77,7 @@ proc replaceUrl*(url: string; prefs: Prefs): string =
|
|||
|
||||
proc linkifyText*(text: string; prefs: Prefs; rss=false): string =
|
||||
result = xmltree.escape(stripText(text))
|
||||
result = result.replace(ellipsisRegex, "")
|
||||
result = result.replace(ellipsisRegex, " ")
|
||||
result = result.replace(emailRegex, reEmailToLink)
|
||||
if rss:
|
||||
result = result.replace(urlRegex, reUrlToLink)
|
||||
|
|
@ -75,6 +85,7 @@ proc linkifyText*(text: string; prefs: Prefs; rss=false): string =
|
|||
else:
|
||||
result = result.replace(urlRegex, reUrlToShortLink)
|
||||
result = result.replace(usernameRegex, reUsernameToLink)
|
||||
result = result.replace(hashtagRegex, reHashtagToLink)
|
||||
result = result.replace(re"([^\s\(\n%])<a", "$1 <a")
|
||||
result = result.replace(re"</a>\s+([;.,!\)'%]|')", "</a>$1")
|
||||
result = result.replace(re"^\. <a", ".<a")
|
||||
|
|
|
|||
|
|
@ -5,13 +5,14 @@ import jester
|
|||
|
||||
import types, config, prefs
|
||||
import views/[general, about]
|
||||
import routes/[preferences, timeline, media, rss]
|
||||
import routes/[preferences, timeline, media, search, rss]
|
||||
|
||||
const configPath {.strdefine.} = "./nitter.conf"
|
||||
let cfg = getConfig(configPath)
|
||||
|
||||
createPrefRouter(cfg)
|
||||
createTimelineRouter(cfg)
|
||||
createSearchRouter(cfg)
|
||||
createMediaRouter(cfg)
|
||||
createRssRouter(cfg)
|
||||
|
||||
|
|
@ -27,13 +28,9 @@ routes:
|
|||
get "/about":
|
||||
resp renderMain(renderAbout(), Prefs(), cfg.title)
|
||||
|
||||
post "/search":
|
||||
if @"query".len == 0:
|
||||
resp Http404, showError("Please enter a username.", cfg.title)
|
||||
redirect("/" & @"query")
|
||||
|
||||
extend preferences, ""
|
||||
extend rss, ""
|
||||
extend search, ""
|
||||
extend timeline, ""
|
||||
extend media, ""
|
||||
|
||||
|
|
|
|||
|
|
@ -23,14 +23,14 @@ proc parseTimelineProfile*(node: XmlNode): Profile =
|
|||
|
||||
result.getProfileStats(node.select(".ProfileNav-list"))
|
||||
|
||||
proc parsePopupProfile*(node: XmlNode): Profile =
|
||||
let profile = node.select(".profile-card")
|
||||
proc parsePopupProfile*(node: XmlNode; selector=".profile-card"): Profile =
|
||||
let profile = node.select(selector)
|
||||
if profile == nil: return
|
||||
|
||||
result = Profile(
|
||||
fullname: profile.getName(".fullname"),
|
||||
username: profile.getUsername(".username"),
|
||||
bio: profile.getBio(".bio"),
|
||||
bio: profile.getBio(".bio", fallback=".ProfileCard-bio"),
|
||||
userpic: profile.getAvatar(".ProfileCard-avatarImage"),
|
||||
verified: isVerified(profile),
|
||||
protected: isProtected(profile),
|
||||
|
|
@ -104,20 +104,20 @@ proc parseTweet*(node: XmlNode): Tweet =
|
|||
|
||||
let by = tweet.selectText(".js-retweet-text > a > b")
|
||||
if by.len > 0:
|
||||
result.retweet = some(Retweet(
|
||||
result.retweet = some Retweet(
|
||||
by: stripText(by),
|
||||
id: tweet.attr("data-retweet-id")
|
||||
))
|
||||
)
|
||||
|
||||
let quote = tweet.select(".QuoteTweet-innerContainer")
|
||||
if quote != nil:
|
||||
result.quote = some(parseQuote(quote))
|
||||
result.quote = some parseQuote(quote)
|
||||
|
||||
let tombstone = tweet.select(".Tombstone")
|
||||
if tombstone != nil:
|
||||
if "unavailable" in tombstone.innerText():
|
||||
let quote = Quote(tombstone: getTombstone(node.selectText(".Tombstone-label")))
|
||||
result.quote = some(quote)
|
||||
result.quote = some quote
|
||||
|
||||
proc parseThread*(nodes: XmlNode): Thread =
|
||||
if nodes == nil: return
|
||||
|
|
@ -157,7 +157,7 @@ proc parseConversation*(node: XmlNode): Conversation =
|
|||
result.replies.add parseThread(thread)
|
||||
|
||||
proc parseTimeline*(node: XmlNode; after: string): Timeline =
|
||||
if node == nil: return
|
||||
if node == nil: return Timeline()
|
||||
result = Timeline(
|
||||
content: parseThread(node.select(".stream > .stream-items")).content,
|
||||
minId: node.attr("data-min-position"),
|
||||
|
|
@ -234,7 +234,7 @@ proc parseCard*(card: var Card; node: XmlNode) =
|
|||
let image = node.select(".tcu-imageWrapper img")
|
||||
if image != nil:
|
||||
# workaround for issue 11713
|
||||
card.image = some(image.attr("data-src").replace("gname", "g&name"))
|
||||
card.image = some image.attr("data-src").replace("gname", "g&name")
|
||||
|
||||
if card.kind == liveEvent:
|
||||
card.text = card.title
|
||||
|
|
|
|||
|
|
@ -86,8 +86,11 @@ proc getName*(profile: XmlNode; selector: string): string =
|
|||
proc getUsername*(profile: XmlNode; selector: string): string =
|
||||
profile.selectText(selector).strip(chars={'@', ' ', '\n'})
|
||||
|
||||
proc getBio*(profile: XmlNode; selector: string): string =
|
||||
profile.selectText(selector).stripText()
|
||||
proc getBio*(profile: XmlNode; selector: string; fallback=""): string =
|
||||
var bio = profile.selectText(selector)
|
||||
if bio.len == 0 and fallback.len > 0:
|
||||
bio = profile.selectText(fallback)
|
||||
stripText(bio)
|
||||
|
||||
proc getAvatar*(profile: XmlNode; selector: string): string =
|
||||
profile.selectAttr(selector, "src").getUserpic()
|
||||
|
|
@ -177,9 +180,9 @@ proc getTweetMedia*(tweet: Tweet; node: XmlNode) =
|
|||
if player == nil: return
|
||||
|
||||
if "gif" in player.attr("class"):
|
||||
tweet.gif = some(getGif(player.select(".PlayableMedia-player")))
|
||||
tweet.gif = some getGif(player.select(".PlayableMedia-player"))
|
||||
elif "video" in player.attr("class"):
|
||||
tweet.video = some(Video())
|
||||
tweet.video = some Video()
|
||||
|
||||
proc getQuoteMedia*(quote: var Quote; node: XmlNode) =
|
||||
if node.select(".QuoteTweet--sensitive") != nil:
|
||||
|
|
@ -206,7 +209,7 @@ proc getTweetCard*(tweet: Tweet; node: XmlNode) =
|
|||
cardType = cardType.split(":")[^1]
|
||||
|
||||
if "poll" in cardType:
|
||||
tweet.poll = some(Poll())
|
||||
tweet.poll = some Poll()
|
||||
return
|
||||
|
||||
let cardDiv = node.select(".card2 > .js-macaw-cards-iframe-container")
|
||||
|
|
@ -227,7 +230,7 @@ proc getTweetCard*(tweet: Tweet; node: XmlNode) =
|
|||
if n.attr("href") == cardUrl:
|
||||
card.url = n.attr("data-expanded-url")
|
||||
|
||||
tweet.card = some(card)
|
||||
tweet.card = some card
|
||||
|
||||
proc getMoreReplies*(node: XmlNode): int =
|
||||
let text = node.innerText().strip()
|
||||
|
|
|
|||
127
src/query.nim
Normal file
127
src/query.nim
Normal file
|
|
@ -0,0 +1,127 @@
|
|||
import strutils, strformat, sequtils, tables, uri
|
||||
|
||||
import types
|
||||
|
||||
const
|
||||
separators = @["AND", "OR"]
|
||||
validFilters* = @[
|
||||
"media", "images", "twimg", "videos",
|
||||
"native_video", "consumer_video", "pro_video",
|
||||
"links", "news", "quote", "mentions",
|
||||
"replies", "retweets", "nativeretweets",
|
||||
"verified", "safe"
|
||||
]
|
||||
|
||||
# Experimental, this might break in the future
|
||||
# Till then, it results in shorter urls
|
||||
const
|
||||
posPrefix = "thGAVUV0VFVB"
|
||||
posSuffix = "EjUAFQAlAFUAFQAA"
|
||||
|
||||
template `@`(param: string): untyped =
|
||||
if param in pms: pms[param]
|
||||
else: ""
|
||||
|
||||
proc initQuery*(pms: Table[string, string]; name=""): Query =
|
||||
result = Query(
|
||||
kind: parseEnum[QueryKind](@"kind", custom),
|
||||
text: @"text",
|
||||
filters: validFilters.filterIt("f-" & it in pms),
|
||||
excludes: validFilters.filterIt("e-" & it in pms),
|
||||
since: @"since",
|
||||
until: @"until",
|
||||
near: @"near"
|
||||
)
|
||||
|
||||
if name.len > 0:
|
||||
result.fromUser = name.split(",")
|
||||
|
||||
if @"e-nativeretweets".len == 0:
|
||||
result.includes.add "nativeretweets"
|
||||
|
||||
proc getMediaQuery*(name: string): Query =
|
||||
Query(
|
||||
kind: media,
|
||||
filters: @["twimg", "native_video"],
|
||||
fromUser: @[name],
|
||||
sep: "OR"
|
||||
)
|
||||
|
||||
proc getReplyQuery*(name: string): Query =
|
||||
Query(
|
||||
kind: replies,
|
||||
includes: @["nativeretweets"],
|
||||
fromUser: @[name]
|
||||
)
|
||||
|
||||
proc genQueryParam*(query: Query): string =
|
||||
var filters: seq[string]
|
||||
var param: string
|
||||
|
||||
if query.kind == users:
|
||||
return query.text
|
||||
|
||||
for i, user in query.fromUser:
|
||||
param &= &"from:{user} "
|
||||
if i < query.fromUser.high:
|
||||
param &= "OR "
|
||||
|
||||
for f in query.filters:
|
||||
filters.add "filter:" & f
|
||||
for e in query.excludes:
|
||||
filters.add "-filter:" & e
|
||||
for i in query.includes:
|
||||
filters.add "include:" & i
|
||||
|
||||
result = strip(param & filters.join(&" {query.sep} "))
|
||||
if query.since.len > 0:
|
||||
result &= " since:" & query.since
|
||||
if query.until.len > 0:
|
||||
result &= " until:" & query.until
|
||||
if query.near.len > 0:
|
||||
result &= &" near:\"{query.near}\" within:15mi"
|
||||
if query.text.len > 0:
|
||||
result &= " " & query.text
|
||||
|
||||
proc genQueryUrl*(query: Query; onlyParam=false): string =
|
||||
if query.fromUser.len > 0:
|
||||
result = "/" & query.fromUser.join(",")
|
||||
|
||||
if query.fromUser.len > 1 and query.kind == posts:
|
||||
return result & "?"
|
||||
|
||||
if query.kind notin {custom, users}:
|
||||
return result & &"/{query.kind}?"
|
||||
|
||||
if onlyParam:
|
||||
result = ""
|
||||
else:
|
||||
result &= &"/search?"
|
||||
|
||||
var params = @[&"kind={query.kind}"]
|
||||
if query.text.len > 0:
|
||||
params.add "text=" & encodeUrl(query.text)
|
||||
for f in query.filters:
|
||||
params.add "f-" & f & "=on"
|
||||
for e in query.excludes:
|
||||
params.add "e-" & e & "=on"
|
||||
for i in query.includes:
|
||||
params.add "i-" & i & "=on"
|
||||
|
||||
if query.since.len > 0:
|
||||
params.add "since=" & query.since
|
||||
if query.until.len > 0:
|
||||
params.add "until=" & query.until
|
||||
if query.near.len > 0:
|
||||
params.add "near=" & query.near
|
||||
|
||||
if params.len > 0:
|
||||
result &= params.join("&")
|
||||
|
||||
proc cleanPos*(pos: string): string =
|
||||
pos.multiReplace((posPrefix, ""), (posSuffix, ""))
|
||||
|
||||
proc genPos*(pos: string): string =
|
||||
result = posPrefix & pos
|
||||
if "A==" notin result:
|
||||
result &= posSuffix
|
||||
|
|
@ -3,12 +3,12 @@ import asyncdispatch, strutils
|
|||
import jester
|
||||
|
||||
import router_utils, timeline
|
||||
import ".."/[cache, agents, search]
|
||||
import ".."/[cache, agents, query]
|
||||
import ../views/general
|
||||
|
||||
include "../views/rss.nimf"
|
||||
|
||||
proc showRss*(name: string; query: Option[Query]): Future[string] {.async.} =
|
||||
proc showRss*(name: string; query: Query): Future[string] {.async.} =
|
||||
let (profile, timeline, _) = await fetchSingleTimeline(name, "", getAgent(), query)
|
||||
return renderTimelineRss(timeline.content, profile)
|
||||
|
||||
|
|
@ -21,12 +21,16 @@ proc createRssRouter*(cfg: Config) =
|
|||
router rss:
|
||||
get "/@name/rss":
|
||||
cond '.' notin @"name"
|
||||
respRss(await showRss(@"name", none(Query)))
|
||||
respRss(await showRss(@"name", Query()))
|
||||
|
||||
get "/@name/replies/rss":
|
||||
cond '.' notin @"name"
|
||||
respRss(await showRss(@"name", some(getReplyQuery(@"name"))))
|
||||
respRss(await showRss(@"name", getReplyQuery(@"name")))
|
||||
|
||||
get "/@name/media/rss":
|
||||
cond '.' notin @"name"
|
||||
respRss(await showRss(@"name", some(getMediaQuery(@"name"))))
|
||||
respRss(await showRss(@"name", getMediaQuery(@"name")))
|
||||
|
||||
get "/@name/search/rss":
|
||||
cond '.' notin @"name"
|
||||
respRss(await showRss(@"name", initQuery(params(request), name=(@"name"))))
|
||||
|
|
|
|||
30
src/routes/search.nim
Normal file
30
src/routes/search.nim
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
import strutils, sequtils, uri
|
||||
|
||||
import jester
|
||||
|
||||
import router_utils
|
||||
import ".."/[query, types, utils, api, agents, prefs]
|
||||
import ../views/[general, search]
|
||||
|
||||
export search
|
||||
|
||||
proc createSearchRouter*(cfg: Config) =
|
||||
router search:
|
||||
get "/search":
|
||||
if @"text".len > 200:
|
||||
resp Http400, showError("Search input too long.", cfg.title)
|
||||
|
||||
let prefs = cookiePrefs()
|
||||
let query = initQuery(params(request))
|
||||
|
||||
case query.kind
|
||||
of users:
|
||||
if "," in @"text":
|
||||
redirect("/" & @"text")
|
||||
let users = await getSearch[Profile](query, @"after", getAgent())
|
||||
resp renderMain(renderUserSearch(users, prefs), prefs, cfg.title, path=getPath())
|
||||
of custom:
|
||||
let tweets = await getSearch[Tweet](query, @"after", getAgent())
|
||||
resp renderMain(renderTweetSearch(tweets, prefs, getPath()), prefs, cfg.title, path=getPath())
|
||||
else:
|
||||
resp Http404, showError("Invalid search.", cfg.title)
|
||||
|
|
@ -3,20 +3,20 @@ import asyncdispatch, strutils, sequtils, uri
|
|||
import jester
|
||||
|
||||
import router_utils
|
||||
import ".."/[api, prefs, types, utils, cache, formatters, agents, search]
|
||||
import ../views/[general, profile, timeline, status]
|
||||
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, search, agents
|
||||
export api, cache, formatters, query, agents
|
||||
export profile, timeline, status
|
||||
|
||||
type ProfileTimeline = (Profile, Timeline, seq[GalleryPhoto])
|
||||
|
||||
proc fetchSingleTimeline*(name, after, agent: string;
|
||||
query: Option[Query]): Future[ProfileTimeline] {.async.} =
|
||||
query: Query): Future[ProfileTimeline] {.async.} =
|
||||
let railFut = getPhotoRail(name, agent)
|
||||
|
||||
var timeline: Timeline
|
||||
|
|
@ -26,14 +26,14 @@ proc fetchSingleTimeline*(name, after, agent: string;
|
|||
if cachedProfile.isSome:
|
||||
profile = get(cachedProfile)
|
||||
|
||||
if query.isNone:
|
||||
if query.kind == posts:
|
||||
if cachedProfile.isSome:
|
||||
timeline = await getTimeline(name, after, agent)
|
||||
else:
|
||||
(profile, timeline) = await getProfileAndTimeline(name, agent, after)
|
||||
cache(profile)
|
||||
else:
|
||||
var timelineFut = getTimelineSearch(get(query), after, agent)
|
||||
var timelineFut = getSearch[Tweet](query, after, agent)
|
||||
if cachedProfile.isNone:
|
||||
profile = await getCachedProfile(name, agent)
|
||||
timeline = await timelineFut
|
||||
|
|
@ -42,16 +42,14 @@ proc fetchSingleTimeline*(name, after, agent: string;
|
|||
return (profile, timeline, await railFut)
|
||||
|
||||
proc fetchMultiTimeline*(names: seq[string]; after, agent: string;
|
||||
query: Option[Query]): Future[Timeline] {.async.} =
|
||||
query: Query): Future[Timeline] {.async.} =
|
||||
var q = query
|
||||
if q.isSome:
|
||||
get(q).fromUser = names
|
||||
else:
|
||||
q = some(Query(kind: multi, fromUser: names, excludes: @["replies"]))
|
||||
q.fromUser = names
|
||||
if q.kind == posts and "replies" notin q.excludes:
|
||||
q.excludes.add "replies"
|
||||
return await getSearch[Tweet](q, after, agent)
|
||||
|
||||
return await getTimelineSearch(get(q), after, agent)
|
||||
|
||||
proc showTimeline*(name, after: string; query: Option[Query];
|
||||
proc showTimeline*(name, after: string; query: Query;
|
||||
prefs: Prefs; path, title, rss: string): Future[string] {.async.} =
|
||||
let agent = getAgent()
|
||||
let names = name.strip(chars={'/'}).split(",").filterIt(it.len > 0)
|
||||
|
|
@ -64,7 +62,7 @@ proc showTimeline*(name, after: string; query: Option[Query];
|
|||
else:
|
||||
let
|
||||
timeline = await fetchMultiTimeline(names, after, agent, query)
|
||||
html = renderMulti(timeline, names.join(","), prefs, path)
|
||||
html = renderTweetSearch(timeline, prefs, path)
|
||||
return renderMain(html, prefs, title, "Multi")
|
||||
|
||||
template respTimeline*(timeline: typed) =
|
||||
|
|
@ -79,27 +77,28 @@ proc createTimelineRouter*(cfg: Config) =
|
|||
get "/@name/?":
|
||||
cond '.' notin @"name"
|
||||
let rss = "/$1/rss" % @"name"
|
||||
respTimeline(await showTimeline(@"name", @"after", none(Query), cookiePrefs(),
|
||||
respTimeline(await showTimeline(@"name", @"after", Query(), cookiePrefs(),
|
||||
getPath(), cfg.title, rss))
|
||||
|
||||
get "/@name/search":
|
||||
cond '.' notin @"name"
|
||||
let query = initQuery(@"filter", @"include", @"not", @"sep", @"name")
|
||||
respTimeline(await showTimeline(@"name", @"after", some(query),
|
||||
cookiePrefs(), getPath(), cfg.title, ""))
|
||||
|
||||
get "/@name/replies":
|
||||
cond '.' notin @"name"
|
||||
let rss = "/$1/replies/rss" % @"name"
|
||||
respTimeline(await showTimeline(@"name", @"after", some(getReplyQuery(@"name")),
|
||||
respTimeline(await showTimeline(@"name", @"after", getReplyQuery(@"name"),
|
||||
cookiePrefs(), getPath(), cfg.title, rss))
|
||||
|
||||
get "/@name/media":
|
||||
cond '.' notin @"name"
|
||||
let rss = "/$1/media/rss" % @"name"
|
||||
respTimeline(await showTimeline(@"name", @"after", some(getMediaQuery(@"name")),
|
||||
respTimeline(await showTimeline(@"name", @"after", getMediaQuery(@"name"),
|
||||
cookiePrefs(), getPath(), cfg.title, rss))
|
||||
|
||||
get "/@name/search":
|
||||
cond '.' notin @"name"
|
||||
let query = initQuery(params(request), name=(@"name"))
|
||||
let rss = "/$1/search/rss?$2" % [@"name", genQueryUrl(query, onlyParam=true)]
|
||||
respTimeline(await showTimeline(@"name", @"after", query, cookiePrefs(),
|
||||
getPath(), cfg.title, rss))
|
||||
|
||||
get "/@name/status/@id":
|
||||
cond '.' notin @"name"
|
||||
let prefs = cookiePrefs()
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
@include center-panel($error_red);
|
||||
}
|
||||
|
||||
.search-panel > form {
|
||||
.search-bar > form {
|
||||
@include center-panel($darkest-grey);
|
||||
|
||||
button {
|
||||
|
|
|
|||
|
|
@ -58,3 +58,40 @@
|
|||
border-color: $accent_light;
|
||||
}
|
||||
}
|
||||
|
||||
@mixin search-resize($width, $rows) {
|
||||
@media(max-width: $width) {
|
||||
.search-toggles {
|
||||
grid-template-columns: repeat($rows, auto);
|
||||
}
|
||||
|
||||
#search-panel-toggle:checked ~ .search-panel {
|
||||
@if $rows == 6 {
|
||||
max-height: 200px !important;
|
||||
}
|
||||
@if $rows == 5 {
|
||||
max-height: 300px !important;
|
||||
}
|
||||
@if $rows == 4 {
|
||||
max-height: 300px !important;
|
||||
}
|
||||
@if $rows == 3 {
|
||||
max-height: 365px !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@mixin create-toggle($elem, $height) {
|
||||
##{$elem}-toggle {
|
||||
display: none;
|
||||
|
||||
&:checked ~ .#{$elem} {
|
||||
max-height: $height;
|
||||
}
|
||||
|
||||
&:checked ~ label .icon-down:before {
|
||||
transform: rotate(180deg) translateY(-1px);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
@import 'navbar';
|
||||
@import 'inputs';
|
||||
@import 'timeline';
|
||||
@import 'search';
|
||||
|
||||
body {
|
||||
background-color: $bg_color;
|
||||
|
|
@ -68,9 +69,6 @@ ul.about-list {
|
|||
.container {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
#content {
|
||||
box-sizing: border-box;
|
||||
padding-top: 50px;
|
||||
margin: auto;
|
||||
|
|
|
|||
|
|
@ -12,7 +12,8 @@ button {
|
|||
float: right;
|
||||
}
|
||||
|
||||
input[type="text"] {
|
||||
input[type="text"],
|
||||
input[type="date"] {
|
||||
@include input-colors;
|
||||
background-color: $bg_elements;
|
||||
padding: 1px 4px;
|
||||
|
|
@ -22,9 +23,50 @@ input[type="text"] {
|
|||
font-size: 14px;
|
||||
}
|
||||
|
||||
input[type="date"]::-webkit-inner-spin-button {
|
||||
display: none;
|
||||
}
|
||||
|
||||
input[type="date"]::-webkit-clear-button {
|
||||
margin-left: 17px;
|
||||
filter: grayscale(100%);
|
||||
filter: hue-rotate(120deg);
|
||||
}
|
||||
|
||||
input::-webkit-calendar-picker-indicator {
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
input::-webkit-datetime-edit-day-field:focus,
|
||||
input::-webkit-datetime-edit-month-field:focus,
|
||||
input::-webkit-datetime-edit-year-field:focus {
|
||||
background-color: $accent;
|
||||
color: $fg_color;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.date-range {
|
||||
.date-input {
|
||||
display: inline-block;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.icon-container {
|
||||
pointer-events: none;
|
||||
position: absolute;
|
||||
top: 2px;
|
||||
right: 5px;
|
||||
}
|
||||
|
||||
.search-title {
|
||||
margin: 0 2px;
|
||||
}
|
||||
}
|
||||
|
||||
.icon-button button {
|
||||
color: $accent;
|
||||
text-decoration: none;
|
||||
background: none;
|
||||
border: none;
|
||||
float: none;
|
||||
padding: unset;
|
||||
|
|
@ -88,6 +130,10 @@ input[type="text"] {
|
|||
}
|
||||
}
|
||||
|
||||
.pref-group {
|
||||
display: inline;
|
||||
}
|
||||
|
||||
.preferences {
|
||||
button {
|
||||
margin: 6px 0 3px 0;
|
||||
|
|
@ -103,6 +149,10 @@ input[type="text"] {
|
|||
max-width: 120px;
|
||||
}
|
||||
|
||||
.pref-group {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.pref-input {
|
||||
position: relative;
|
||||
margin-bottom: 6px;
|
||||
|
|
|
|||
|
|
@ -1,27 +1,25 @@
|
|||
@import '_variables';
|
||||
|
||||
nav {
|
||||
z-index: 1000;
|
||||
background-color: $bg_overlays;
|
||||
box-shadow: 0 0 4px $shadow;
|
||||
}
|
||||
|
||||
.nav-bar {
|
||||
padding: 0;
|
||||
width: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
position: fixed;
|
||||
background-color: $bg_overlays;
|
||||
box-shadow: 0 0 4px $shadow;
|
||||
padding: 0;
|
||||
width: 100%;
|
||||
height: 50px;
|
||||
z-index: 1000;
|
||||
}
|
||||
|
||||
.inner-nav {
|
||||
margin: auto;
|
||||
box-sizing: border-box;
|
||||
padding: 0 10px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-basis: 920px;
|
||||
height: 50px;
|
||||
}
|
||||
.inner-nav {
|
||||
margin: auto;
|
||||
box-sizing: border-box;
|
||||
padding: 0 10px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-basis: 920px;
|
||||
height: 50px;
|
||||
}
|
||||
|
||||
.site-name {
|
||||
|
|
@ -39,7 +37,7 @@ nav {
|
|||
height: 35px;
|
||||
}
|
||||
|
||||
.item {
|
||||
.nav-item {
|
||||
display: flex;
|
||||
flex: 1;
|
||||
line-height: 50px;
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue