This commit is contained in:
Zed 2022-01-02 07:00:44 +01:00
parent 9d117aa15b
commit 9dd7419ecf
3 changed files with 6 additions and 15 deletions

View File

@ -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)

View File

@ -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

View File

@ -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 =