feat: support custom tracker url (#59)

This commit is contained in:
Li Wei authored and GitHub committed 2022-12-12 15:58:11 +08:00
1 parent 9ef3405e43
commit 691c2f496e
71 files changed
+2209 -891

No files matched your search

+8
View File
@@ -0,0 +1,8 @@
package base
import "errors"
var (
NotFound = errors.New("not found")
BadParams = errors.New("bad params")
)
+37 -5
View File
@@ -1,11 +1,13 @@
package base
import "github.com/monkeyWie/gopeed/pkg/util"
// 下载请求
type Request struct {
// 下载链接
URL string `json:"url"`
// 附加信息
Extra interface{} `json:"extra"`
Extra any `json:"extra"`
}
// 资源信息
@@ -19,8 +21,8 @@ type Resource struct {
Range bool `json:"range"`
// 资源所包含的文件列表
Files []*FileInfo `json:"files"`
// 附加信息
Extra interface{} `json:"extra"`
// 资源hash值
Hash string `json:"hash"`
}
type FileInfo struct {
@@ -35,8 +37,38 @@ type Options struct {
Name string `json:"name"`
// 保存目录
Path string `json:"path"`
// 并发连接数
Connections int `json:"connections"`
// 选择下载的文件下标列表
SelectFiles []int `json:"selectFiles"`
// 附加信息
Extra any `json:"extra"`
}
func ParseReqExtra[E any](req *Request) error {
if req.Extra == nil {
return nil
}
if _, ok := req.Extra.(*E); ok {
return nil
}
var t E
if err := util.MapToStruct(req.Extra, &t); err != nil {
return err
}
req.Extra = &t
return nil
}
func ParseOptsExtra[E any](opts *Options) error {
if opts.Extra == nil {
return nil
}
if _, ok := opts.Extra.(*E); ok {
return nil
}
var t E
if err := util.MapToStruct(opts.Extra, &t); err != nil {
return err
}
opts.Extra = &t
return nil
}