feat: support RESTful api (#33)

This commit is contained in:
monkeyWie authored and GitHub committed 2022-09-09 18:31:57 +08:00
1 parent e292926697
commit c6aa83194f
22 files changed
+603 -125

No files matched your search

+6 -13
View File
@@ -1,16 +1,13 @@
package base
import "errors"
type Status int
type Status string
const (
DownloadStatusPrepare Status = iota
DownloadStatusReady
DownloadStatusStart
DownloadStatusPause
DownloadStatusError
DownloadStatusDone
DownloadStatusReady Status = "ready"
DownloadStatusRunning Status = "running"
DownloadStatusPause Status = "pause"
DownloadStatusError Status = "error"
DownloadStatusDone Status = "done"
)
const (
@@ -24,7 +21,3 @@ const (
HttpHeaderRangeFormat = "bytes=%d-%d"
)
var (
DeleteErr = errors.New("delete")
)
+14 -16
View File
@@ -3,38 +3,36 @@ package base
// 下载请求
type Request struct {
// 下载链接
Schema string
// 下载链接
URL string
URL string `json:"url"`
// 附加信息
Extra interface{}
Extra interface{} `json:"extra"`
}
// 资源信息
type Resource struct {
Req *Request
Req *Request `json:"req"`
// 资源总大小
Length int64
Size int64 `json:"size"`
// 是否支持断点下载
Range bool
Range bool `json:"range"`
// 资源所包含的文件列表
Files []*FileInfo
Files []*FileInfo `json:"files"`
}
type FileInfo struct {
Name string
Path string
Size int64
Name string `json:"name"`
Path string `json:"path"`
Size int64 `json:"size"`
}
// 下载选项
type Options struct {
// 保存文件名
Name string
Name string `json:"name"`
// 保存目录
Path string
Path string `json:"path"`
// 并发连接数
Connections int
// 下载的文件下标列表
SelectFiles []int
Connections int `json:"connections"`
// 选择下载的文件下标列表
SelectFiles []int `json:"select_files"`
}