fix data override on torrent edit via web

This commit is contained in:
nikk gitanes
2024-04-12 11:27:08 +03:00
parent b4e6281c5c
commit 7a5d22b8bf
4 changed files with 26 additions and 11 deletions

View File

@@ -136,14 +136,18 @@ func SetTorrent(hashHex, title, poster, category string, data string) *Torrent {
torr.Title = title
torr.Poster = poster
torr.Category = category
torr.Data = data
if data != "" {
torr.Data = data
}
}
if torrDb != nil {
torrDb.Title = title
torrDb.Poster = poster
torrDb.Category = category
torrDb.Data = data
if data != "" {
torrDb.Data = data
}
AddTorrentDB(torrDb)
}
if torr != nil {

View File

@@ -4,10 +4,9 @@ import (
"encoding/json"
"time"
"server/torr/utils"
"server/settings"
"server/torr/state"
"server/torr/utils"
"github.com/anacrolix/torrent/metainfo"
)
@@ -26,9 +25,11 @@ func AddTorrentDB(torr *Torrent) {
if torr.Data == "" {
files := new(tsFiles)
files.TorrServer.Files = torr.Status().FileStats
buf, _ := json.Marshal(files)
t.Data = string(buf)
torr.Data = t.Data
buf, err := json.Marshal(files)
if err == nil {
t.Data = string(buf)
torr.Data = t.Data
}
} else {
t.Data = torr.Data
}
@@ -51,11 +52,11 @@ func GetTorrentDB(hash metainfo.Hash) *Torrent {
torr.TorrentSpec = db.TorrentSpec
torr.Title = db.Title
torr.Poster = db.Poster
torr.Category = db.Category
torr.Timestamp = db.Timestamp
torr.Size = db.Size
torr.Data = db.Data
torr.Stat = state.TorrentInDB
torr.Category = db.Category
return torr
}
}
@@ -74,9 +75,9 @@ func ListTorrentsDB() map[metainfo.Hash]*Torrent {
torr.TorrentSpec = db.TorrentSpec
torr.Title = db.Title
torr.Poster = db.Poster
torr.Category = db.Category
torr.Timestamp = db.Timestamp
torr.Size = db.Size
torr.Category = db.Category
torr.Data = db.Data
torr.Stat = state.TorrentInDB
ret[torr.TorrentSpec.InfoHash] = torr