From 7a5d22b8bf5e83e2937883b7a9a4b9845a5c3830 Mon Sep 17 00:00:00 2001 From: nikk gitanes Date: Fri, 12 Apr 2024 11:27:08 +0300 Subject: [PATCH] fix data override on torrent edit via web --- server/torr/apihelper.go | 8 ++++++-- server/torr/dbwrapper.go | 15 ++++++++------- server/web/api/torrents.go | 7 ++++++- server/web/api/upload.go | 7 ++++++- 4 files changed, 26 insertions(+), 11 deletions(-) diff --git a/server/torr/apihelper.go b/server/torr/apihelper.go index 76e4ca6..63a170c 100644 --- a/server/torr/apihelper.go +++ b/server/torr/apihelper.go @@ -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 { diff --git a/server/torr/dbwrapper.go b/server/torr/dbwrapper.go index 60e525f..05c1919 100644 --- a/server/torr/dbwrapper.go +++ b/server/torr/dbwrapper.go @@ -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 diff --git a/server/web/api/torrents.go b/server/web/api/torrents.go index 3afe201..e334afb 100644 --- a/server/web/api/torrents.go +++ b/server/web/api/torrents.go @@ -97,7 +97,12 @@ func addTorrent(req torrReqJS, c *gin.Context) { tor, err := torr.AddTorrent(torrSpec, req.Title, req.Poster, req.Data, req.Category) - log.TLogln("Final torrent category:", tor.Category) + if tor.Data != "" { + log.TLogln("torrent data:", tor.Data) + } + if tor.Category != "" { + log.TLogln("torrent category:", tor.Category) + } if err != nil { log.TLogln("error add torrent:", err) diff --git a/server/web/api/upload.go b/server/web/api/upload.go index edbe8e9..f98445a 100644 --- a/server/web/api/upload.go +++ b/server/web/api/upload.go @@ -73,7 +73,12 @@ func torrentUpload(c *gin.Context) { tor, err = torr.AddTorrent(spec, title, poster, data, category) - log.TLogln("Final torrent category:", tor.Category) + if tor.Data != "" { + log.TLogln("torrent data:", tor.Data) + } + if tor.Category != "" { + log.TLogln("torrent category:", tor.Category) + } if err != nil { log.TLogln("error upload torrent:", err)