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