mirror of
https://github.com/zedeus/nitter
synced 2026-09-05 22:59:31 +00:00
Refactor hostname to be a runtime option
Add a `hostname` field under Server in your conf file, see the updated nitter.conf in the repo for an example. The compile-time option (-d:hostname) is no longer used.
This commit is contained in:
parent
3218cc4069
commit
de62eedea5
19 changed files with 91 additions and 85 deletions
|
|
@ -22,6 +22,10 @@ withDb:
|
|||
except DbError:
|
||||
discard
|
||||
|
||||
proc getDefaultPrefs(hostname: string): Prefs =
|
||||
result = genDefaultPrefs()
|
||||
result.replaceTwitter = hostname
|
||||
|
||||
proc cache*(prefs: var Prefs) =
|
||||
withDb:
|
||||
try:
|
||||
|
|
@ -31,17 +35,18 @@ proc cache*(prefs: var Prefs) =
|
|||
except AssertionError, KeyError:
|
||||
prefs.insert()
|
||||
|
||||
proc getPrefs*(id: string): Prefs =
|
||||
if id.len == 0: return genDefaultPrefs()
|
||||
proc getPrefs*(id, hostname: string): Prefs =
|
||||
if id.len == 0:
|
||||
return getDefaultPrefs(hostname)
|
||||
|
||||
withDb:
|
||||
try:
|
||||
result.getOne("id = ?", id)
|
||||
except KeyError:
|
||||
result = genDefaultPrefs()
|
||||
result = getDefaultPrefs(hostname)
|
||||
|
||||
proc resetPrefs*(prefs: var Prefs) =
|
||||
var defPrefs = genDefaultPrefs()
|
||||
proc resetPrefs*(prefs: var Prefs; hostname: string) =
|
||||
var defPrefs = getDefaultPrefs(hostname)
|
||||
defPrefs.id = prefs.id
|
||||
cache(defPrefs)
|
||||
prefs = defPrefs
|
||||
|
|
|
|||
Loading…
Reference in a new issue