2023-10-05 05:38:35 +00:00
|
|
|
package tool
|
2023-10-04 08:27:08 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
"os"
|
2023-10-04 12:59:11 +00:00
|
|
|
"time"
|
2023-10-04 08:27:08 +00:00
|
|
|
|
|
|
|
"github.com/alist-org/alist/v3/internal/model"
|
|
|
|
)
|
|
|
|
|
2023-10-05 14:13:02 +00:00
|
|
|
type AddUrlArgs struct {
|
|
|
|
Url string
|
2023-10-04 08:27:08 +00:00
|
|
|
UID string
|
|
|
|
TempDir string
|
|
|
|
Signal chan int
|
|
|
|
}
|
|
|
|
|
|
|
|
type Status struct {
|
2023-10-04 12:59:11 +00:00
|
|
|
Progress float64
|
2023-10-04 08:27:08 +00:00
|
|
|
NewTID string
|
|
|
|
Completed bool
|
|
|
|
Status string
|
|
|
|
Err error
|
|
|
|
}
|
|
|
|
|
|
|
|
type Tool interface {
|
|
|
|
// Items return the setting items the tool need
|
|
|
|
Items() []model.SettingItem
|
|
|
|
Init() (string, error)
|
|
|
|
IsReady() bool
|
2023-10-05 14:13:02 +00:00
|
|
|
// AddURL add an uri to download, return the task id
|
|
|
|
AddURL(args *AddUrlArgs) (string, error)
|
2023-10-04 14:23:45 +00:00
|
|
|
// Remove the download if task been canceled
|
2023-10-04 08:27:08 +00:00
|
|
|
Remove(tid string) error
|
|
|
|
// Status return the status of the download task, if an error occurred, return the error in Status.Err
|
|
|
|
Status(tid string) (*Status, error)
|
2023-10-05 14:13:02 +00:00
|
|
|
// GetFiles return the files of the download task, if nil, means walk the temp dir to get the files
|
|
|
|
GetFiles(tid string) []File
|
2023-10-04 08:27:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type File struct {
|
2023-10-05 14:13:02 +00:00
|
|
|
// ReadCloser for http client
|
2023-10-04 08:27:08 +00:00
|
|
|
io.ReadCloser
|
2023-10-04 12:59:11 +00:00
|
|
|
Name string
|
|
|
|
Size int64
|
|
|
|
Path string
|
|
|
|
Modified time.Time
|
2023-10-04 08:27:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (f *File) GetReadCloser() (io.ReadCloser, error) {
|
|
|
|
if f.ReadCloser != nil {
|
|
|
|
return f.ReadCloser, nil
|
|
|
|
}
|
|
|
|
file, err := os.Open(f.Path)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return file, nil
|
|
|
|
}
|