1
0
mirror of https://github.com/zedeus/nitter.git synced 2026-01-28 22:32:48 -05:00

Add client preferences

This commit is contained in:
Zed
2019-08-13 19:44:29 +02:00
parent c42b2893ff
commit 966b3d5d62
12 changed files with 329 additions and 82 deletions

View File

@@ -1,7 +1,7 @@
import asyncdispatch, times
import types, api
withDb:
withCustomDb("cache.db", "", "", ""):
try:
createTables()
except DbError:
@@ -13,7 +13,7 @@ proc isOutdated*(profile: Profile): bool =
getTime() - profile.updated > profileCacheTime
proc cache*(profile: var Profile) =
withDb:
withCustomDb("cache.db", "", "", ""):
try:
let p = Profile.getOne("lower(username) = ?", toLower(profile.username))
profile.id = p.id
@@ -23,7 +23,7 @@ proc cache*(profile: var Profile) =
profile.insert()
proc hasCachedProfile*(username: string): Option[Profile] =
withDb:
withCustomDb("cache.db", "", "", ""):
try:
let p = Profile.getOne("lower(username) = ?", toLower(username))
doAssert not p.isOutdated
@@ -32,7 +32,7 @@ proc hasCachedProfile*(username: string): Option[Profile] =
result = none(Profile)
proc getCachedProfile*(username, agent: string; force=false): Future[Profile] {.async.} =
withDb:
withCustomDb("cache.db", "", "", ""):
try:
result.getOne("lower(username) = ?", toLower(username))
doAssert not result.isOutdated