tool

package
v3.34.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 2, 2024 License: AGPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DownloadTaskManager *tache.Manager[*DownloadTask]
)
View Source
var (
	Tools = make(ToolsManager)
)
View Source
var (
	TransferTaskManager *tache.Manager[*TransferTask]
)

Functions

func AddURL

func AddURL(ctx context.Context, args *AddURLArgs) (tache.TaskWithInfo, error)

Types

type AddURLArgs

type AddURLArgs struct {
	URL          string
	DstDirPath   string
	Tool         string
	DeletePolicy DeletePolicy
}

type AddUrlArgs

type AddUrlArgs struct {
	Url     string
	UID     string
	TempDir string
	Signal  chan int
}

type DeletePolicy

type DeletePolicy string
const (
	DeleteOnUploadSucceed DeletePolicy = "delete_on_upload_succeed"
	DeleteOnUploadFailed  DeletePolicy = "delete_on_upload_failed"
	DeleteNever           DeletePolicy = "delete_never"
	DeleteAlways          DeletePolicy = "delete_always"
)

type DownloadTask

type DownloadTask struct {
	tache.Base
	Url          string       `json:"url"`
	DstDirPath   string       `json:"dst_dir_path"`
	TempDir      string       `json:"temp_dir"`
	DeletePolicy DeletePolicy `json:"delete_policy"`

	Status string   `json:"status"`
	Signal chan int `json:"-"`
	GID    string   `json:"-"`
	// contains filtered or unexported fields
}

func (*DownloadTask) Complete

func (t *DownloadTask) Complete() error

func (*DownloadTask) GetName

func (t *DownloadTask) GetName() string

func (*DownloadTask) GetStatus

func (t *DownloadTask) GetStatus() string

func (*DownloadTask) Run

func (t *DownloadTask) Run() error

func (*DownloadTask) Update

func (t *DownloadTask) Update() (bool, error)

Update download status, return true if download completed

type File

type File struct {
	// ReadCloser for http client
	ReadCloser io.ReadCloser
	Name       string
	Size       int64
	Path       string
	Modified   time.Time
}

func GetFiles

func GetFiles(dir string) ([]File, error)

func (*File) GetReadCloser

func (f *File) GetReadCloser() (io.ReadCloser, error)

type GetFileser

type GetFileser interface {
	// GetFiles return the files of the download task, if nil, means walk the temp dir to get the files
	GetFiles(task *DownloadTask) []File
}

type Status

type Status struct {
	Progress  float64
	NewGID    string
	Completed bool
	Status    string
	Err       error
}

type Tool

type Tool interface {
	Name() string
	// Items return the setting items the tool need
	Items() []model.SettingItem
	Init() (string, error)
	IsReady() bool
	// AddURL add an uri to download, return the task id
	AddURL(args *AddUrlArgs) (string, error)
	// Remove the download if task been canceled
	Remove(task *DownloadTask) error
	// Status return the status of the download task, if an error occurred, return the error in Status.Err
	Status(task *DownloadTask) (*Status, error)

	// Run for simple http download
	Run(task *DownloadTask) error
}

type ToolsManager

type ToolsManager map[string]Tool

func (ToolsManager) Add

func (t ToolsManager) Add(tool Tool)

func (ToolsManager) Get

func (t ToolsManager) Get(name string) (Tool, error)

func (ToolsManager) Items

func (t ToolsManager) Items() []model.SettingItem

func (ToolsManager) Names

func (t ToolsManager) Names() []string

type TransferTask

type TransferTask struct {
	tache.Base
	// contains filtered or unexported fields
}

func (*TransferTask) GetName

func (t *TransferTask) GetName() string

func (*TransferTask) GetStatus

func (t *TransferTask) GetStatus() string

func (*TransferTask) OnFailed

func (t *TransferTask) OnFailed()

func (*TransferTask) OnSucceeded

func (t *TransferTask) OnSucceeded()

func (*TransferTask) Run

func (t *TransferTask) Run() error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL