Refactoring
This commit is contained in:
parent
ffce6e21ab
commit
5979d7f588
|
@ -4,7 +4,7 @@ import sequtils, strutils, json, uri
|
|||
import ".."/[types, parser, parserutils, query]
|
||||
import utils, consts, timeline, search
|
||||
|
||||
proc getListTimeline*(username, list, agent, after: string; media=true): Future[Timeline] {.async.} =
|
||||
proc getListTimeline*(username, list, after, agent: string; media=true): Future[Timeline] {.async.} =
|
||||
let url = base / (listUrl % [username, list])
|
||||
|
||||
var params = toSeq({
|
||||
|
@ -23,20 +23,7 @@ proc getListTimeline*(username, list, agent, after: string; media=true): Future[
|
|||
|
||||
result.minId = getLastId(result)
|
||||
|
||||
proc getListMembers*(username, list, agent: string): Future[Result[Profile]] {.async.} =
|
||||
let
|
||||
url = base / (listMembersUrl % [username, list])
|
||||
html = await fetchHtml(url, genHeaders(agent, url))
|
||||
|
||||
result = Result[Profile](
|
||||
minId: html.selectAttr(".stream-container", "data-min-position"),
|
||||
hasMore: html.select(".has-more-items") != nil,
|
||||
beginning: true,
|
||||
query: Query(kind: userList),
|
||||
content: html.selectAll(".account").map(parseListProfile)
|
||||
)
|
||||
|
||||
proc getListMembersSearch*(username, list, agent, after: string): Future[Result[Profile]] {.async.} =
|
||||
proc getListMembersSearch(username, list, after, agent: string): Future[Result[Profile]] {.async.} =
|
||||
let
|
||||
referer = base / (listMembersUrl % [username, list])
|
||||
url = referer / "timeline"
|
||||
|
@ -60,3 +47,19 @@ proc getListMembersSearch*(username, list, agent, after: string): Future[Result[
|
|||
result.hasMore = html != "\n"
|
||||
for p in parseHtml(html).selectAll(".account"):
|
||||
result.content.add parseListProfile(p)
|
||||
|
||||
proc getListMembers*(username, list, after, agent: string): Future[Result[Profile]] {.async.} =
|
||||
if after.len > 0:
|
||||
return await getListMembersSearch(username, list, after, agent)
|
||||
|
||||
let
|
||||
url = base / (listMembersUrl % [username, list])
|
||||
html = await fetchHtml(url, genHeaders(agent, url))
|
||||
|
||||
result = Result[Profile](
|
||||
minId: html.selectAttr(".stream-container", "data-min-position"),
|
||||
hasMore: html.select(".has-more-items") != nil,
|
||||
beginning: true,
|
||||
query: Query(kind: userList),
|
||||
content: html.selectAll(".account").map(parseListProfile)
|
||||
)
|
||||
|
|
|
@ -23,7 +23,7 @@ proc finishTimeline*(json: JsonNode; query: Query; after, agent: string;
|
|||
if media: await getMedia(timeline, agent)
|
||||
result.content = timeline.content
|
||||
|
||||
proc getProfileAndTimeline*(username, agent, after: string; media=true): Future[(Profile, Timeline)] {.async.} =
|
||||
proc getProfileAndTimeline*(username, after, agent: string; media=true): Future[(Profile, Timeline)] {.async.} =
|
||||
var url = base / username
|
||||
if after.len > 0:
|
||||
url = url ? {"max_position": after}
|
||||
|
@ -54,7 +54,6 @@ proc getTimeline*(username, after, agent: string; media=true): Future[Timeline]
|
|||
result = await finishTimeline(json, Query(), after, agent, media)
|
||||
|
||||
proc getMediaTimeline*(username, after, agent: string; media=true): Future[Timeline] {.async.} =
|
||||
echo "mediaTimeline"
|
||||
var params = toSeq({
|
||||
"include_available_features": "1",
|
||||
"include_entities": "1",
|
||||
|
|
|
@ -18,17 +18,13 @@ proc createListRouter*(cfg: Config) =
|
|||
get "/@name/lists/@list":
|
||||
cond '.' notin @"name"
|
||||
let
|
||||
list = await getListTimeline(@"name", @"list", getAgent(), @"max_position")
|
||||
list = await getListTimeline(@"name", @"list", @"max_position", getAgent())
|
||||
tweets = renderTimelineTweets(list, cookiePrefs(), request.path)
|
||||
respList list, tweets
|
||||
|
||||
get "/@name/lists/@list/members":
|
||||
cond '.' notin @"name"
|
||||
let list =
|
||||
if @"max_position".len == 0:
|
||||
await getListMembers(@"name", @"list", getAgent())
|
||||
else:
|
||||
await getListMembersSearch(@"name", @"list", getAgent(), @"max_position")
|
||||
|
||||
let users = renderTimelineUsers(list, cookiePrefs(), request.path)
|
||||
let
|
||||
list = await getListMembers(@"name", @"list", @"max_position", getAgent())
|
||||
users = renderTimelineUsers(list, cookiePrefs(), request.path)
|
||||
respList list, users
|
||||
|
|
|
@ -51,5 +51,5 @@ proc createRssRouter*(cfg: Config) =
|
|||
|
||||
get "/@name/lists/@list/rss":
|
||||
cond '.' notin @"name"
|
||||
let list = await getListTimeline(@"name", @"list", getAgent(), "", media=false)
|
||||
let list = await getListTimeline(@"name", @"list", "", getAgent(), media=false)
|
||||
respRss(renderListRss(list.content, @"name", @"list", cfg.hostname))
|
||||
|
|
|
@ -24,7 +24,7 @@ proc fetchSingleTimeline*(name, after, agent: string; query: Query;
|
|||
if cachedProfile.isSome:
|
||||
timeline = await getTimeline(name, after, agent, media)
|
||||
else:
|
||||
(profile, timeline) = await getProfileAndTimeline(name, agent, after, media)
|
||||
(profile, timeline) = await getProfileAndTimeline(name, after, agent, media)
|
||||
cache(profile)
|
||||
else:
|
||||
var timelineFut =
|
||||
|
@ -59,21 +59,21 @@ proc showTimeline*(request: Request; query: Query; cfg: Config; rss: string): Fu
|
|||
after = request.get("max_position")
|
||||
names = name.strip(chars={'/'}).split(",").filterIt(it.len > 0)
|
||||
|
||||
if names.len == 1:
|
||||
let
|
||||
rail = getPhotoRail(names[0], agent, skip=(query.kind == media))
|
||||
(p, t) = await fetchSingleTimeline(names[0], after, agent, query)
|
||||
r = await rail
|
||||
if p.username.len == 0: return
|
||||
let pHtml = renderProfile(p, t, r, prefs, getPath())
|
||||
return renderMain(pHtml, request, cfg, pageTitle(p), pageDesc(p),
|
||||
rss=rss, images = @[p.getUserpic("_200x200")])
|
||||
else:
|
||||
if names.len != 1:
|
||||
let
|
||||
timeline = await fetchMultiTimeline(names, after, agent, query)
|
||||
html = renderTweetSearch(timeline, prefs, getPath())
|
||||
return renderMain(html, request, cfg, "Multi")
|
||||
|
||||
let
|
||||
rail = getPhotoRail(names[0], agent, skip=(query.kind == media))
|
||||
(p, t) = await fetchSingleTimeline(names[0], after, agent, query)
|
||||
r = await rail
|
||||
if p.username.len == 0: return
|
||||
let pHtml = renderProfile(p, t, r, prefs, getPath())
|
||||
return renderMain(pHtml, request, cfg, pageTitle(p), pageDesc(p),
|
||||
rss=rss, images = @[p.getUserpic("_200x200")])
|
||||
|
||||
template respTimeline*(timeline: typed) =
|
||||
if timeline.len == 0:
|
||||
resp Http404, showError("User \"" & @"name" & "\" not found", cfg)
|
||||
|
|
Loading…
Reference in New Issue