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:
Krau
2025-06-15 23:57:49 +08:00
committed by GitHub
parent 280745cae3
commit 900823cdb9
150 changed files with 5730 additions and 3923 deletions

View File

@@ -0,0 +1,5 @@
package key
//go:generate go-enum --values --names --flag --nocase
// ENUM(content-length)
type ContextKey string

View File

@@ -0,0 +1,82 @@
// Code generated by go-enum DO NOT EDIT.
// Version: 0.6.1
// Revision: a6f63bddde05aca4221df9c8e9e6d7d9674b1cb4
// Build Date: 2025-03-18T23:42:14Z
// Built By: goreleaser
package key
import (
"fmt"
"strings"
)
const (
// ContextKeyContentLength is a ContextKey of type content-length.
ContextKeyContentLength ContextKey = "content-length"
)
var ErrInvalidContextKey = fmt.Errorf("not a valid ContextKey, try [%s]", strings.Join(_ContextKeyNames, ", "))
var _ContextKeyNames = []string{
string(ContextKeyContentLength),
}
// ContextKeyNames returns a list of possible string values of ContextKey.
func ContextKeyNames() []string {
tmp := make([]string, len(_ContextKeyNames))
copy(tmp, _ContextKeyNames)
return tmp
}
// ContextKeyValues returns a list of the values for ContextKey
func ContextKeyValues() []ContextKey {
return []ContextKey{
ContextKeyContentLength,
}
}
// String implements the Stringer interface.
func (x ContextKey) String() string {
return string(x)
}
// IsValid provides a quick way to determine if the typed value is
// part of the allowed enumerated values
func (x ContextKey) IsValid() bool {
_, err := ParseContextKey(string(x))
return err == nil
}
var _ContextKeyValue = map[string]ContextKey{
"content-length": ContextKeyContentLength,
}
// ParseContextKey attempts to convert a string to a ContextKey.
func ParseContextKey(name string) (ContextKey, error) {
if x, ok := _ContextKeyValue[name]; ok {
return x, nil
}
// Case insensitive parse, do a separate lookup to prevent unnecessary cost of lowercasing a string if we don't need to.
if x, ok := _ContextKeyValue[strings.ToLower(name)]; ok {
return x, nil
}
return ContextKey(""), fmt.Errorf("%s is %w", name, ErrInvalidContextKey)
}
// Set implements the Golang flag.Value interface func.
func (x *ContextKey) Set(val string) error {
v, err := ParseContextKey(val)
*x = v
return err
}
// Get implements the Golang flag.Getter interface func.
func (x *ContextKey) Get() interface{} {
return *x
}
// Type implements the github.com/spf13/pFlag Value interface.
func (x *ContextKey) Type() string {
return "ContextKey"
}

View File

@@ -0,0 +1,16 @@
package rule
type RuleType string
const (
FileNameRegex RuleType = "FILENAME-REGEX"
MessageRegex RuleType = "MESSAGE-REGEX"
)
func (r RuleType) String() string {
return string(r)
}
func Values() []RuleType {
return []RuleType{FileNameRegex, MessageRegex}
}

View File

@@ -0,0 +1,9 @@
package storage
//go:generate go-enum --values --names --noprefix --flag --nocase
// StorageType
/* ENUM(
local, webdav, alist, minio, telegram
) */
type StorageType string

View File

