mirror of
https://github.com/Ernous/TorrServerJellyfin.git
synced 2025-12-20 14:06:09 +05:00
creating...
This commit is contained in:
50
src/server/web/api/utils/dbwrapper.go
Normal file
50
src/server/web/api/utils/dbwrapper.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/anacrolix/torrent/metainfo"
|
||||
"server/settings"
|
||||
"server/torr"
|
||||
)
|
||||
|
||||
func AddTorrent(torr *torr.Torrent) {
|
||||
t := new(settings.TorrentDB)
|
||||
t.TorrentSpec = torr.TorrentSpec
|
||||
t.Title = torr.Title
|
||||
t.Poster = torr.Poster
|
||||
t.Timestamp = time.Now().Unix()
|
||||
t.Files = torr.Stats().FileStats
|
||||
settings.AddTorrent(t)
|
||||
}
|
||||
|
||||
func GetTorrent(hash metainfo.Hash) *torr.Torrent {
|
||||
list := settings.ListTorrent()
|
||||
for _, db := range list {
|
||||
if hash == db.InfoHash {
|
||||
torr := new(torr.Torrent)
|
||||
torr.TorrentSpec = db.TorrentSpec
|
||||
torr.Title = db.Title
|
||||
torr.Poster = db.Poster
|
||||
return torr
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func RemTorrent(hash metainfo.Hash) {
|
||||
settings.RemTorrent(hash)
|
||||
}
|
||||
|
||||
func ListTorrents() []*torr.Torrent {
|
||||
var ret []*torr.Torrent
|
||||
list := settings.ListTorrent()
|
||||
for _, db := range list {
|
||||
torr := new(torr.Torrent)
|
||||
torr.TorrentSpec = db.TorrentSpec
|
||||
torr.Title = db.Title
|
||||
torr.Poster = db.Poster
|
||||
ret = append(ret, torr)
|
||||
}
|
||||
return ret
|
||||
}
|
||||
Reference in New Issue
Block a user