mirror of
https://github.com/Ernous/TorrServerJellyfin.git
synced 2025-12-19 13:36:09 +05:00
refactor read only sets
This commit is contained in:
@@ -47,7 +47,7 @@ var (
|
||||
)
|
||||
|
||||
func SetBTSets(sets *BTSets) {
|
||||
if tdb.ReadOnly {
|
||||
if ReadOnly {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -10,11 +10,10 @@ import (
|
||||
|
||||
type TDB struct {
|
||||
Path string
|
||||
ReadOnly bool
|
||||
db *bolt.DB
|
||||
}
|
||||
|
||||
func NewTDB(readOnly bool) *TDB {
|
||||
func NewTDB() *TDB {
|
||||
db, err := bolt.Open(filepath.Join(Path, "config.db"), 0666, nil)
|
||||
if err != nil {
|
||||
log.TLogln(err)
|
||||
@@ -24,7 +23,6 @@ func NewTDB(readOnly bool) *TDB {
|
||||
tdb := new(TDB)
|
||||
tdb.db = db
|
||||
tdb.Path = Path
|
||||
tdb.ReadOnly = readOnly
|
||||
return tdb
|
||||
}
|
||||
|
||||
@@ -69,7 +67,7 @@ func (v *TDB) Get(xpath, name string) []byte {
|
||||
}
|
||||
|
||||
func (v *TDB) Set(xpath, name string, value []byte) {
|
||||
if v.ReadOnly {
|
||||
if ReadOnly {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -144,7 +142,7 @@ func (v *TDB) List(xpath string) []string {
|
||||
}
|
||||
|
||||
func (v *TDB) Rem(xpath, name string) {
|
||||
if v.ReadOnly {
|
||||
if ReadOnly {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -3,10 +3,12 @@ package settings
|
||||
var (
|
||||
tdb *TDB
|
||||
Path string
|
||||
ReadOnly bool
|
||||
)
|
||||
|
||||
func InitSets(readOnly bool) {
|
||||
tdb = NewTDB(readOnly)
|
||||
ReadOnly = readOnly
|
||||
tdb = NewTDB()
|
||||
loadBTSets()
|
||||
Migrate()
|
||||
}
|
||||
@@ -14,10 +16,3 @@ func InitSets(readOnly bool) {
|
||||
func CloseDB() {
|
||||
tdb.CloseDB()
|
||||
}
|
||||
|
||||
func IsReadOnly() bool {
|
||||
if tdb == nil || tdb.ReadOnly {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -119,6 +119,9 @@ func DropTorrent(hashHex string) {
|
||||
}
|
||||
|
||||
func SetSettings(set *sets.BTSets) {
|
||||
if sets.ReadOnly {
|
||||
return
|
||||
}
|
||||
bts.Disconnect()
|
||||
sets.SetBTSets(set)
|
||||
bts.Connect()
|
||||
|
||||
@@ -43,7 +43,7 @@ func echo(c *gin.Context) {
|
||||
}
|
||||
|
||||
func shutdown(c *gin.Context) {
|
||||
if sets.IsReadOnly() {
|
||||
if sets.ReadOnly {
|
||||
c.Status(http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user