mirror of
https://github.com/krau/SaveAny-Bot.git
synced 2026-05-12 04:19:40 +08:00
refactor: refactor task logic for better scalability (#76)
* refactor: a big refactor. wip * refactor: port handle file * refactor: place all handlers * fix: task info nil pointer * feat: enhance task progress tracking and context management * feat: cancel task * feat: stream mode * feat: silent mode * feat: dir cmd * refactor: remove unused old file * feat: rule cmd * feat: handle silent mode * feat: batch task * fix: batch task progress and temp file cleanup * refactor: update file creation and cleanup methods for better resource management * feat: add save command with silent mode handling * feat: message link * feat: update message prompts to include file count in storage selection * feat: slient save links * refactor: reduce dup code * feat: rule type * feat: chose dir * feat: refactor file handling and storage rules, improve error handling and logging * feat: rule mode * feat: telegraph pics * fix: tphpics nil pointer and inaccurate dirpath * feat: silent save telegraph * feat: add suffix to avoid file overwrite * feat: new storage telegram * chore: tidy go mod
This commit is contained in:
51
core/tphtask/task.go
Normal file
51
core/tphtask/task.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package tphtask
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/krau/SaveAny-Bot/pkg/telegraph"
|
||||
"github.com/krau/SaveAny-Bot/storage"
|
||||
)
|
||||
|
||||
type Task struct {
|
||||
ID string
|
||||
Ctx context.Context
|
||||
PhPath string
|
||||
Pics []string
|
||||
Stor storage.Storage
|
||||
StorPath string
|
||||
client *telegraph.Client
|
||||
progress ProgressTracker
|
||||
|
||||
cannotStream bool
|
||||
totalpics int
|
||||
downloaded atomic.Int64
|
||||
}
|
||||
|
||||
func NewTask(
|
||||
id string,
|
||||
ctx context.Context,
|
||||
phPath string,
|
||||
pics []string,
|
||||
stor storage.Storage,
|
||||
storPath string,
|
||||
client *telegraph.Client,
|
||||
progress ProgressTracker,
|
||||
) *Task {
|
||||
_, cannotStream := stor.(storage.StorageCannotStream)
|
||||
tphtask := &Task{
|
||||
ID: id,
|
||||
Ctx: ctx,
|
||||
PhPath: phPath,
|
||||
Pics: pics,
|
||||
Stor: stor,
|
||||
StorPath: storPath,
|
||||
client: client,
|
||||
progress: progress,
|
||||
cannotStream: cannotStream,
|
||||
totalpics: len(pics),
|
||||
downloaded: atomic.Int64{},
|
||||
}
|
||||
return tphtask
|
||||
}
|
||||
Reference in New Issue
Block a user