@@ -0,0 +1,102 @@
// Code generated by go-enum DO NOT EDIT.
// Version: 0.6.1
// Revision: a6f63bddde05aca4221df9c8e9e6d7d9674b1cb4
// Build Date: 2025-03-18T23:42:14Z
// Built By: goreleaser
package storage
import (
"fmt"
"strings"
)
const (
// Local is a StorageType of type local.
Local StorageType = "local"
// Webdav is a StorageType of type webdav.
Webdav StorageType = "webdav"
// Alist is a StorageType of type alist.
Alist StorageType = "alist"
// Minio is a StorageType of type minio.
Minio StorageType = "minio"
// Telegram is a StorageType of type telegram.
Telegram StorageType = "telegram"
)
var ErrInvalidStorageType = fmt.Errorf("not a valid StorageType, try [%s]", strings.Join(_StorageTypeNames, ", "))
var _StorageTypeNames = []string{
string(Local),
string(Webdav),
string(Alist),
string(Minio),
string(Telegram),
}
// StorageTypeNames returns a list of possible string values of StorageType.
func StorageTypeNames() []string {
tmp := make([]string, len(_StorageTypeNames))
copy(tmp, _StorageTypeNames)
return tmp
}
// StorageTypeValues returns a list of the values for StorageType
func StorageTypeValues() []StorageType {
return []StorageType{
Local,
Webdav,
Alist,
Minio,
Telegram,
}
}
// String implements the Stringer interface.
func (x StorageType) String() string {
return string(x)
}
// IsValid provides a quick way to determine if the typed value is
// part of the allowed enumerated values
func (x StorageType) IsValid() bool {
_, err := ParseStorageType(string(x))
return err == nil
}
var _StorageTypeValue = map[string]StorageType{
"local": Local,
"webdav": Webdav,
"alist": Alist,
"minio": Minio,
"telegram": Telegram,
}
// ParseStorageType attempts to convert a string to a StorageType.
func ParseStorageType(name string) (StorageType, error) {
if x, ok := _StorageTypeValue[name]; ok {
return x, nil
}
// Case insensitive parse, do a separate lookup to prevent unnecessary cost of lowercasing a string if we don't need to.
if x, ok := _StorageTypeValue[strings.ToLower(name)]; ok {
return x, nil
}
return StorageType(""), fmt.Errorf("%s is %w", name, ErrInvalidStorageType)
}
// Set implements the Golang flag.Value interface func.
func (x *StorageType) Set(val string) error {
v, err := ParseStorageType(val)
*x = v
return err
}
// Get implements the Golang flag.Getter interface func.
func (x *StorageType) Get() interface{} {
return *x
}
// Type implements the github.com/spf13/pFlag Value interface.
func (x *StorageType) Type() string {
return "StorageType"
}

View File

@@ -0,0 +1,5 @@
package tasktype
//go:generate go-enum --values --names --flag --nocase
// ENUM(tgfiles,tphpics)
type TaskType string

View File

@@ -0,0 +1,87 @@
// Code generated by go-enum DO NOT EDIT.
// Version: 0.6.1
// Revision: a6f63bddde05aca4221df9c8e9e6d7d9674b1cb4
// Build Date: 2025-03-18T23:42:14Z
// Built By: goreleaser
package tasktype
import (
"fmt"
"strings"
)
const (
// TaskTypeTgfiles is a TaskType of type tgfiles.
TaskTypeTgfiles TaskType = "tgfiles"
// TaskTypeTphpics is a TaskType of type tphpics.
TaskTypeTphpics TaskType = "tphpics"
)
var ErrInvalidTaskType = fmt.Errorf("not a valid TaskType, try [%s]", strings.Join(_TaskTypeNames, ", "))
var _TaskTypeNames = []string{
string(TaskTypeTgfiles),
string(TaskTypeTphpics),
}
// TaskTypeNames returns a list of possible string values of TaskType.
func TaskTypeNames() []string {
tmp := make([]string, len(_TaskTypeNames))
copy(tmp, _TaskTypeNames)
return tmp
}
// TaskTypeValues returns a list of the values for TaskType
func TaskTypeValues() []TaskType {
return []TaskType{
TaskTypeTgfiles,
TaskTypeTphpics,
}
}
// String implements the Stringer interface.
func (x TaskType) String() string {
return string(x)
}
// IsValid provides a quick way to determine if the typed value is
// part of the allowed enumerated values
func (x TaskType) IsValid() bool {
_, err := ParseTaskType(string(x))
return err == nil
}
var _TaskTypeValue = map[string]TaskType{
"tgfiles": TaskTypeTgfiles,
"tphpics": TaskTypeTphpics,
}
// ParseTaskType attempts to convert a string to a TaskType.
func ParseTaskType(name string) (TaskType, error) {
if x, ok := _TaskTypeValue[name]; ok {
return x, nil
}
// Case insensitive parse, do a separate lookup to prevent unnecessary cost of lowercasing a string if we don't need to.
if x, ok := _TaskTypeValue[strings.ToLower(name)]; ok {
return x, nil
}
return TaskType(""), fmt.Errorf("%s is %w", name, ErrInvalidTaskType)
}
// Set implements the Golang flag.Value interface func.
func (x *TaskType) Set(val string) error {
v, err := ParseTaskType(val)
*x = v
return err
}
// Get implements the Golang flag.Getter interface func.
func (x *TaskType) Get() interface{} {
return *x
}
// Type implements the github.com/spf13/pFlag Value interface.
func (x *TaskType) Type() string {
return "TaskType"
}