Merge pull request #102 from cyclopsian/int64

Change ID types to int64
This commit is contained in:
Zed 2019-12-10 10:18:10 +01:00 committed by GitHub
commit 698ed8a85d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 19 additions and 19 deletions

View File

@ -63,7 +63,7 @@ proc cache*(video: var Video) =
if video.videoId.len > 0: if video.videoId.len > 0:
video.insert() video.insert()
proc getCachedVideo*(id: int): Option[Video] = proc getCachedVideo*(id: int64): Option[Video] =
withDb: withDb:
try: try:
return some Video.getOne("videoId = ?", $id) return some Video.getOne("videoId = ?", $id)

View File

@ -49,7 +49,7 @@ proc getUserpic*(userpic: string; style=""): string =
proc getUserpic*(profile: Profile; style=""): string = proc getUserpic*(profile: Profile; style=""): string =
getUserPic(profile.userpic, style) getUserPic(profile.userpic, style)
proc getVideoEmbed*(cfg: Config; id: int): string = proc getVideoEmbed*(cfg: Config; id: int64): string =
&"https://{cfg.hostname}/i/videos/{id}" &"https://{cfg.hostname}/i/videos/{id}"
proc pageTitle*(profile: Profile): string = proc pageTitle*(profile: Profile): string =

View File

@ -72,7 +72,7 @@ proc parseTweetProfile*(profile: XmlNode): Profile =
proc parseQuote*(quote: XmlNode): Quote = proc parseQuote*(quote: XmlNode): Quote =
result = Quote( result = Quote(
id: parseInt(quote.attr("data-item-id")), id: parseBiggestInt(quote.attr("data-item-id")),
text: getQuoteText(quote), text: getQuoteText(quote),
reply: parseTweetReply(quote), reply: parseTweetReply(quote),
hasThread: quote.select(".self-thread-context") != nil, hasThread: quote.select(".self-thread-context") != nil,
@ -99,8 +99,8 @@ proc parseTweet*(node: XmlNode): Tweet =
return Tweet() return Tweet()
result = Tweet( result = Tweet(
id: parseInt(tweet.attr("data-item-id")), id: parseBiggestInt(tweet.attr("data-item-id")),
threadId: parseInt(tweet.attr("data-conversation-id")), threadId: parseBiggestInt(tweet.attr("data-conversation-id")),
text: getTweetText(tweet), text: getTweetText(tweet),
time: getTimestamp(tweet), time: getTimestamp(tweet),
shortTime: getShortTime(tweet), shortTime: getShortTime(tweet),
@ -119,7 +119,7 @@ proc parseTweet*(node: XmlNode): Tweet =
if by.len > 0: if by.len > 0:
result.retweet = some Retweet( result.retweet = some Retweet(
by: stripText(by), by: stripText(by),
id: parseInt(tweet.attr("data-retweet-id")) id: parseBiggestInt(tweet.attr("data-retweet-id"))
) )
let quote = tweet.select(".QuoteTweet-innerContainer") let quote = tweet.select(".QuoteTweet-innerContainer")
@ -196,7 +196,7 @@ proc parseTimeline*(node: XmlNode; after: string): Timeline =
beginning: after.len == 0 beginning: after.len == 0
) )
proc parseVideo*(node: JsonNode; tweetId: int): Video = proc parseVideo*(node: JsonNode; tweetId: int64): Video =
let let
track = node{"track"} track = node{"track"}
cType = track["contentType"].to(string) cType = track["contentType"].to(string)

View File

@ -82,7 +82,7 @@ proc getTweetText*(tweet: XmlNode): string =
proc getTimestamp*(tweet: XmlNode): Time = proc getTimestamp*(tweet: XmlNode): Time =
let time = tweet.selectAttr(".js-short-timestamp", "data-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 = proc getShortTime*(tweet: XmlNode): string =
tweet.selectText(".js-short-timestamp") tweet.selectText(".js-short-timestamp")
@ -270,9 +270,9 @@ proc getTweetCard*(tweet: Tweet; node: XmlNode) =
tweet.card = some card tweet.card = some card
proc getMoreReplies*(node: XmlNode): int = proc getMoreReplies*(node: XmlNode): int64 =
let text = node.innerText().strip() let text = node.innerText().strip()
try: try:
result = parseInt(text.split(" ")[0]) result = parseBiggestInt(text.split(" ")[0])
except: except:
result = -1 result = -1

View File

@ -11,6 +11,6 @@ export embed
proc createEmbedRouter*(cfg: Config) = proc createEmbedRouter*(cfg: Config) =
router embed: router embed:
get "/i/videos/tweet/@id": 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(), "") await getVideo(tweet, getAgent(), "")
resp renderVideoEmbed(cfg, tweet) resp renderVideoEmbed(cfg, tweet)

View File

@ -115,7 +115,7 @@ type
video*: Option[Video] video*: Option[Video]
Quote* = object Quote* = object
id*: int id*: int64
profile*: Profile profile*: Profile
text*: string text*: string
reply*: seq[string] reply*: seq[string]
@ -128,7 +128,7 @@ type
Retweet* = object Retweet* = object
by*: string by*: string
id*: int id*: int64
TweetStats* = object TweetStats* = object
replies*: string replies*: string
@ -136,8 +136,8 @@ type
likes*: string likes*: string
Tweet* = ref object Tweet* = ref object
id*: int id*: int64
threadId*: int threadId*: int64
profile*: Profile profile*: Profile
text*: string text*: string
time*: Time time*: Time
@ -159,7 +159,7 @@ type
Chain* = ref object Chain* = ref object
content*: seq[Tweet] content*: seq[Tweet]
more*: int more*: int64
Conversation* = ref object Conversation* = ref object
tweet*: Tweet tweet*: Tweet

View File

@ -45,7 +45,7 @@ proc renderThread(thread: seq[Tweet]; prefs: Prefs; path: string): VNode =
renderTweet(tweet, prefs, path, class=(header & "thread"), renderTweet(tweet, prefs, path, class=(header & "thread"),
index=i, total=thread.high, showThread=show) 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 it.retweet.isNone and it.reply.len == 0 and it.threadId == thread
proc renderUser(user: Profile; prefs: Prefs): VNode = 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: if results.content.len == 0:
renderNoneFound() renderNoneFound()
else: else:
var threads: seq[int] var threads: seq[int64]
var retweets: seq[int] var retweets: seq[int64]
for tweet in results.content: for tweet in results.content:
if tweet.threadId in threads or tweet.id in retweets: continue if tweet.threadId in threads or tweet.id in retweets: continue
if tweet.pinned and prefs.hidePins: continue if tweet.pinned and prefs.hidePins: continue