From 9dd7419ecf2dfdaacbcf0a5752198bae5954a16d Mon Sep 17 00:00:00 2001 From: Zed Date: Sun, 2 Jan 2022 07:00:44 +0100 Subject: [PATCH] Cleanup --- src/agents.nim | 2 +- src/redis_cache.nim | 5 +++-- src/utils.nim | 14 ++------------ 3 files changed, 6 insertions(+), 15 deletions(-) diff --git a/src/agents.nim b/src/agents.nim index 63a7677..a907e7b 100644 --- a/src/agents.nim +++ b/src/agents.nim @@ -31,7 +31,7 @@ proc windows(): string = trident = ["", "; Trident/5.0", "; Trident/6.0", "; Trident/7.0"] "Windows " & sample(nt) & sample(enc) & sample(arch) & sample(trident) -let macs = toSeq(6..15).mapIt($it) & @["14_4", "10_1", "9_3"] +const macs = toSeq(6..15).mapIt($it) & @["14_4", "10_1", "9_3"] proc mac(): string = "Macintosh; Intel Mac OS X 10_" & sample(macs) & sample(enc) diff --git a/src/redis_cache.nim b/src/redis_cache.nim index b434def..66ef415 100644 --- a/src/redis_cache.nim +++ b/src/redis_cache.nim @@ -4,11 +4,12 @@ import redis, redpool, flatty, supersnappy import types, api -const redisNil = "\0\0" +const + redisNil = "\0\0" + baseCacheTime = 60 * 60 var pool {.threadvar.}: RedisPool - baseCacheTime = 60 * 60 rssCacheTime: int listCacheTime*: int diff --git a/src/utils.nim b/src/utils.nim index e92d220..2ca0617 100644 --- a/src/utils.nim +++ b/src/utils.nim @@ -9,8 +9,6 @@ var const https* = "https://" twimg* = "pbs.twimg.com/" - badJpgExts = @["1500x500", "jpgn", "jpg:", "jpg_", "_jpg"] - badPngExts = @["pngn", "png:", "png_", "_png"] twitterDomains = @[ "twitter.com", "pic.twitter.com", @@ -19,6 +17,7 @@ const "pbs.twimg.com", "video.twimg.com" ] + nitterParams = ["name", "tab", "id", "list", "referer", "scroll"] proc setHmacKey*(key: string) = hmacKey = key @@ -43,18 +42,9 @@ proc getPicUrl*(link: string): string = else: &"/pic/{encodeUrl(link)}" -proc cleanFilename*(filename: string): string = - const reg = re"[^A-Za-z0-9._-]" - result = filename.replace(reg, "_") - if badJpgExts.anyIt(it in result): - result &= ".jpg" - elif badPngExts.anyIt(it in result): - result &= ".png" - proc filterParams*(params: Table): seq[(string, string)] = - const filter = ["name", "tab", "id", "list", "referer", "scroll"] for p in params.pairs(): - if p[1].len > 0 and p[0] notin filter: + if p[1].len > 0 and p[0] notin nitterParams: result.add p proc isTwitterUrl*(uri: Uri): bool =