Style fixes

This commit is contained in:
Zed 2022-01-06 03:57:14 +01:00
parent f5ba2b62e7
commit ffcac982d0
9 changed files with 33 additions and 31 deletions

View File

@ -9,7 +9,7 @@ const
var pool: HttpPool var pool: HttpPool
proc genParams*(pars: openarray[(string, string)] = @[]; cursor=""; proc genParams*(pars: openArray[(string, string)] = @[]; cursor="";
count="20"; ext=true): seq[(string, string)] = count="20"; ext=true): seq[(string, string)] =
result = timelineParams result = timelineParams
for p in pars: for p in pars:

View File

@ -23,7 +23,7 @@ const
wwwRegex = re"https?://(www[0-9]?\.)?" wwwRegex = re"https?://(www[0-9]?\.)?"
m3u8Regex = re"""url="(.+.m3u8)"""" m3u8Regex = re"""url="(.+.m3u8)""""
manifestRegex = re"\/(.+(.ts|.m4s|.m3u8|.vmap|.mp4))" manifestRegex = re"\/(.+(.ts|.m4s|.m3u8|.vmap|.mp4))"
userpicRegex = re"_(normal|bigger|mini|200x200|400x400)(\.[A-z]+)$" userPicRegex = re"_(normal|bigger|mini|200x200|400x400)(\.[A-z]+)$"
extRegex = re"(\.[A-z]+)$" extRegex = re"(\.[A-z]+)$"
illegalXmlRegex = re"[^\x09\x0A\x0D\x20-\uD7FF\uE000-\uFFFD\u10000-\u10FFFF]" illegalXmlRegex = re"[^\x09\x0A\x0D\x20-\uD7FF\uE000-\uFFFD\u10000-\u10FFFF]"
@ -89,12 +89,12 @@ proc proxifyVideo*(manifest: string; proxy: bool): string =
if proxy: result = getVidUrl(result) if proxy: result = getVidUrl(result)
result = manifest.replace(manifestRegex, cb) result = manifest.replace(manifestRegex, cb)
proc getUserpic*(userpic: string; style=""): string = proc getUserPic*(userPic: string; style=""): string =
let pic = userpic.replace(userpicRegex, "$2") let pic = userPic.replace(userPicRegex, "$2")
pic.replace(extRegex, style & "$1") pic.replace(extRegex, style & "$1")
proc getUserpic*(profile: Profile; style=""): string = proc getUserPic*(profile: Profile; style=""): string =
getUserPic(profile.userpic, style) getUserPic(profile.userPic, style)
proc getVideoEmbed*(cfg: Config; id: int64): string = proc getVideoEmbed*(cfg: Config; id: int64): string =
&"{getUrlPrefix(cfg)}/i/videos/{id}" &"{getUrlPrefix(cfg)}/i/videos/{id}"

View File

@ -12,7 +12,7 @@ proc parseProfile(js: JsonNode; id=""): Profile =
fullname: js{"name"}.getStr, fullname: js{"name"}.getStr,
location: js{"location"}.getStr, location: js{"location"}.getStr,
bio: js{"description"}.getStr, bio: js{"description"}.getStr,
userpic: js{"profile_image_url_https"}.getImageStr.replace("_normal", ""), userPic: js{"profile_image_url_https"}.getImageStr.replace("_normal", ""),
banner: js.getBanner, banner: js.getBanner,
following: $js{"friends_count"}.getInt, following: $js{"friends_count"}.getInt,
followers: $js{"followers_count"}.getInt, followers: $js{"followers_count"}.getInt,

View File

@ -65,45 +65,45 @@ proc get(query: string): Future[string] {.async.} =
pool.withAcquire(r): pool.withAcquire(r):
result = await r.get(query) result = await r.get(query)
proc setex(key: string; time: int; data: string) {.async.} = proc setEx(key: string; time: int; data: string) {.async.} =
pool.withAcquire(r): pool.withAcquire(r):
discard await r.setex(key, time, data) discard await r.setEx(key, time, data)
proc cache*(data: List) {.async.} = proc cache*(data: List) {.async.} =
await setex(data.listKey, listCacheTime, compress(toFlatty(data))) await setEx(data.listKey, listCacheTime, compress(toFlatty(data)))
proc cache*(data: PhotoRail; name: string) {.async.} = proc cache*(data: PhotoRail; name: string) {.async.} =
await setex("pr:" & toLower(name), baseCacheTime, compress(toFlatty(data))) await setEx("pr:" & toLower(name), baseCacheTime, compress(toFlatty(data)))
proc cache*(data: Profile) {.async.} = proc cache*(data: Profile) {.async.} =
if data.username.len == 0 or data.id.len == 0: return if data.username.len == 0 or data.id.len == 0: return
let name = toLower(data.username) let name = toLower(data.username)
pool.withAcquire(r): pool.withAcquire(r):
r.startPipelining() r.startPipelining()
discard await r.setex(name.profileKey, baseCacheTime, compress(toFlatty(data))) discard await r.setEx(name.profileKey, baseCacheTime, compress(toFlatty(data)))
discard await r.setex("i:" & data.id , baseCacheTime, data.username) discard await r.setEx("i:" & data.id , baseCacheTime, data.username)
discard await r.hset(name.pidKey, name, data.id) discard await r.hSet(name.pidKey, name, data.id)
discard await r.flushPipeline() discard await r.flushPipeline()
proc cacheProfileId*(username, id: string) {.async.} = proc cacheProfileId*(username, id: string) {.async.} =
if username.len == 0 or id.len == 0: return if username.len == 0 or id.len == 0: return
let name = toLower(username) let name = toLower(username)
pool.withAcquire(r): pool.withAcquire(r):
discard await r.hset(name.pidKey, name, id) discard await r.hSet(name.pidKey, name, id)
proc cacheRss*(query: string; rss: Rss) {.async.} = proc cacheRss*(query: string; rss: Rss) {.async.} =
let key = "rss:" & query let key = "rss:" & query
pool.withAcquire(r): pool.withAcquire(r):
r.startPipelining() r.startPipelining()
discard await r.hset(key, "rss", rss.feed) discard await r.hSet(key, "rss", rss.feed)
discard await r.hset(key, "min", rss.cursor) discard await r.hSet(key, "min", rss.cursor)
discard await r.expire(key, rssCacheTime) discard await r.expire(key, rssCacheTime)
discard await r.flushPipeline() discard await r.flushPipeline()
proc getProfileId*(username: string): Future[string] {.async.} = proc getProfileId*(username: string): Future[string] {.async.} =
let name = toLower(username) let name = toLower(username)
pool.withAcquire(r): pool.withAcquire(r):
result = await r.hget(name.pidKey, name) result = await r.hGet(name.pidKey, name)
if result == redisNil: if result == redisNil:
result.setLen(0) result.setLen(0)
@ -148,8 +148,8 @@ proc getCachedList*(username=""; slug=""; id=""): Future[List] {.async.} =
proc getCachedRss*(key: string): Future[Rss] {.async.} = proc getCachedRss*(key: string): Future[Rss] {.async.} =
let k = "rss:" & key let k = "rss:" & key
pool.withAcquire(r): pool.withAcquire(r):
result.cursor = await r.hget(k, "min") result.cursor = await r.hGet(k, "min")
if result.cursor.len > 2: if result.cursor.len > 2:
result.feed = await r.hget(k, "rss") result.feed = await r.hGet(k, "rss")
else: else:
result.cursor.setLen 0 result.cursor.setLen 0

View File

@ -93,7 +93,7 @@ proc showTimeline*(request: Request; query: Query; cfg: Config; prefs: Prefs;
let pHtml = renderProfile(p, t, r, prefs, getPath()) let pHtml = renderProfile(p, t, r, prefs, getPath())
result = renderMain(pHtml, request, cfg, prefs, pageTitle(p), pageDesc(p), result = renderMain(pHtml, request, cfg, prefs, pageTitle(p), pageDesc(p),
rss=rss, images = @[p.getUserpic("_400x400")], rss=rss, images = @[p.getUserPic("_400x400")],
banner=p.banner) banner=p.banner)
template respTimeline*(timeline: typed) = template respTimeline*(timeline: typed) =

View File

@ -52,7 +52,7 @@ type
location*: string location*: string
website*: string website*: string
bio*: string bio*: string
userpic*: string userPic*: string
banner*: string banner*: string
following*: string following*: string
followers*: string followers*: string

View File

@ -15,12 +15,14 @@ proc renderStat(num, class: string; text=""): VNode =
proc renderProfileCard*(profile: Profile; prefs: Prefs): VNode = proc renderProfileCard*(profile: Profile; prefs: Prefs): VNode =
buildHtml(tdiv(class="profile-card")): buildHtml(tdiv(class="profile-card")):
tdiv(class="profile-card-info"): tdiv(class="profile-card-info"):
let url = getPicUrl(profile.getUserPic()) let
var size = "_400x400" url = getPicUrl(profile.getUserPic())
if prefs.autoplayGifs and profile.userpic.endsWith("gif"): size =
size = "" if prefs.autoplayGifs and profile.userPic.endsWith("gif"): ""
else: "_400x400"
a(class="profile-card-avatar", href=url, target="_blank"): a(class="profile-card-avatar", href=url, target="_blank"):
genImg(profile.getUserpic(size)) genImg(profile.getUserPic(size))
tdiv(class="profile-card-tabs-name"): tdiv(class="profile-card-tabs-name"):
linkUser(profile, class="profile-card-fullname") linkUser(profile, class="profile-card-fullname")

View File

@ -63,7 +63,7 @@ proc renderUser(user: Profile; prefs: Prefs): VNode =
tdiv(class="tweet-body profile-result"): tdiv(class="tweet-body profile-result"):
tdiv(class="tweet-header"): tdiv(class="tweet-header"):
a(class="tweet-avatar", href=("/" & user.username)): a(class="tweet-avatar", href=("/" & user.username)):
genImg(user.getUserpic("_bigger"), class="avatar") genImg(user.getUserPic("_bigger"), class="avatar")
tdiv(class="tweet-name-row"): tdiv(class="tweet-name-row"):
tdiv(class="fullname-and-username"): tdiv(class="fullname-and-username"):

View File

@ -12,7 +12,7 @@ proc getSmallPic(url: string): string =
result = getPicUrl(result) result = getPicUrl(result)
proc renderMiniAvatar(profile: Profile): VNode = proc renderMiniAvatar(profile: Profile): VNode =
let url = getPicUrl(profile.getUserpic("_mini")) let url = getPicUrl(profile.getUserPic("_mini"))
buildHtml(): buildHtml():
img(class="avatar mini", src=url) img(class="avatar mini", src=url)
@ -29,9 +29,9 @@ proc renderHeader(tweet: Tweet; retweet: string; prefs: Prefs): VNode =
tdiv(class="tweet-header"): tdiv(class="tweet-header"):
a(class="tweet-avatar", href=("/" & tweet.profile.username)): a(class="tweet-avatar", href=("/" & tweet.profile.username)):
var size = "_bigger" var size = "_bigger"
if not prefs.autoplayGifs and tweet.profile.userpic.endsWith("gif"): if not prefs.autoplayGifs and tweet.profile.userPic.endsWith("gif"):
size = "_400x400" size = "_400x400"
genImg(tweet.profile.getUserpic(size), class="avatar") genImg(tweet.profile.getUserPic(size), class="avatar")
tdiv(class="tweet-name-row"): tdiv(class="tweet-name-row"):
tdiv(class="fullname-and-username"): tdiv(class="fullname-and-username"):