mirror of
https://github.com/Ernous/TorrServerJellyfin.git
synced 2025-12-19 21:46:11 +05:00
add torrent storage capacity func
This commit is contained in:
@@ -6,7 +6,7 @@ import (
|
|||||||
"server/torr/storage"
|
"server/torr/storage"
|
||||||
|
|
||||||
"github.com/anacrolix/torrent/metainfo"
|
"github.com/anacrolix/torrent/metainfo"
|
||||||
storage2 "github.com/anacrolix/torrent/storage"
|
ts "github.com/anacrolix/torrent/storage"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Storage struct {
|
type Storage struct {
|
||||||
@@ -24,16 +24,20 @@ func NewStorage(capacity int64) *Storage {
|
|||||||
return stor
|
return stor
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Storage) OpenTorrent(info *metainfo.Info, infoHash metainfo.Hash) (storage2.TorrentImpl, error) {
|
func (s *Storage) OpenTorrent(info *metainfo.Info, infoHash metainfo.Hash) (ts.TorrentImpl, error) {
|
||||||
|
capFunc := func() (int64, bool) {
|
||||||
|
return s.capacity, true
|
||||||
|
}
|
||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
defer s.mu.Unlock()
|
defer s.mu.Unlock()
|
||||||
ch := NewCache(s.capacity, s)
|
ch := NewCache(s.capacity, s)
|
||||||
ch.Init(info, infoHash)
|
ch.Init(info, infoHash)
|
||||||
s.caches[infoHash] = ch
|
s.caches[infoHash] = ch
|
||||||
// return ch, nil
|
// return ch, nil
|
||||||
return storage2.TorrentImpl{
|
return ts.TorrentImpl{
|
||||||
Piece: ch.Piece,
|
Piece: ch.Piece,
|
||||||
Close: ch.Close,
|
Close: ch.Close,
|
||||||
|
Capacity: &capFunc,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user