mirror of
https://github.com/Ernous/TorrServerJellyfin.git
synced 2025-12-19 21:46:11 +05:00
add read-only db work mode
This commit is contained in:
@@ -18,6 +18,7 @@ type args struct {
|
||||
Port string `arg:"-p" help:"web server port"`
|
||||
Path string `arg:"-d" help:"database path"`
|
||||
Add string `arg:"-a" help:"add torrent link and exit"`
|
||||
RDB bool `arg:"-r" help:"start in read-only DB mode"`
|
||||
Kill bool `arg:"-k" help:"dont kill program on signal"`
|
||||
}
|
||||
|
||||
@@ -45,7 +46,11 @@ func main() {
|
||||
Preconfig(params.Kill)
|
||||
|
||||
server.Start(params.Path, params.Port)
|
||||
if (params.RDB) {
|
||||
settings.SetRDB()
|
||||
} else {
|
||||
settings.SaveSettings()
|
||||
}
|
||||
fmt.Println(server.WaitServer())
|
||||
time.Sleep(time.Second * 3)
|
||||
os.Exit(0)
|
||||
|
||||
@@ -22,9 +22,10 @@ func openDB() error {
|
||||
}
|
||||
|
||||
var err error
|
||||
db, err = bolt.Open(filepath.Join(Path, "torrserver.db"), 0666, nil)
|
||||
var ro = Get().ReadOnlyMode
|
||||
db, err = bolt.Open(filepath.Join(Path, "torrserver.db"), 0666, &bolt.Options{ReadOnly: ro})
|
||||
if err != nil {
|
||||
fmt.Print(err)
|
||||
fmt.Println(err)
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@ type Settings struct {
|
||||
DisableUPNP bool
|
||||
DisableDHT bool
|
||||
DisableUpload bool
|
||||
ReadOnlyMode bool
|
||||
Encryption int // 0 - Enable, 1 - disable, 2 - force
|
||||
DownloadRateLimit int // in kb, 0 - inf
|
||||
UploadRateLimit int // in kb, 0 - inf
|
||||
@@ -113,3 +114,10 @@ func SaveSettings() error {
|
||||
return setsDB.Put([]byte("json"), []byte(buf))
|
||||
})
|
||||
}
|
||||
|
||||
func SetRDB() {
|
||||
SaveSettings()
|
||||
fmt.Println("Enable Read-only DB mode")
|
||||
CloseDB()
|
||||
sets.ReadOnlyMode = true
|
||||
}
|
||||
|
||||
@@ -182,7 +182,7 @@ func torrentGet(c echo.Context) error {
|
||||
tor, err := settings.LoadTorrentDB(jreq.Hash)
|
||||
if err != nil {
|
||||
fmt.Println("Error get torrent:", jreq.Hash, err)
|
||||
return echo.NewHTTPError(http.StatusBadRequest, err.Error())
|
||||
// return echo.NewHTTPError(http.StatusBadRequest, err.Error()) // Handle R/O DB
|
||||
}
|
||||
|
||||
torrStatus := torr.TorrentAdded
|
||||
|
||||
Reference in New Issue
Block a user