Fix compiler warnings

This commit is contained in:
Zed 2021-12-20 03:11:12 +01:00
parent f02515fda2
commit 7af71ec480
12 changed files with 21 additions and 23 deletions

View file

@ -7,3 +7,4 @@
# disable annoying warnings # disable annoying warnings
warning("GcUnsafe2", off) warning("GcUnsafe2", off)
warning("ObservableStores", off) warning("ObservableStores", off)
warning("HoleEnumConv", off)

View file

@ -88,7 +88,7 @@ proc getTweet*(id: string; after=""): Future[Conversation] {.async.} =
proc resolve*(url: string; prefs: Prefs): Future[string] {.async.} = proc resolve*(url: string; prefs: Prefs): Future[string] {.async.} =
let client = newAsyncHttpClient(maxRedirects=0) let client = newAsyncHttpClient(maxRedirects=0)
try: try:
let resp = await client.request(url, $HttpHead) let resp = await client.request(url, HttpHead)
result = resp.headers["location"].replaceUrl(prefs) result = resp.headers["location"].replaceUrl(prefs)
except: except:
discard discard

View file

@ -104,12 +104,9 @@ proc getTweetTime*(tweet: Tweet): string =
proc getShortTime*(tweet: Tweet): string = proc getShortTime*(tweet: Tweet): string =
let now = now() let now = now()
var then = tweet.time.local() let since = now - tweet.time
then.utcOffset = 0
let since = now - then if now.year != tweet.time.year:
if now.year != then.year:
result = tweet.time.format("d MMM yyyy") result = tweet.time.format("d MMM yyyy")
elif since.inDays >= 1: elif since.inDays >= 1:
result = tweet.time.format("MMM d") result = tweet.time.format("MMM d")

View file

@ -93,8 +93,8 @@ proc parsePoll(js: JsonNode): Poll =
result.options.add vals{choice & "_label"}.getStrVal result.options.add vals{choice & "_label"}.getStrVal
let time = vals{"end_datetime_utc", "string_value"}.getDateTime let time = vals{"end_datetime_utc", "string_value"}.getDateTime
if time > getTime(): if time > now():
let timeLeft = $(time - getTime()) let timeLeft = $(time - now())
result.status = timeLeft[0 ..< timeLeft.find(",")] result.status = timeLeft[0 ..< timeLeft.find(",")]
else: else:
result.status = "Final results" result.status = "Final results"
@ -269,12 +269,11 @@ proc parseTweet(js: JsonNode): Tweet =
result.gif = some(parseGif(m)) result.gif = some(parseGif(m))
else: discard else: discard
let withheldInCountries = ( let withheldInCountries: seq[string] =
if js{"withheld_in_countries"}.kind == JArray: if js{"withheld_in_countries"}.kind == JArray:
js{"withheld_in_countries"}.to(seq[string]) js{"withheld_in_countries"}.to(seq[string])
else: else:
newSeq[string]() newSeq[string]()
)
if js{"withheld_copyright"}.getBool or if js{"withheld_copyright"}.getBool or
# XX - Content is withheld in all countries # XX - Content is withheld in all countries

View file

@ -43,14 +43,14 @@ template getError*(js: JsonNode): Error =
if js.kind != JArray or js.len == 0: null if js.kind != JArray or js.len == 0: null
else: Error(js[0]{"code"}.getInt) 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 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) 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) parseTime(js.getStr, "ddd MMM dd hh:mm:ss \'+0000\' yyyy", 30)
proc getId*(id: string): string {.inline.} = proc getId*(id: string): string {.inline.} =

View file

@ -22,7 +22,7 @@ proc migrate*(key, match: string) {.async.} =
let list = await r.scan(newCursor(0), match, 100000) let list = await r.scan(newCursor(0), match, 100000)
r.startPipelining() r.startPipelining()
for item in list: for item in list:
if item != "p:" or item == match: if item == match:
discard await r.del(item) discard await r.del(item)
await r.setk(key, "true") await r.setk(key, "true")
discard await r.flushPipeline() discard await r.flushPipeline()
@ -35,6 +35,7 @@ proc initRedisPool*(cfg: Config) {.async.} =
await migrate("snappyRss", "rss:*") await migrate("snappyRss", "rss:*")
await migrate("oldFrosty", "*") await migrate("oldFrosty", "*")
await migrate("userBuckets", "p:") await migrate("userBuckets", "p:")
await migrate("profileDates", "p:")
pool.withAcquire(r): pool.withAcquire(r):
await r.configSet("hash-max-ziplist-entries", "1000") await r.configSet("hash-max-ziplist-entries", "1000")

View file

@ -1,8 +1,8 @@
import asyncdispatch, strutils, sequtils, uri, options import asyncdispatch, strutils, options
import jester import jester
import ".."/[types, api], ../views/embed import ".."/[types, api], ../views/embed
export embed export api, embed
proc createEmbedRouter*(cfg: Config) = proc createEmbedRouter*(cfg: Config) =
router embed: router embed:

View file

@ -3,7 +3,7 @@ import strutils
import jester import jester
import router_utils import router_utils
import ".."/[query, types, redis_cache, api] import ".."/[types, redis_cache, api]
import ../views/[general, timeline, list] import ../views/[general, timeline, list]
export getListTimeline, getGraphList export getListTimeline, getGraphList

View file

@ -3,7 +3,7 @@ import strutils
import jester import jester
import router_utils import router_utils
import ".."/[query, types, api] import ".."/[types, api]
import ../views/general import ../views/general
template respResolved*(url, kind: string): untyped = template respResolved*(url, kind: string): untyped =

View file

@ -1,4 +1,4 @@
import asyncdispatch, strutils, tables, times, sequtils, hashes, supersnappy import asyncdispatch, strutils, tables, times, hashes, supersnappy
import jester import jester

View file

@ -1,4 +1,4 @@
import strutils, sequtils, uri import strutils, uri
import jester import jester

View file

@ -46,7 +46,7 @@ type
verified*: bool verified*: bool
protected*: bool protected*: bool
suspended*: bool suspended*: bool
joinDate*: Time joinDate*: DateTime
VideoType* = enum VideoType* = enum
m3u8 = "application/x-mpegURL" m3u8 = "application/x-mpegURL"
@ -152,7 +152,7 @@ type
replyId*: int64 replyId*: int64
profile*: Profile profile*: Profile
text*: string text*: string
time*: Time time*: DateTime
reply*: seq[string] reply*: seq[string]
pinned*: bool pinned*: bool
hasThread*: bool hasThread*: bool