Support rss for custom search

This commit is contained in:
Zed 2019-09-20 03:35:27 +02:00
parent bd4895f6fd
commit df3001ae95
3 changed files with 19 additions and 11 deletions

View File

@ -68,10 +68,10 @@ proc genQueryParam*(query: Query): string =
for f in query.filters: for f in query.filters:
filters.add "filter:" & f filters.add "filter:" & f
for i in query.includes:
filters.add "include:" & i
for e in query.excludes: for e in query.excludes:
filters.add "-filter:" & e filters.add "-filter:" & e
for i in query.includes:
filters.add "include:" & i
result = strip(param & filters.join(&" {query.sep} ")) result = strip(param & filters.join(&" {query.sep} "))
if query.since.len > 0: if query.since.len > 0:
@ -83,7 +83,7 @@ proc genQueryParam*(query: Query): string =
if query.text.len > 0: if query.text.len > 0:
result &= " " & query.text result &= " " & query.text
proc genQueryUrl*(query: Query): string = proc genQueryUrl*(query: Query; onlyParam=false): string =
if query.fromUser.len > 0: if query.fromUser.len > 0:
result = "/" & query.fromUser.join(",") result = "/" & query.fromUser.join(",")
@ -93,7 +93,10 @@ proc genQueryUrl*(query: Query): string =
if query.kind notin {custom, users}: if query.kind notin {custom, users}:
return result & &"/{query.kind}?" return result & &"/{query.kind}?"
result &= &"/search?" if onlyParam:
result = ""
else:
result &= &"/search?"
var params = @[&"kind={query.kind}"] var params = @[&"kind={query.kind}"]
if query.text.len > 0: if query.text.len > 0:
@ -102,7 +105,7 @@ proc genQueryUrl*(query: Query): string =
params.add "f-" & f & "=on" params.add "f-" & f & "=on"
for e in query.excludes: for e in query.excludes:
params.add "e-" & e & "=on" params.add "e-" & e & "=on"
for i in query.excludes: for i in query.includes:
params.add "i-" & i & "=on" params.add "i-" & i & "=on"
if query.since.len > 0: if query.since.len > 0:

View File

@ -30,3 +30,7 @@ proc createRssRouter*(cfg: Config) =
get "/@name/media/rss": get "/@name/media/rss":
cond '.' notin @"name" cond '.' notin @"name"
respRss(await showRss(@"name", getMediaQuery(@"name"))) respRss(await showRss(@"name", getMediaQuery(@"name")))
get "/@name/search/rss":
cond '.' notin @"name"
respRss(await showRss(@"name", initQuery(params(request), name=(@"name"))))

View File

@ -80,12 +80,6 @@ proc createTimelineRouter*(cfg: Config) =
respTimeline(await showTimeline(@"name", @"after", Query(), cookiePrefs(), respTimeline(await showTimeline(@"name", @"after", Query(), cookiePrefs(),
getPath(), cfg.title, rss)) getPath(), cfg.title, rss))
get "/@name/search":
cond '.' notin @"name"
let query = initQuery(params(request), name=(@"name"))
respTimeline(await showTimeline(@"name", @"after", query, cookiePrefs(),
getPath(), cfg.title, ""))
get "/@name/replies": get "/@name/replies":
cond '.' notin @"name" cond '.' notin @"name"
let rss = "/$1/replies/rss" % @"name" let rss = "/$1/replies/rss" % @"name"
@ -98,6 +92,13 @@ proc createTimelineRouter*(cfg: Config) =
respTimeline(await showTimeline(@"name", @"after", getMediaQuery(@"name"), respTimeline(await showTimeline(@"name", @"after", getMediaQuery(@"name"),
cookiePrefs(), getPath(), cfg.title, rss)) 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": get "/@name/status/@id":
cond '.' notin @"name" cond '.' notin @"name"
let prefs = cookiePrefs() let prefs = cookiePrefs()