فهرست منبع

Fix compiler warnings

Zed 4 سال پیش
والد
کامیت
7af71ec480
12فایلهای تغییر یافته به همراه21 افزوده شده و 23 حذف شده
  1. 1 0
      config.nims
  2. 1 1
      src/api.nim
  3. 2 5
      src/formatters.nim
  4. 3 4
      src/parser.nim
  5. 4 4
      src/parserutils.nim
  6. 2 1
      src/redis_cache.nim
  7. 2 2
      src/routes/embed.nim
  8. 1 1
      src/routes/list.nim
  9. 1 1
      src/routes/resolver.nim
  10. 1 1
      src/routes/rss.nim
  11. 1 1
      src/routes/search.nim
  12. 2 2
      src/types.nim

+ 1 - 0
config.nims

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

+ 1 - 1
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

+ 2 - 5
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")

+ 3 - 4
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

+ 4 - 4
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.} =

+ 2 - 1
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")

+ 2 - 2
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:

+ 1 - 1
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
 

+ 1 - 1
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 =

+ 1 - 1
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
 

+ 1 - 1
src/routes/search.nim

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

+ 2 - 2
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