move Settings and Viewed to separate json files

This commit is contained in:
Alexey D. Filimonov
2024-02-01 20:35:54 +03:00
parent cd830f67c9
commit 83c7ed1f95
7 changed files with 465 additions and 9 deletions

View File

@@ -1,6 +1,7 @@
package settings
import (
"fmt"
"os"
"path/filepath"
@@ -8,7 +9,7 @@ import (
)
var (
tdb *TDB
tdb TorrServerDB
Path string
Port string
Ssl bool
@@ -24,13 +25,35 @@ var (
func InitSets(readOnly, searchWA bool) {
ReadOnly = readOnly
SearchWA = searchWA
tdb = NewTDB()
if tdb == nil {
log.TLogln("Error open db:", filepath.Join(Path, "config.db"))
bboltDB := NewTDB()
if bboltDB == nil {
log.TLogln("Error open bboltDB:", filepath.Join(Path, "config.db"))
os.Exit(1)
}
jsonDB := NewJsonDB()
if jsonDB == nil {
log.TLogln("Error open jsonDB")
os.Exit(1)
}
dbRouter := NewXPathDBRouter()
// First registered DB becomes default route
dbRouter.RegisterRoute(jsonDB, "Settings")
dbRouter.RegisterRoute(jsonDB, "Viewed")
dbRouter.RegisterRoute(bboltDB, "Torrents")
tdb = NewDBReadCache(dbRouter)
// We migrate settings here, it must be done before loadBTSets()
if err := Migrate2(bboltDB, jsonDB); err != nil {
log.TLogln(fmt.Sprintf("Migrate2 failed"))
os.Exit(1)
}
loadBTSets()
Migrate()
Migrate1()
}
func CloseDB() {