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) {
|
func SetBTSets(sets *BTSets) {
|
||||||
if tdb.ReadOnly {
|
if ReadOnly {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,12 +9,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type TDB struct {
|
type TDB struct {
|
||||||
Path string
|
Path string
|
||||||
ReadOnly bool
|
db *bolt.DB
|
||||||
db *bolt.DB
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTDB(readOnly bool) *TDB {
|
func NewTDB() *TDB {
|
||||||
db, err := bolt.Open(filepath.Join(Path, "config.db"), 0666, nil)
|
db, err := bolt.Open(filepath.Join(Path, "config.db"), 0666, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.TLogln(err)
|
log.TLogln(err)
|
||||||
@@ -24,7 +23,6 @@ func NewTDB(readOnly bool) *TDB {
|
|||||||
tdb := new(TDB)
|
tdb := new(TDB)
|
||||||
tdb.db = db
|
tdb.db = db
|
||||||
tdb.Path = Path
|
tdb.Path = Path
|
||||||
tdb.ReadOnly = readOnly
|
|
||||||
return tdb
|
return tdb
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,7 +67,7 @@ func (v *TDB) Get(xpath, name string) []byte {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (v *TDB) Set(xpath, name string, value []byte) {
|
func (v *TDB) Set(xpath, name string, value []byte) {
|
||||||
if v.ReadOnly {
|
if ReadOnly {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,7 +142,7 @@ func (v *TDB) List(xpath string) []string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (v *TDB) Rem(xpath, name string) {
|
func (v *TDB) Rem(xpath, name string) {
|
||||||
if v.ReadOnly {
|
if ReadOnly {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
package settings
|
package settings
|
||||||
|
|
||||||
var (
|
var (
|
||||||
tdb *TDB
|
tdb *TDB
|
||||||
Path string
|
Path string
|
||||||
|
ReadOnly bool
|
||||||
)
|
)
|
||||||
|
|
||||||
func InitSets(readOnly bool) {
|
func InitSets(readOnly bool) {
|
||||||
tdb = NewTDB(readOnly)
|
ReadOnly = readOnly
|
||||||
|
tdb = NewTDB()
|
||||||
loadBTSets()
|
loadBTSets()
|
||||||
Migrate()
|
Migrate()
|
||||||
}
|
}
|
||||||
@@ -14,10 +16,3 @@ func InitSets(readOnly bool) {
|
|||||||
func CloseDB() {
|
func CloseDB() {
|
||||||
tdb.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) {
|
func SetSettings(set *sets.BTSets) {
|
||||||
|
if sets.ReadOnly {
|
||||||
|
return
|
||||||
|
}
|
||||||
bts.Disconnect()
|
bts.Disconnect()
|
||||||
sets.SetBTSets(set)
|
sets.SetBTSets(set)
|
||||||
bts.Connect()
|
bts.Connect()
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ func echo(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func shutdown(c *gin.Context) {
|
func shutdown(c *gin.Context) {
|
||||||
if sets.IsReadOnly() {
|
if sets.ReadOnly {
|
||||||
c.Status(http.StatusForbidden)
|
c.Status(http.StatusForbidden)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user