api

package
v0.55.0 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2026 License: AGPL-3.0 Imports: 37 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthMiddleware

func AuthMiddleware() func(http.Handler) http.Handler

AuthMiddleware 返回认证中间件

func DeleteTask

func DeleteTask(taskID string)

DeleteTask 删除任务记录

func ExtractFilesFromLinks(ctx context.Context, links []string) ([]tfile.TGFileMessage, error)

ExtractFilesFromLinks 从消息链接中提取文件 每个文件的处理流程:解析链接 -> 获取消息 -> 获取媒体组 -> 创建文件对象 对于单个文件,全程使用同一个 client context,不会交叉

func ExtractTelegraphImages

func ExtractTelegraphImages(ctx context.Context, pageURL string) ([]string, string, error)

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(ctx context.Context, link string) (int64, int, error)

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 Start

func Start(ctx context.Context) error

Start 初始化并启动 API 服务器

func WrapTaskWithWebhook

func WrapTaskWithWebhook(ctx context.Context, taskID string, fn func() error) error

WrapTaskWithWebhook 包装任务执行,添加 webhook 回调

func WriteError

func WriteError(w http.ResponseWriter, statusCode int, errCode, message string) error

WriteError 写入错误响应

func WriteJSON

func WriteJSON(w http.ResponseWriter, statusCode int, data any) error

WriteJSON 写入 JSON 响应

Types

type APIError

type APIError struct {
	StatusCode int
	ErrorCode  string
	Message    string
}

APIError API 错误

func (*APIError) Error

func (e *APIError) Error() string

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

type ErrorResponse struct {
	Error   string `json:"error"`
	Message string `json:"message,omitempty"`
}

ErrorResponse 错误响应

type Handlers

type Handlers struct {
	// contains filtered or unexported fields
}

Handlers 处理器结构体

func NewHandlers

func NewHandlers(factory *TaskFactory) *Handlers

NewHandlers 创建处理器

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

type MessageContext struct {
	Message *tg.Message
	Client  *ext.Context
}

MessageContext 保存消息和获取它所用的 context

type ParsedParams

type ParsedParams struct {
	URL string `json:"url"`
}

ParsedParams parsed 任务参数

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) OnDone

func (p *ProgressTracker) OnDone(err error)

OnDone 任务完成

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 Server

type Server struct {
	// contains filtered or unexported fields
}

Server API 服务器

func NewServer

func NewServer(ctx context.Context) *Server

NewServer 创建新的 API 服务器

func (*Server) Start

func (s *Server) Start(ctx context.Context) error

Start 启动服务器

type StorageInfo

type StorageInfo struct {
	Name string `json:"name"`
	Type string `json:"type"`
}

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 NewTaskFactory

func NewTaskFactory(ctx context.Context) *TaskFactory

NewTaskFactory 创建任务工厂

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 GetAllTasks

func GetAllTasks() []*TaskProgressInfo

GetAllTasks 获取所有任务

func GetTask

func GetTask(taskID string) (*TaskProgressInfo, bool)

GetTask 获取任务进度信息

func RegisterTask

func RegisterTask(taskID, taskType, storage, path, title, webhook string) *TaskProgressInfo

RegisterTask 注册一个新的 API 任务

func (*TaskProgressInfo) SetError

func (t *TaskProgressInfo) SetError(err string)

SetError 设置错误信息

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

type YTDLPParams struct {
	URLs  []string `json:"urls"`
	Flags []string `json:"flags,omitempty"`
}

YTDLPParams ytdlp 任务参数

Jump to

Keyboard shortcuts

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