mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-07 09:00:47 +00:00
feat: support custom tracker url (#59)
This commit is contained in:
1 parent
9ef3405e43
commit
691c2f496e
71 files changed
+2209
-891
No files matched your search
+18
-12
@@ -5,40 +5,46 @@ import (
|
||||
"github.com/monkeyWie/gopeed/pkg/base"
|
||||
)
|
||||
|
||||
// 对应协议的下载支持
|
||||
// Fetcher defines the interface for a download protocol.
|
||||
type Fetcher interface {
|
||||
Setup(ctl controller.Controller) error
|
||||
// 解析请求
|
||||
// Name return the name of the protocol.
|
||||
Name() string
|
||||
|
||||
Setup(ctl *controller.Controller) error
|
||||
// Resolve resource info from request
|
||||
Resolve(req *base.Request) (res *base.Resource, err error)
|
||||
// 创建任务
|
||||
// Create ready to download, but not started
|
||||
Create(res *base.Resource, opts *base.Options) (err error)
|
||||
Start() (err error)
|
||||
Pause() (err error)
|
||||
Continue() (err error)
|
||||
Close() (err error)
|
||||
|
||||
// 获取任务各个文件下载进度
|
||||
// Progress returns the progress of the download.
|
||||
Progress() Progress
|
||||
// 该方法会一直阻塞,直到任务下载结束
|
||||
// Wait for the download to complete, this method will block until the download is done.
|
||||
Wait() (err error)
|
||||
}
|
||||
|
||||
// FetcherBuilder defines the interface for a fetcher builder.
|
||||
type FetcherBuilder interface {
|
||||
// Schemes returns the schemes supported by the fetcher.
|
||||
Schemes() []string
|
||||
// Build returns a new fetcher.
|
||||
Build() Fetcher
|
||||
|
||||
// Store 存储任务
|
||||
// Store fetcher
|
||||
Store(fetcher Fetcher) (any, error)
|
||||
// Restore 恢复任务
|
||||
// Restore fetcher
|
||||
Restore() (v any, f func(res *base.Resource, opts *base.Options, v any) Fetcher)
|
||||
}
|
||||
|
||||
type DefaultFetcher struct {
|
||||
Ctl controller.Controller
|
||||
Ctl *controller.Controller
|
||||
DoneCh chan error
|
||||
}
|
||||
|
||||
func (f *DefaultFetcher) Setup(ctl controller.Controller) (err error) {
|
||||
func (f *DefaultFetcher) Setup(ctl *controller.Controller) (err error) {
|
||||
f.Ctl = ctl
|
||||
f.DoneCh = make(chan error, 1)
|
||||
return
|
||||
@@ -48,10 +54,10 @@ func (f *DefaultFetcher) Wait() (err error) {
|
||||
return <-f.DoneCh
|
||||
}
|
||||
|
||||
// 获取任务中各个文件的已下载字节数
|
||||
// Progress is a map of the progress of each file in the torrent.
|
||||
type Progress []int64
|
||||
|
||||
// TotalDownloaded 获取任务总下载字节数
|
||||
// TotalDownloaded returns the total downloaded bytes.
|
||||
func (p Progress) TotalDownloaded() int64 {
|
||||
total := int64(0)
|
||||
for _, d := range p {
|
||||
|
||||
Reference in new issue
Block a user