Documentation ¶
Index ¶
- Constants
- Variables
- func Init(isReload bool)
- func NewMonitor(task *model.Download)
- type Aria2
- type DummyAria2
- func (instance *DummyAria2) Cancel(task *model.Download) error
- func (instance *DummyAria2) CreateTask(model *model.Download, options map[string]interface{}) error
- func (instance *DummyAria2) Select(task *model.Download, files []int) error
- func (instance *DummyAria2) Status(task *model.Download) (rpc.StatusInfo, error)
- type Monitor
- func (monitor *Monitor) Complete(status rpc.StatusInfo) bool
- func (monitor *Monitor) Error(status rpc.StatusInfo) bool
- func (monitor *Monitor) Loop()
- func (monitor *Monitor) RemoveTempFolder()
- func (monitor *Monitor) Update() bool
- func (monitor *Monitor) UpdateTaskInfo(status rpc.StatusInfo) error
- func (monitor *Monitor) ValidateFile() error
- type Notifier
- func (notifier *Notifier) Notify(events []rpc.Event, status int)
- func (notifier *Notifier) OnBtDownloadComplete(events []rpc.Event)
- func (notifier *Notifier) OnDownloadComplete(events []rpc.Event)
- func (notifier *Notifier) OnDownloadError(events []rpc.Event)
- func (notifier *Notifier) OnDownloadPause(events []rpc.Event)
- func (notifier *Notifier) OnDownloadStart(events []rpc.Event)
- func (notifier *Notifier) OnDownloadStop(events []rpc.Event)
- func (notifier *Notifier) Subscribe(target chan StatusEvent, gid string)
- func (notifier *Notifier) Unsubscribe(gid string)
- type RPCService
- func (client *RPCService) Cancel(task *model.Download) error
- func (client *RPCService) CreateTask(task *model.Download, groupOptions map[string]interface{}) error
- func (client *RPCService) Init(server, secret string, timeout int, options map[string]interface{}) error
- func (client *RPCService) Select(task *model.Download, files []int) error
- func (client *RPCService) Status(task *model.Download) (rpc.StatusInfo, error)
- type StatusEvent
Constants ¶
View Source
const ( // URLTask 从URL添加的任务 URLTask = iota // TorrentTask 种子任务 TorrentTask )
View Source
const ( // Ready 准备就绪 Ready = iota // Downloading 下载中 Downloading // Paused 暂停中 Paused // Error 出错 Error // Complete 完成 Complete // Canceled 取消/停止 Canceled // Unknown 未知状态 Unknown )
Variables ¶
View Source
var ( // ErrNotEnabled 功能未开启错误 ErrNotEnabled = serializer.NewError(serializer.CodeNoPermissionErr, "离线下载功能未开启", nil) // ErrUserNotFound 未找到下载任务创建者 ErrUserNotFound = serializer.NewError(serializer.CodeNotFound, "无法找到任务创建者", nil) )
View Source
var EventNotifier = &Notifier{}
EventNotifier 任务状态更新通知处理器
View Source
var Lock sync.RWMutex
Lock Instance的读写锁
View Source
var MAX_RETRY = 10
Functions ¶
Types ¶
type Aria2 ¶
type Aria2 interface { // CreateTask 创建新的任务 CreateTask(task *model.Download, options map[string]interface{}) error // 返回状态信息 Status(task *model.Download) (rpc.StatusInfo, error) // 取消任务 Cancel(task *model.Download) error // 选择要下载的文件 Select(task *model.Download, files []int) error }
Aria2 离线下载处理接口
var Instance Aria2 = &DummyAria2{}
Instance 默认使用的Aria2处理实例
type DummyAria2 ¶
type DummyAria2 struct { }
DummyAria2 未开启Aria2功能时使用的默认处理器
func (*DummyAria2) Cancel ¶
func (instance *DummyAria2) Cancel(task *model.Download) error
Cancel 返回未开启错误
func (*DummyAria2) CreateTask ¶
func (instance *DummyAria2) CreateTask(model *model.Download, options map[string]interface{}) error
CreateTask 创建新任务,此处直接返回未开启错误
func (*DummyAria2) Select ¶
func (instance *DummyAria2) Select(task *model.Download, files []int) error
Select 返回未开启错误
func (*DummyAria2) Status ¶
func (instance *DummyAria2) Status(task *model.Download) (rpc.StatusInfo, error)
Status 返回未开启错误
type Monitor ¶
type Monitor struct { Task *model.Download Interval time.Duration // contains filtered or unexported fields }
Monitor 离线下载状态监控
func (*Monitor) Complete ¶
func (monitor *Monitor) Complete(status rpc.StatusInfo) bool
Complete 完成下载,返回是否中断监控
func (*Monitor) Error ¶
func (monitor *Monitor) Error(status rpc.StatusInfo) bool
Error 任务下载出错处理,返回是否中断监控
func (*Monitor) RemoveTempFolder ¶
func (monitor *Monitor) RemoveTempFolder()
RemoveTempFolder 清理下载临时目录
func (*Monitor) UpdateTaskInfo ¶
func (monitor *Monitor) UpdateTaskInfo(status rpc.StatusInfo) error
UpdateTaskInfo 更新数据库中的任务信息
func (*Monitor) ValidateFile ¶
ValidateFile 上传过程中校验文件大小、文件名
type Notifier ¶
Notifier aria2实践通知处理
func (*Notifier) OnBtDownloadComplete ¶
OnBtDownloadComplete BT下载完成
func (*Notifier) OnDownloadComplete ¶
OnDownloadComplete 下载完成
func (*Notifier) OnDownloadError ¶
OnDownloadError 下载出错
func (*Notifier) OnDownloadPause ¶
OnDownloadPause 下载暂停
func (*Notifier) OnDownloadStart ¶
OnDownloadStart 下载开始
func (*Notifier) OnDownloadStop ¶
OnDownloadStop 下载停止
func (*Notifier) Subscribe ¶
func (notifier *Notifier) Subscribe(target chan StatusEvent, gid string)
Subscribe 订阅事件通知
func (*Notifier) Unsubscribe ¶
Unsubscribe 取消订阅事件通知
type RPCService ¶
RPCService 通过RPC服务的Aria2任务管理器
func (*RPCService) Cancel ¶
func (client *RPCService) Cancel(task *model.Download) error
Cancel 取消下载
func (*RPCService) CreateTask ¶
func (client *RPCService) CreateTask(task *model.Download, groupOptions map[string]interface{}) error
CreateTask 创建新任务
func (*RPCService) Init ¶
func (client *RPCService) Init(server, secret string, timeout int, options map[string]interface{}) error
Init 初始化
func (*RPCService) Select ¶
func (client *RPCService) Select(task *model.Download, files []int) error
Select 选取要下载的文件
func (*RPCService) Status ¶
func (client *RPCService) Status(task *model.Download) (rpc.StatusInfo, error)
Status 查询下载状态
Click to show internal directories.
Click to hide internal directories.