createTPHPicsTask 创建 Telegraph 图片下载任务
(taskID string, createdAt time.Time, req *CreateTaskRequest, stor storage.Storage)
| 284 | |
| 285 | // createTPHPicsTask 创建 Telegraph 图片下载任务 |
| 286 | func (f *TaskFactory) createTPHPicsTask(taskID string, createdAt time.Time, req *CreateTaskRequest, stor storage.Storage) (*CreateTaskResponse, error) { |
| 287 | var params TPHPicsParams |
| 288 | if err := json.Unmarshal(req.Params, ¶ms); err != nil { |
| 289 | return nil, fmt.Errorf("invalid params: %w", err) |
| 290 | } |
| 291 | |
| 292 | if params.TelegraphURL == "" { |
| 293 | return nil, fmt.Errorf("no telegraph URL provided") |
| 294 | } |
| 295 | |
| 296 | // 提取图片 |
| 297 | pics, phPath, err := ExtractTelegraphImages(f.ctx, params.TelegraphURL) |
| 298 | if err != nil { |
| 299 | return nil, fmt.Errorf("failed to extract telegraph images: %w", err) |
| 300 | } |
| 301 | |
| 302 | if len(pics) == 0 { |
| 303 | return nil, fmt.Errorf("no images found in telegraph page") |
| 304 | } |
| 305 | |
| 306 | client := telegraph.NewClient() |
| 307 | task := tphtask.NewTask(taskID, f.ctx, phPath, pics, stor, req.Path, client, nil) |
| 308 | |
| 309 | err = f.registerAndEnqueueTask(task, tasktype.TaskTypeTphpics, req.Storage, req.Path, req.Webhook) |
| 310 | if err != nil { |
| 311 | return nil, err |
| 312 | } |
| 313 | |
| 314 | return &CreateTaskResponse{ |
| 315 | TaskID: taskID, |
| 316 | Type: tasktype.TaskTypeTphpics, |
| 317 | Status: TaskStatusQueued, |
| 318 | CreatedAt: createdAt, |
| 319 | }, nil |
| 320 | } |
| 321 | |
| 322 | // createTransferTask 创建存储间传输任务 |
| 323 | func (f *TaskFactory) createTransferTask(taskID string, createdAt time.Time, req *CreateTaskRequest) (*CreateTaskResponse, error) { |
no test coverage detected