mirror of
https://github.com/Ernous/TorrServerJellyfin.git
synced 2025-12-19 21:46:11 +05:00
Merge pull request #23 from tsynik/read-only-db
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"`
|
Port string `arg:"-p" help:"web server port"`
|
||||||
Path string `arg:"-d" help:"database path"`
|
Path string `arg:"-d" help:"database path"`
|
||||||
Add string `arg:"-a" help:"add torrent link and exit"`
|
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"`
|
Kill bool `arg:"-k" help:"dont kill program on signal"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,7 +46,11 @@ func main() {
|
|||||||
Preconfig(params.Kill)
|
Preconfig(params.Kill)
|
||||||
|
|
||||||
server.Start(params.Path, params.Port)
|
server.Start(params.Path, params.Port)
|
||||||
settings.SaveSettings()
|
if (params.RDB) {
|
||||||
|
settings.SetRDB()
|
||||||
|
} else {
|
||||||
|
settings.SaveSettings()
|
||||||
|
}
|
||||||
fmt.Println(server.WaitServer())
|
fmt.Println(server.WaitServer())
|
||||||
time.Sleep(time.Second * 3)
|
time.Sleep(time.Second * 3)
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
|
|||||||
@@ -22,9 +22,10 @@ func openDB() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var err 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 {
|
if err != nil {
|
||||||
fmt.Print(err)
|
fmt.Println(err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ type Settings struct {
|
|||||||
DisableUPNP bool
|
DisableUPNP bool
|
||||||
DisableDHT bool
|
DisableDHT bool
|
||||||
DisableUpload bool
|
DisableUpload bool
|
||||||
|
ReadOnlyMode bool
|
||||||
Encryption int // 0 - Enable, 1 - disable, 2 - force
|
Encryption int // 0 - Enable, 1 - disable, 2 - force
|
||||||
DownloadRateLimit int // in kb, 0 - inf
|
DownloadRateLimit int // in kb, 0 - inf
|
||||||
UploadRateLimit int // in kb, 0 - inf
|
UploadRateLimit int // in kb, 0 - inf
|
||||||
@@ -115,3 +116,10 @@ func SaveSettings() error {
|
|||||||
return setsDB.Put([]byte("json"), []byte(buf))
|
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)
|
tor, err := settings.LoadTorrentDB(jreq.Hash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Error get torrent:", jreq.Hash, err)
|
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
|
torrStatus := torr.TorrentAdded
|
||||||
|
|||||||
Reference in New Issue
Block a user