Documentation
¶
Index ¶
- func AuthMiddleware() func(http.Handler) http.Handler
- func DeleteTask(taskID string)
- func ExtractFilesFromLinks(ctx context.Context, links []string) ([]tfile.TGFileMessage, error)
- func ExtractTelegraphImages(ctx context.Context, pageURL string) ([]string, string, error)
- func MethodNotAllowedHandler(w http.ResponseWriter, r *http.Request)
- func NotFoundHandler(w http.ResponseWriter, r *http.Request)
- func ParseMessageLink(ctx context.Context, link string) (int64, int, error)
- func SendWebhook(ctx context.Context, payload *WebhookPayload)
- func Start(ctx context.Context) error
- func WrapTaskWithWebhook(ctx context.Context, taskID string, fn func() error) error
- func WriteError(w http.ResponseWriter, statusCode int, errCode, message string) error
- func WriteJSON(w http.ResponseWriter, statusCode int, data any) error
- type APIError
- type Aria2Params
- type CreateTaskRequest
- type CreateTaskResponse
- type DirectLinksParams
- type ErrorResponse
- type Handlers
- func (h *Handlers) CancelTaskHandler(w http.ResponseWriter, r *http.Request)
- func (h *Handlers) CreateTaskHandler(w http.ResponseWriter, r *http.Request)
- func (h *Handlers) GetTaskHandler(w http.ResponseWriter, r *http.Request)
- func (h *Handlers) GetTaskTypesHandler(w http.ResponseWriter, r *http.Request)
- func (h *Handlers) HealthCheckHandler(w http.ResponseWriter, r *http.Request)
- func (h *Handlers) ListStoragesHandler(w http.ResponseWriter, r *http.Request)
- func (h *Handlers) ListTasksHandler(w http.ResponseWriter, r *http.Request)
- type MessageContext
- type ParsedParams
- type ProgressTracker
- func (p *ProgressTracker) GetInfo() *TaskProgressInfo
- func (p *ProgressTracker) OnDone(err error)
- func (p *ProgressTracker) OnProgress(downloadedBytes int64, downloadedFiles int)
- func (p *ProgressTracker) OnStart(totalBytes int64, totalFiles int)
- func (p *ProgressTracker) UpdateProgressBytes(bytes int64)
- func (p *ProgressTracker) UpdateProgressFiles(files int)
- type Server
- type StorageInfo
- type StoragesResponse
- type TGFilesParams
- type TPHPicsParams
- type TaskFactory
- type TaskInfoResponse
- type TaskProgress
- type TaskProgressInfo
- type TaskStatus
- type TasksListResponse
- type TransferParams
- type WebhookPayload
- type YTDLPParams
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractFilesFromLinks ¶
ExtractFilesFromLinks 从消息链接中提取文件 每个文件的处理流程:解析链接 -> 获取消息 -> 获取媒体组 -> 创建文件对象 对于单个文件,全程使用同一个 client context,不会交叉
func ExtractTelegraphImages ¶
ExtractTelegraphImages 从 Telegraph URL 提取图片
func MethodNotAllowedHandler ¶
func MethodNotAllowedHandler(w http.ResponseWriter, r *http.Request)
MethodNotAllowedHandler 405 处理器
func NotFoundHandler ¶
func NotFoundHandler(w http.ResponseWriter, r *http.Request)
NotFoundHandler 404 处理器
func ParseMessageLink ¶
ParseMessageLink 解析 Telegram 消息链接 支持格式: - https://t.me/username/123 - https://t.me/c/123456789/123 - https://t.me/c/123456789/111/456 (topic id) - https://t.me/username/123?comment=2 (评论)
func SendWebhook ¶
func SendWebhook(ctx context.Context, payload *WebhookPayload)
SendWebhook 发送 Webhook 回调
func WrapTaskWithWebhook ¶
WrapTaskWithWebhook 包装任务执行,添加 webhook 回调
func WriteError ¶
func WriteError(w http.ResponseWriter, statusCode int, errCode, message string) error
WriteError 写入错误响应
Types ¶
type Aria2Params ¶
type Aria2Params struct {
URLs []string `json:"urls"`
Options map[string]string `json:"options,omitempty"`
}
Aria2Params aria2 任务参数
type CreateTaskRequest ¶
type CreateTaskRequest struct {
Type tasktype.TaskType `json:"type"`
Storage string `json:"storage"`
Path string `json:"path"`
Webhook string `json:"webhook,omitempty"`
Params json.RawMessage `json:"params"`
}
CreateTaskRequest 创建任务请求
type CreateTaskResponse ¶
type CreateTaskResponse struct {
TaskID string `json:"task_id"`
Type tasktype.TaskType `json:"type"`
Status TaskStatus `json:"status"`
CreatedAt time.Time `json:"created_at"`
}
CreateTaskResponse 创建任务响应
type DirectLinksParams ¶
type DirectLinksParams struct {
URLs []string `json:"urls"`
}
DirectLinksParams directlinks 任务参数
type ErrorResponse ¶
ErrorResponse 错误响应
type Handlers ¶
type Handlers struct {
// contains filtered or unexported fields
}
Handlers 处理器结构体
func (*Handlers) CancelTaskHandler ¶
func (h *Handlers) CancelTaskHandler(w http.ResponseWriter, r *http.Request)
CancelTaskHandler 取消任务处理器
func (*Handlers) CreateTaskHandler ¶
func (h *Handlers) CreateTaskHandler(w http.ResponseWriter, r *http.Request)
CreateTaskHandler 创建任务处理器
func (*Handlers) GetTaskHandler ¶
func (h *Handlers) GetTaskHandler(w http.ResponseWriter, r *http.Request)
GetTaskHandler 获取单个任务处理器
func (*Handlers) GetTaskTypesHandler ¶
func (h *Handlers) GetTaskTypesHandler(w http.ResponseWriter, r *http.Request)
GetTaskTypesHandler 获取支持的任务类型
func (*Handlers) HealthCheckHandler ¶
func (h *Handlers) HealthCheckHandler(w http.ResponseWriter, r *http.Request)
HealthCheckHandler 健康检查处理器
func (*Handlers) ListStoragesHandler ¶
func (h *Handlers) ListStoragesHandler(w http.ResponseWriter, r *http.Request)
ListStoragesHandler 列出存储处理器
func (*Handlers) ListTasksHandler ¶
func (h *Handlers) ListTasksHandler(w http.ResponseWriter, r *http.Request)
ListTasksHandler 列出任务处理器
type MessageContext ¶
MessageContext 保存消息和获取它所用的 context
type ProgressTracker ¶
type ProgressTracker struct {
// contains filtered or unexported fields
}
ProgressTracker 用于 API 任务的进度追踪
func NewProgressTracker ¶
func NewProgressTracker(taskID, taskType, storage, path, title, webhook string) *ProgressTracker
NewProgressTracker 创建新的进度追踪器
func (*ProgressTracker) GetInfo ¶
func (p *ProgressTracker) GetInfo() *TaskProgressInfo
GetInfo 获取任务信息
func (*ProgressTracker) OnProgress ¶
func (p *ProgressTracker) OnProgress(downloadedBytes int64, downloadedFiles int)
OnProgress 进度更新
func (*ProgressTracker) OnStart ¶
func (p *ProgressTracker) OnStart(totalBytes int64, totalFiles int)
OnStart 任务开始
func (*ProgressTracker) UpdateProgressBytes ¶
func (p *ProgressTracker) UpdateProgressBytes(bytes int64)
UpdateProgressBytes 更新下载字节数
func (*ProgressTracker) UpdateProgressFiles ¶
func (p *ProgressTracker) UpdateProgressFiles(files int)
UpdateProgressFiles 更新下载文件数
type StorageInfo ¶
StorageInfo 存储信息
type StoragesResponse ¶
type StoragesResponse struct {
Storages []StorageInfo `json:"storages"`
}
StoragesResponse 存储列表响应
type TGFilesParams ¶
type TGFilesParams struct {
MessageLinks []string `json:"message_links"`
}
TGFilesParams tgfiles 任务参数
type TPHPicsParams ¶
type TPHPicsParams struct {
TelegraphURL string `json:"telegraph_url"`
}
TPHPicsParams tphpics 任务参数
type TaskFactory ¶
type TaskFactory struct {
// contains filtered or unexported fields
}
TaskFactory 任务工厂
func (*TaskFactory) CreateTask ¶
func (f *TaskFactory) CreateTask(req *CreateTaskRequest) (*CreateTaskResponse, error)
CreateTask 创建任务
type TaskInfoResponse ¶
type TaskInfoResponse struct {
TaskID string `json:"task_id"`
Type tasktype.TaskType `json:"type"`
Status TaskStatus `json:"status"`
Title string `json:"title"`
Progress *TaskProgress `json:"progress,omitempty"`
Storage string `json:"storage"`
Path string `json:"path"`
Error string `json:"error,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
TaskInfoResponse 任务信息响应
type TaskProgress ¶
type TaskProgress struct {
TotalBytes int64 `json:"total_bytes,omitempty"`
DownloadedBytes int64 `json:"downloaded_bytes,omitempty"`
Percent float64 `json:"percent,omitempty"`
SpeedMBPS float64 `json:"speed_mbps,omitempty"`
}
TaskProgress 任务进度
type TaskProgressInfo ¶
type TaskProgressInfo struct {
TaskID string
Type string
Status TaskStatus
Title string
TotalBytes int64
DownloadedBytes int64
TotalFiles int
DownloadedFiles int
Storage string
Path string
Error string
CreatedAt time.Time
UpdatedAt time.Time
Webhook string
}
TaskProgressInfo 存储任务的进度信息
func RegisterTask ¶
func RegisterTask(taskID, taskType, storage, path, title, webhook string) *TaskProgressInfo
RegisterTask 注册一个新的 API 任务
func (*TaskProgressInfo) UpdateStatus ¶
func (t *TaskProgressInfo) UpdateStatus(status TaskStatus)
UpdateStatus 更新任务状态
type TaskStatus ¶
type TaskStatus string
TaskStatus 表示任务状态
const ( TaskStatusQueued TaskStatus = "queued" TaskStatusRunning TaskStatus = "running" TaskStatusCompleted TaskStatus = "completed" TaskStatusFailed TaskStatus = "failed" TaskStatusCancelled TaskStatus = "cancelled" )
type TasksListResponse ¶
type TasksListResponse struct {
Tasks []TaskInfoResponse `json:"tasks"`
Total int `json:"total"`
}
TasksListResponse 任务列表响应
type TransferParams ¶
type TransferParams struct {
SourceStorage string `json:"source_storage"`
SourcePath string `json:"source_path"`
TargetStorage string `json:"target_storage"`
TargetPath string `json:"target_path"`
}
TransferParams transfer 任务参数
type WebhookPayload ¶
type WebhookPayload struct {
TaskID string `json:"task_id"`
Type string `json:"type"`
Status TaskStatus `json:"status"`
Storage string `json:"storage"`
Path string `json:"path"`
CompletedAt *time.Time `json:"completed_at,omitempty"`
Error string `json:"error,omitempty"`
}
WebhookPayload Webhook 回调负载
func CreateWebhookPayload ¶
func CreateWebhookPayload(taskID string, taskType string, status TaskStatus, storage, path string, err error) *WebhookPayload
CreateWebhookPayload 创建 Webhook 负载
type YTDLPParams ¶
YTDLPParams ytdlp 任务参数