From 7af71ec480cdab6f965f334443b6317c3489fb6e Mon Sep 17 00:00:00 2001 From: Zed Date: Mon, 20 Dec 2021 03:11:12 +0100 Subject: [PATCH] Fix compiler warnings --- config.nims | 1 + src/api.nim | 2 +- src/formatters.nim | 7 ++----- src/parser.nim | 7 +++---- src/parserutils.nim | 8 ++++---- src/redis_cache.nim | 3 ++- src/routes/embed.nim | 4 ++-- src/routes/list.nim | 2 +- src/routes/resolver.nim | 2 +- src/routes/rss.nim | 2 +- src/routes/search.nim | 2 +- src/types.nim | 4 ++-- 12 files changed, 21 insertions(+), 23 deletions(-) diff --git a/config.nims b/config.nims index a306dc8..7c2b04e 100644 --- a/config.nims +++ b/config.nims @@ -7,3 +7,4 @@ # disable annoying warnings warning("GcUnsafe2", off) warning("ObservableStores", off) +warning("HoleEnumConv", off) diff --git a/src/api.nim b/src/api.nim index 07465da..cf6f177 100644 --- a/src/api.nim +++ b/src/api.nim @@ -88,7 +88,7 @@ proc getTweet*(id: string; after=""): Future[Conversation] {.async.} = proc resolve*(url: string; prefs: Prefs): Future[string] {.async.} = let client = newAsyncHttpClient(maxRedirects=0) try: - let resp = await client.request(url, $HttpHead) + let resp = await client.request(url, HttpHead) result = resp.headers["location"].replaceUrl(prefs) except: discard diff --git a/src/formatters.nim b/src/formatters.nim index 56d445c..4fd14fb 100644 --- a/src/formatters.nim +++ b/src/formatters.nim @@ -104,12 +104,9 @@ proc getTweetTime*(tweet: Tweet): string = proc getShortTime*(tweet: Tweet): string = let now = now() - var then = tweet.time.local() - then.utcOffset = 0 + let since = now - tweet.time - let since = now - then - - if now.year != then.year: + if now.year != tweet.time.year: result = tweet.time.format("d MMM yyyy") elif since.inDays >= 1: result = tweet.time.format("MMM d") diff --git a/src/parser.nim b/src/parser.nim index 33774f5..f094639 100644 --- a/src/parser.nim +++ b/src/parser.nim @@ -93,8 +93,8 @@ proc parsePoll(js: JsonNode): Poll = result.options.add vals{choice & "_label"}.getStrVal let time = vals{"end_datetime_utc", "string_value"}.getDateTime - if time > getTime(): - let timeLeft = $(time - getTime()) + if time > now(): + let timeLeft = $(time - now()) result.status = timeLeft[0 ..< timeLeft.find(",")] else: result.status = "Final results" @@ -269,12 +269,11 @@ proc parseTweet(js: JsonNode): Tweet = result.gif = some(parseGif(m)) else: discard - let withheldInCountries = ( + let withheldInCountries: seq[string] = if js{"withheld_in_countries"}.kind == JArray: js{"withheld_in_countries"}.to(seq[string]) else: newSeq[string]() - ) if js{"withheld_copyright"}.getBool or # XX - Content is withheld in all countries diff --git a/src/parserutils.nim b/src/parserutils.nim index 5b694cc..4b9ece9 100644 --- a/src/parserutils.nim +++ b/src/parserutils.nim @@ -43,14 +43,14 @@ template getError*(js: JsonNode): Error = if js.kind != JArray or js.len == 0: null else: Error(js[0]{"code"}.getInt) -template parseTime(time: string; f: static string; flen: int): Time = +template parseTime(time: string; f: static string; flen: int): DateTime = if time.len != flen: return - parse(time, f).toTime + parse(time, f, utc()) -proc getDateTime*(js: JsonNode): Time = +proc getDateTime*(js: JsonNode): DateTime = parseTime(js.getStr, "yyyy-MM-dd\'T\'HH:mm:ss\'Z\'", 20) -proc getTime*(js: JsonNode): Time = +proc getTime*(js: JsonNode): DateTime = parseTime(js.getStr, "ddd MMM dd hh:mm:ss \'+0000\' yyyy", 30) proc getId*(id: string): string {.inline.} = diff --git a/src/redis_cache.nim b/src/redis_cache.nim index 1cb3bed..fce0c5a 100644 --- a/src/redis_cache.nim +++ b/src/redis_cache.nim @@ -22,7 +22,7 @@ proc migrate*(key, match: string) {.async.} = let list = await r.scan(newCursor(0), match, 100000) r.startPipelining() for item in list: - if item != "p:" or item == match: + if item == match: discard await r.del(item) await r.setk(key, "true") discard await r.flushPipeline() @@ -35,6 +35,7 @@ proc initRedisPool*(cfg: Config) {.async.} = await migrate("snappyRss", "rss:*") await migrate("oldFrosty", "*") await migrate("userBuckets", "p:") + await migrate("profileDates", "p:") pool.withAcquire(r): await r.configSet("hash-max-ziplist-entries", "1000") diff --git a/src/routes/embed.nim b/src/routes/embed.nim index 85839e2..cdd87c8 100644 --- a/src/routes/embed.nim +++ b/src/routes/embed.nim @@ -1,8 +1,8 @@ -import asyncdispatch, strutils, sequtils, uri, options +import asyncdispatch, strutils, options import jester import ".."/[types, api], ../views/embed -export embed +export api, embed proc createEmbedRouter*(cfg: Config) = router embed: diff --git a/src/routes/list.nim b/src/routes/list.nim index 12156b4..8ca76b6 100644 --- a/src/routes/list.nim +++ b/src/routes/list.nim @@ -3,7 +3,7 @@ import strutils import jester import router_utils -import ".."/[query, types, redis_cache, api] +import ".."/[types, redis_cache, api] import ../views/[general, timeline, list] export getListTimeline, getGraphList diff --git a/src/routes/resolver.nim b/src/routes/resolver.nim index fe1e981..a61dff8 100644 --- a/src/routes/resolver.nim +++ b/src/routes/resolver.nim @@ -3,7 +3,7 @@ import strutils import jester import router_utils -import ".."/[query, types, api] +import ".."/[types, api] import ../views/general template respResolved*(url, kind: string): untyped = diff --git a/src/routes/rss.nim b/src/routes/rss.nim index 69264a6..72a247a 100644 --- a/src/routes/rss.nim +++ b/src/routes/rss.nim @@ -1,4 +1,4 @@ -import asyncdispatch, strutils, tables, times, sequtils, hashes, supersnappy +import asyncdispatch, strutils, tables, times, hashes, supersnappy import jester diff --git a/src/routes/search.nim b/src/routes/search.nim index 329d955..2651352 100644 --- a/src/routes/search.nim +++ b/src/routes/search.nim @@ -1,4 +1,4 @@ -import strutils, sequtils, uri +import strutils, uri import jester diff --git a/src/types.nim b/src/types.nim index d3e2fff..d9fc747 100644 --- a/src/types.nim +++ b/src/types.nim @@ -46,7 +46,7 @@ type verified*: bool protected*: bool suspended*: bool - joinDate*: Time + joinDate*: DateTime VideoType* = enum m3u8 = "application/x-mpegURL" @@ -152,7 +152,7 @@ type replyId*: int64 profile*: Profile text*: string - time*: Time + time*: DateTime reply*: seq[string] pinned*: bool hasThread*: bool