mirror of
https://github.com/Ernous/TorrServerJellyfin.git
synced 2025-12-19 13:36:09 +05:00
refactor expired time
This commit is contained in:
@@ -54,7 +54,7 @@ func GetTorrent(hashHex string) *Torrent {
|
||||
hash := metainfo.NewHashFromHex(hashHex)
|
||||
tor := bts.GetTorrent(hash)
|
||||
if tor != nil {
|
||||
tor.expiredTime = time.Now().Add(time.Minute)
|
||||
tor.AddExpiredTime(time.Minute)
|
||||
return tor
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
sync "github.com/sasha-s/go-deadlock"
|
||||
"sync"
|
||||
|
||||
"server/log"
|
||||
"server/settings"
|
||||
@@ -84,7 +84,7 @@ func NewTorrent(spec *torrent.TorrentSpec, bt *BTServer) (*Torrent, error) {
|
||||
torr.bt = bt
|
||||
torr.closed = goTorrent.Closed()
|
||||
torr.TorrentSpec = spec
|
||||
torr.expiredTime = time.Now().Add(time.Minute)
|
||||
torr.AddExpiredTime(time.Minute)
|
||||
torr.Timestamp = time.Now().Unix()
|
||||
|
||||
go torr.watch()
|
||||
@@ -120,7 +120,7 @@ func (t *Torrent) GotInfo() bool {
|
||||
t.Stat = state.TorrentGettingInfo
|
||||
if t.WaitInfo() {
|
||||
t.Stat = state.TorrentWorking
|
||||
t.expiredTime = time.Now().Add(time.Minute * 5)
|
||||
t.AddExpiredTime(time.Minute * 5)
|
||||
return true
|
||||
} else {
|
||||
t.Close()
|
||||
@@ -128,6 +128,10 @@ func (t *Torrent) GotInfo() bool {
|
||||
}
|
||||
}
|
||||
|
||||
func (t *Torrent) AddExpiredTime(duration time.Duration) {
|
||||
t.expiredTime = time.Now().Add(duration)
|
||||
}
|
||||
|
||||
func (t *Torrent) watch() {
|
||||
t.progressTicker = time.NewTicker(time.Second)
|
||||
defer t.progressTicker.Stop()
|
||||
@@ -228,7 +232,7 @@ func (t *Torrent) NewReader(file *torrent.File) *torrstor.Reader {
|
||||
|
||||
func (t *Torrent) CloseReader(reader *torrstor.Reader) {
|
||||
t.cache.CloseReader(reader)
|
||||
t.expiredTime = time.Now().Add(time.Second * time.Duration(settings.BTsets.TorrentDisconnectTimeout))
|
||||
t.AddExpiredTime(time.Second * time.Duration(settings.BTsets.TorrentDisconnectTimeout))
|
||||
}
|
||||
|
||||
func (t *Torrent) GetCache() *torrstor.Cache {
|
||||
|
||||
Reference in New Issue
Block a user