From ed400f53eef81c843d7972bdb0e936cc5c818440 Mon Sep 17 00:00:00 2001 From: YouROK <8yourok8@mail.ru> Date: Wed, 22 Sep 2021 14:54:08 +0300 Subject: [PATCH] add files info to data on add to db --- server/torr/dbwrapper.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/server/torr/dbwrapper.go b/server/torr/dbwrapper.go index 6ae17f6..1b6533b 100644 --- a/server/torr/dbwrapper.go +++ b/server/torr/dbwrapper.go @@ -1,6 +1,7 @@ package torr import ( + "encoding/json" "time" "server/settings" @@ -9,11 +10,25 @@ import ( "github.com/anacrolix/torrent/metainfo" ) +type tsFiles struct { + TorrServer struct { + Files []*state.TorrentFileStat `json:"Files"` + } `json:"TorrServer"` +} + func AddTorrentDB(torr *Torrent) { t := new(settings.TorrentDB) t.TorrentSpec = torr.TorrentSpec t.Title = torr.Title - t.Data = torr.Data + if torr.Data == "" { + files := new(tsFiles) + files.TorrServer.Files = torr.Status().FileStats + buf, _ := json.Marshal(files) + t.Data = string(buf) + torr.Data = t.Data + } else { + t.Data = torr.Data + } t.Poster = torr.Poster t.Size = torr.Size if t.Size == 0 && torr.Torrent != nil {