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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user