616c6b1c62
Release Docker multi arch / docker (push) Has been cancelled
Test Install Script / Test Script Syntax (push) Has been cancelled
Test Install Script / Test on almalinux-10 (default) (push) Has been cancelled
Test Install Script / Test on almalinux-10 (root) (push) Has been cancelled
Test Install Script / Test on almalinux-8 (default) (push) Has been cancelled
Test Install Script / Test on almalinux-8 (root) (push) Has been cancelled
Test Install Script / Test on almalinux-9 (default) (push) Has been cancelled
Test Install Script / Test on almalinux-9 (root) (push) Has been cancelled
Test Install Script / Test on amazonlinux-2 (default) (push) Has been cancelled
Test Install Script / Test on amazonlinux-2 (root) (push) Has been cancelled
Test Install Script / Test on debian-11 (default) (push) Has been cancelled
Test Install Script / Test on debian-11 (root) (push) Has been cancelled
Test Install Script / Test on debian-12 (default) (push) Has been cancelled
Test Install Script / Test on debian-12 (root) (push) Has been cancelled
Test Install Script / Test on debian-13 (default) (push) Has been cancelled
Test Install Script / Test on debian-13 (root) (push) Has been cancelled
Test Install Script / Test on fedora-latest (default) (push) Has been cancelled
Test Install Script / Test on fedora-latest (root) (push) Has been cancelled
Test Install Script / Test on rocky-10 (default) (push) Has been cancelled
Test Install Script / Test on rocky-10 (root) (push) Has been cancelled
Test Install Script / Test on rocky-8 (default) (push) Has been cancelled
Test Install Script / Test on rocky-8 (root) (push) Has been cancelled
Test Install Script / Test on rocky-9 (default) (push) Has been cancelled
Test Install Script / Test on rocky-9 (root) (push) Has been cancelled
Test Install Script / Test on ubuntu-22.04 (default) (push) Has been cancelled
Test Install Script / Test on ubuntu-22.04 (root) (push) Has been cancelled
Test Install Script / Test on ubuntu-24.04 (default) (push) Has been cancelled
Test Install Script / Test on ubuntu-24.04 (root) (push) Has been cancelled
87 lines
1.6 KiB
Go
87 lines
1.6 KiB
Go
package settings
|
|
|
|
import (
|
|
"encoding/json"
|
|
"sort"
|
|
"sync"
|
|
|
|
"github.com/anacrolix/torrent"
|
|
"github.com/anacrolix/torrent/metainfo"
|
|
)
|
|
|
|
type TorrentDB struct {
|
|
*torrent.TorrentSpec
|
|
|
|
Title string `json:"title,omitempty"`
|
|
Category string `json:"category,omitempty"`
|
|
Poster string `json:"poster,omitempty"`
|
|
Data string `json:"data,omitempty"`
|
|
|
|
Timestamp int64 `json:"timestamp,omitempty"`
|
|
Size int64 `json:"size,omitempty"`
|
|
}
|
|
|
|
type File struct {
|
|
Name string `json:"name,omitempty"`
|
|
Id int `json:"id,omitempty"`
|
|
Size int64 `json:"size,omitempty"`
|
|
}
|
|
|
|
var mu sync.Mutex
|
|
|
|
func AddTorrent(torr *TorrentDB) {
|
|
list := ListTorrent()
|
|
mu.Lock()
|
|
find := -1
|
|
for i, db := range list {
|
|
if db.InfoHash.HexString() == torr.InfoHash.HexString() {
|
|
find = i
|
|
break
|
|
}
|
|
}
|
|
if find != -1 {
|
|
list[find] = torr
|
|
} else {
|
|
list = append(list, torr)
|
|
}
|
|
for _, db := range list {
|
|
buf, err := json.Marshal(db)
|
|
if err == nil {
|
|
tdb.Set("Torrents", db.InfoHash.HexString(), buf)
|
|
}
|
|
}
|
|
mu.Unlock()
|
|
}
|
|
|
|
func ListTorrent() []*TorrentDB {
|
|
// Use read lock to prevent migration during read
|
|
dbMigrationLock.RLock()
|
|
defer dbMigrationLock.RUnlock()
|
|
|
|
mu.Lock()
|
|
defer mu.Unlock()
|
|
|
|
var list []*TorrentDB
|
|
keys := tdb.List("Torrents")
|
|
for _, key := range keys {
|
|
buf := tdb.Get("Torrents", key)
|
|
if len(buf) > 0 {
|
|
var torr *TorrentDB
|
|
err := json.Unmarshal(buf, &torr)
|
|
if err == nil {
|
|
list = append(list, torr)
|
|
}
|
|
}
|
|
}
|
|
sort.Slice(list, func(i, j int) bool {
|
|
return list[i].Timestamp > list[j].Timestamp
|
|
})
|
|
return list
|
|
}
|
|
|
|
func RemTorrent(hash metainfo.Hash) {
|
|
mu.Lock()
|
|
tdb.Rem("Torrents", hash.HexString())
|
|
mu.Unlock()
|
|
}
|