From ffcac982d07646ada24318c0bac3be9ecdcdb5ea Mon Sep 17 00:00:00 2001 From: Zed Date: Thu, 6 Jan 2022 03:57:14 +0100 Subject: [PATCH] Style fixes --- src/apiutils.nim | 2 +- src/formatters.nim | 10 +++++----- src/parser.nim | 2 +- src/redis_cache.nim | 26 +++++++++++++------------- src/routes/timeline.nim | 2 +- src/types.nim | 2 +- src/views/profile.nim | 12 +++++++----- src/views/timeline.nim | 2 +- src/views/tweet.nim | 6 +++--- 9 files changed, 33 insertions(+), 31 deletions(-) diff --git a/src/apiutils.nim b/src/apiutils.nim index 25d9456..e287dc5 100644 --- a/src/apiutils.nim +++ b/src/apiutils.nim @@ -9,7 +9,7 @@ const var pool: HttpPool -proc genParams*(pars: openarray[(string, string)] = @[]; cursor=""; +proc genParams*(pars: openArray[(string, string)] = @[]; cursor=""; count="20"; ext=true): seq[(string, string)] = result = timelineParams for p in pars: diff --git a/src/formatters.nim b/src/formatters.nim index 1af3e20..7ff04e3 100644 --- a/src/formatters.nim +++ b/src/formatters.nim @@ -23,7 +23,7 @@ const wwwRegex = re"https?://(www[0-9]?\.)?" m3u8Regex = re"""url="(.+.m3u8)"""" 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]+)$" 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) result = manifest.replace(manifestRegex, cb) -proc getUserpic*(userpic: string; style=""): string = - let pic = userpic.replace(userpicRegex, "$2") +proc getUserPic*(userPic: string; style=""): string = + let pic = userPic.replace(userPicRegex, "$2") pic.replace(extRegex, style & "$1") -proc getUserpic*(profile: Profile; style=""): string = - getUserPic(profile.userpic, style) +proc getUserPic*(profile: Profile; style=""): string = + getUserPic(profile.userPic, style) proc getVideoEmbed*(cfg: Config; id: int64): string = &"{getUrlPrefix(cfg)}/i/videos/{id}" diff --git a/src/parser.nim b/src/parser.nim index a086dc3..3b16786 100644 --- a/src/parser.nim +++ b/src/parser.nim @@ -12,7 +12,7 @@ proc parseProfile(js: JsonNode; id=""): Profile = fullname: js{"name"}.getStr, location: js{"location"}.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, following: $js{"friends_count"}.getInt, followers: $js{"followers_count"}.getInt, diff --git a/src/redis_cache.nim b/src/redis_cache.nim index e0133d2..dbe917c 100644 --- a/src/redis_cache.nim +++ b/src/redis_cache.nim @@ -65,45 +65,45 @@ proc get(query: string): Future[string] {.async.} = pool.withAcquire(r): 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): - discard await r.setex(key, time, data) + discard await r.setEx(key, time, data) 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.} = - await setex("pr:" & toLower(name), baseCacheTime, compress(toFlatty(data))) + await setEx("pr:" & toLower(name), baseCacheTime, compress(toFlatty(data))) proc cache*(data: Profile) {.async.} = if data.username.len == 0 or data.id.len == 0: return let name = toLower(data.username) pool.withAcquire(r): r.startPipelining() - discard await r.setex(name.profileKey, baseCacheTime, compress(toFlatty(data))) - discard await r.setex("i:" & data.id , baseCacheTime, data.username) - discard await r.hset(name.pidKey, name, data.id) + discard await r.setEx(name.profileKey, baseCacheTime, compress(toFlatty(data))) + discard await r.setEx("i:" & data.id , baseCacheTime, data.username) + discard await r.hSet(name.pidKey, name, data.id) discard await r.flushPipeline() proc cacheProfileId*(username, id: string) {.async.} = if username.len == 0 or id.len == 0: return let name = toLower(username) 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.} = let key = "rss:" & query pool.withAcquire(r): r.startPipelining() - discard await r.hset(key, "rss", rss.feed) - discard await r.hset(key, "min", rss.cursor) + discard await r.hSet(key, "rss", rss.feed) + discard await r.hSet(key, "min", rss.cursor) discard await r.expire(key, rssCacheTime) discard await r.flushPipeline() proc getProfileId*(username: string): Future[string] {.async.} = let name = toLower(username) pool.withAcquire(r): - result = await r.hget(name.pidKey, name) + result = await r.hGet(name.pidKey, name) if result == redisNil: result.setLen(0) @@ -148,8 +148,8 @@ proc getCachedList*(username=""; slug=""; id=""): Future[List] {.async.} = proc getCachedRss*(key: string): Future[Rss] {.async.} = let k = "rss:" & key pool.withAcquire(r): - result.cursor = await r.hget(k, "min") + result.cursor = await r.hGet(k, "min") if result.cursor.len > 2: - result.feed = await r.hget(k, "rss") + result.feed = await r.hGet(k, "rss") else: result.cursor.setLen 0 diff --git a/src/routes/timeline.nim b/src/routes/timeline.nim index e904f2d..2992888 100644 --- a/src/routes/timeline.nim +++ b/src/routes/timeline.nim @@ -93,7 +93,7 @@ proc showTimeline*(request: Request; query: Query; cfg: Config; prefs: Prefs; let pHtml = renderProfile(p, t, r, prefs, getPath()) 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) template respTimeline*(timeline: typed) = diff --git a/src/types.nim b/src/types.nim index e8cdb7d..5b329b7 100644 --- a/src/types.nim +++ b/src/types.nim @@ -52,7 +52,7 @@ type location*: string website*: string bio*: string - userpic*: string + userPic*: string banner*: string following*: string followers*: string diff --git a/src/views/profile.nim b/src/views/profile.nim index 6918550..78e9fce 100644 --- a/src/views/profile.nim +++ b/src/views/profile.nim @@ -15,12 +15,14 @@ proc renderStat(num, class: string; text=""): VNode = proc renderProfileCard*(profile: Profile; prefs: Prefs): VNode = buildHtml(tdiv(class="profile-card")): tdiv(class="profile-card-info"): - let url = getPicUrl(profile.getUserPic()) - var size = "_400x400" - if prefs.autoplayGifs and profile.userpic.endsWith("gif"): - size = "" + let + url = getPicUrl(profile.getUserPic()) + size = + if prefs.autoplayGifs and profile.userPic.endsWith("gif"): "" + else: "_400x400" + a(class="profile-card-avatar", href=url, target="_blank"): - genImg(profile.getUserpic(size)) + genImg(profile.getUserPic(size)) tdiv(class="profile-card-tabs-name"): linkUser(profile, class="profile-card-fullname") diff --git a/src/views/timeline.nim b/src/views/timeline.nim index 4a2f29c..cf14ff3 100644 --- a/src/views/timeline.nim +++ b/src/views/timeline.nim @@ -63,7 +63,7 @@ proc renderUser(user: Profile; prefs: Prefs): VNode = tdiv(class="tweet-body profile-result"): tdiv(class="tweet-header"): 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="fullname-and-username"): diff --git a/src/views/tweet.nim b/src/views/tweet.nim index b04fb0c..d435469 100644 --- a/src/views/tweet.nim +++ b/src/views/tweet.nim @@ -12,7 +12,7 @@ proc getSmallPic(url: string): string = result = getPicUrl(result) proc renderMiniAvatar(profile: Profile): VNode = - let url = getPicUrl(profile.getUserpic("_mini")) + let url = getPicUrl(profile.getUserPic("_mini")) buildHtml(): img(class="avatar mini", src=url) @@ -29,9 +29,9 @@ proc renderHeader(tweet: Tweet; retweet: string; prefs: Prefs): VNode = tdiv(class="tweet-header"): a(class="tweet-avatar", href=("/" & tweet.profile.username)): 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" - genImg(tweet.profile.getUserpic(size), class="avatar") + genImg(tweet.profile.getUserPic(size), class="avatar") tdiv(class="tweet-name-row"): tdiv(class="fullname-and-username"):