From 5576cbac8d8b9baea13cef97bae35b2a95bb9164 Mon Sep 17 00:00:00 2001 From: Jason Francis Date: Mon, 9 Dec 2019 18:39:12 -0500 Subject: [PATCH] Change ID types to int64 --- src/cache.nim | 2 +- src/formatters.nim | 2 +- src/parser.nim | 10 +++++----- src/parserutils.nim | 6 +++--- src/routes/embed.nim | 2 +- src/types.nim | 10 +++++----- src/views/timeline.nim | 6 +++--- 7 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/cache.nim b/src/cache.nim index 52a4bae..99383f9 100644 --- a/src/cache.nim +++ b/src/cache.nim @@ -63,7 +63,7 @@ proc cache*(video: var Video) = if video.videoId.len > 0: video.insert() -proc getCachedVideo*(id: int): Option[Video] = +proc getCachedVideo*(id: int64): Option[Video] = withDb: try: return some Video.getOne("videoId = ?", $id) diff --git a/src/formatters.nim b/src/formatters.nim index 8f4540d..a8b9dd7 100644 --- a/src/formatters.nim +++ b/src/formatters.nim @@ -49,7 +49,7 @@ proc getUserpic*(userpic: string; style=""): string = proc getUserpic*(profile: Profile; style=""): string = getUserPic(profile.userpic, style) -proc getVideoEmbed*(cfg: Config; id: int): string = +proc getVideoEmbed*(cfg: Config; id: int64): string = &"https://{cfg.hostname}/i/videos/{id}" proc pageTitle*(profile: Profile): string = diff --git a/src/parser.nim b/src/parser.nim index 050f3a6..b5e1660 100644 --- a/src/parser.nim +++ b/src/parser.nim @@ -72,7 +72,7 @@ proc parseTweetProfile*(profile: XmlNode): Profile = proc parseQuote*(quote: XmlNode): Quote = result = Quote( - id: parseInt(quote.attr("data-item-id")), + id: parseBiggestInt(quote.attr("data-item-id")), text: getQuoteText(quote), reply: parseTweetReply(quote), hasThread: quote.select(".self-thread-context") != nil, @@ -99,8 +99,8 @@ proc parseTweet*(node: XmlNode): Tweet = return Tweet() result = Tweet( - id: parseInt(tweet.attr("data-item-id")), - threadId: parseInt(tweet.attr("data-conversation-id")), + id: parseBiggestInt(tweet.attr("data-item-id")), + threadId: parseBiggestInt(tweet.attr("data-conversation-id")), text: getTweetText(tweet), time: getTimestamp(tweet), shortTime: getShortTime(tweet), @@ -119,7 +119,7 @@ proc parseTweet*(node: XmlNode): Tweet = if by.len > 0: result.retweet = some Retweet( by: stripText(by), - id: parseInt(tweet.attr("data-retweet-id")) + id: parseBiggestInt(tweet.attr("data-retweet-id")) ) let quote = tweet.select(".QuoteTweet-innerContainer") @@ -196,7 +196,7 @@ proc parseTimeline*(node: XmlNode; after: string): Timeline = beginning: after.len == 0 ) -proc parseVideo*(node: JsonNode; tweetId: int): Video = +proc parseVideo*(node: JsonNode; tweetId: int64): Video = let track = node{"track"} cType = track["contentType"].to(string) diff --git a/src/parserutils.nim b/src/parserutils.nim index fed38ed..09116ad 100644 --- a/src/parserutils.nim +++ b/src/parserutils.nim @@ -82,7 +82,7 @@ proc getTweetText*(tweet: XmlNode): string = proc getTimestamp*(tweet: XmlNode): Time = let time = tweet.selectAttr(".js-short-timestamp", "data-time") - fromUnix(if time.len > 0: parseInt(time) else: 0) + fromUnix(if time.len > 0: parseBiggestInt(time) else: 0) proc getShortTime*(tweet: XmlNode): string = tweet.selectText(".js-short-timestamp") @@ -270,9 +270,9 @@ proc getTweetCard*(tweet: Tweet; node: XmlNode) = tweet.card = some card -proc getMoreReplies*(node: XmlNode): int = +proc getMoreReplies*(node: XmlNode): int64 = let text = node.innerText().strip() try: - result = parseInt(text.split(" ")[0]) + result = parseBiggestInt(text.split(" ")[0]) except: result = -1 diff --git a/src/routes/embed.nim b/src/routes/embed.nim index 6f5a9fd..a4c4784 100644 --- a/src/routes/embed.nim +++ b/src/routes/embed.nim @@ -11,6 +11,6 @@ export embed proc createEmbedRouter*(cfg: Config) = router embed: get "/i/videos/tweet/@id": - let tweet = Tweet(id: @"id".parseInt, video: some Video()) + let tweet = Tweet(id: @"id".parseBiggestInt, video: some Video()) await getVideo(tweet, getAgent(), "") resp renderVideoEmbed(cfg, tweet) diff --git a/src/types.nim b/src/types.nim index 07d683b..00c383f 100644 --- a/src/types.nim +++ b/src/types.nim @@ -115,7 +115,7 @@ type video*: Option[Video] Quote* = object - id*: int + id*: int64 profile*: Profile text*: string reply*: seq[string] @@ -128,7 +128,7 @@ type Retweet* = object by*: string - id*: int + id*: int64 TweetStats* = object replies*: string @@ -136,8 +136,8 @@ type likes*: string Tweet* = ref object - id*: int - threadId*: int + id*: int64 + threadId*: int64 profile*: Profile text*: string time*: Time @@ -159,7 +159,7 @@ type Chain* = ref object content*: seq[Tweet] - more*: int + more*: int64 Conversation* = ref object tweet*: Tweet diff --git a/src/views/timeline.nim b/src/views/timeline.nim index 5e2e9c7..58bf339 100644 --- a/src/views/timeline.nim +++ b/src/views/timeline.nim @@ -45,7 +45,7 @@ proc renderThread(thread: seq[Tweet]; prefs: Prefs; path: string): VNode = renderTweet(tweet, prefs, path, class=(header & "thread"), index=i, total=thread.high, showThread=show) -proc threadFilter(it: Tweet; thread: int): bool = +proc threadFilter(it: Tweet; thread: int64): bool = it.retweet.isNone and it.reply.len == 0 and it.threadId == thread proc renderUser(user: Profile; prefs: Prefs): VNode = @@ -88,8 +88,8 @@ proc renderTimelineTweets*(results: Result[Tweet]; prefs: Prefs; path: string): if results.content.len == 0: renderNoneFound() else: - var threads: seq[int] - var retweets: seq[int] + var threads: seq[int64] + var retweets: seq[int64] for tweet in results.content: if tweet.threadId in threads or tweet.id in retweets: continue if tweet.pinned and prefs.hidePins: continue