style: format codebase

This commit is contained in:
krau
2026-08-11 08:47:35 +08:00
parent e49ebef977
commit 7e3e26fcf4
9 changed files with 41 additions and 50 deletions
+22 -22
View File
@@ -11,23 +11,23 @@ import (
// guarded by mu. It implements taskevent.Sink so the task layer can update it // guarded by mu. It implements taskevent.Sink so the task layer can update it
// without knowing about the API. // without knowing about the API.
type TaskProgressInfo struct { type TaskProgressInfo struct {
mu sync.Mutex mu sync.Mutex
TaskID string TaskID string
Type string Type string
Status TaskStatus Status TaskStatus
Title string Title string
TotalBytes int64 TotalBytes int64
DownloadedBytes int64 DownloadedBytes int64
TotalFiles int TotalFiles int
DownloadedFiles int DownloadedFiles int
Storage string Storage string
Path string Path string
Error string Error string
CreatedAt time.Time CreatedAt time.Time
UpdatedAt time.Time UpdatedAt time.Time
StartedAt time.Time StartedAt time.Time
Webhook string Webhook string
webhookNotified bool webhookNotified bool
} }
// progressStore holds all API tasks. Entries are removed a fixed duration after // progressStore holds all API tasks. Entries are removed a fixed duration after
@@ -208,9 +208,9 @@ func NewProgressTracker(taskID, taskType, storage, path, title, webhook string)
return &ProgressTracker{} return &ProgressTracker{}
} }
func (p *ProgressTracker) OnStart(totalBytes int64, totalFiles int) {} func (p *ProgressTracker) OnStart(totalBytes int64, totalFiles int) {}
func (p *ProgressTracker) OnProgress(downloadedBytes int64, downloadedFiles int) {} func (p *ProgressTracker) OnProgress(downloadedBytes int64, downloadedFiles int) {}
func (p *ProgressTracker) OnDone(err error) {} func (p *ProgressTracker) OnDone(err error) {}
func (p *ProgressTracker) GetInfo() *TaskProgressInfo { return nil } func (p *ProgressTracker) GetInfo() *TaskProgressInfo { return nil }
func (p *ProgressTracker) UpdateProgressBytes(bytes int64) {} func (p *ProgressTracker) UpdateProgressBytes(bytes int64) {}
func (p *ProgressTracker) UpdateProgressFiles(files int) {} func (p *ProgressTracker) UpdateProgressFiles(files int) {}
+1 -1
View File
@@ -13,8 +13,8 @@ import (
"github.com/krau/SaveAny-Bot/client/bot/handlers/utils/shortcut" "github.com/krau/SaveAny-Bot/client/bot/handlers/utils/shortcut"
"github.com/krau/SaveAny-Bot/common/i18n" "github.com/krau/SaveAny-Bot/common/i18n"
"github.com/krau/SaveAny-Bot/common/i18n/i18nk" "github.com/krau/SaveAny-Bot/common/i18n/i18nk"
"github.com/krau/SaveAny-Bot/database"
"github.com/krau/SaveAny-Bot/config" "github.com/krau/SaveAny-Bot/config"
"github.com/krau/SaveAny-Bot/database"
"github.com/krau/SaveAny-Bot/pkg/tcbdata" "github.com/krau/SaveAny-Bot/pkg/tcbdata"
"github.com/krau/SaveAny-Bot/pkg/tfile" "github.com/krau/SaveAny-Bot/pkg/tfile"
"github.com/krau/SaveAny-Bot/storage" "github.com/krau/SaveAny-Bot/storage"
@@ -220,17 +220,13 @@ func TestUploadProgressNotificationsRemainOrdered(t *testing.T) {
second := task.uploadCallback(t.Context(), "second") second := task.uploadCallback(t.Context(), "second")
var wait sync.WaitGroup var wait sync.WaitGroup
wait.Add(1) wait.Go(func() {
go func() {
defer wait.Done()
first(100, 100) first(100, 100)
}() })
<-recorder.firstEntered <-recorder.firstEntered
wait.Add(1) wait.Go(func() {
go func() {
defer wait.Done()
second(100, 100) second(100, 100)
}() })
overtook := false overtook := false
select { select {
+2 -4
View File
@@ -63,11 +63,9 @@ func TestUploadProgressConcurrentCallbacks(t *testing.T) {
var wg sync.WaitGroup var wg sync.WaitGroup
for uploaded := int64(1 << 20); uploaded <= total; uploaded += 1 << 20 { for uploaded := int64(1 << 20); uploaded <= total; uploaded += 1 << 20 {
uploaded := uploaded uploaded := uploaded
wg.Add(1) wg.Go(func() {
go func() {
defer wg.Done()
progress.OnUploadProgress(ctx, info, uploaded, total) progress.OnUploadProgress(ctx, info, uploaded, total)
}() })
} }
wg.Wait() wg.Wait()
+3 -6
View File
@@ -1,6 +1,8 @@
package tcbdata package tcbdata
import ( import (
"slices"
"github.com/krau/SaveAny-Bot/pkg/enums/tasktype" "github.com/krau/SaveAny-Bot/pkg/enums/tasktype"
"github.com/krau/SaveAny-Bot/pkg/parser" "github.com/krau/SaveAny-Bot/pkg/parser"
"github.com/krau/SaveAny-Bot/pkg/telegraph" "github.com/krau/SaveAny-Bot/pkg/telegraph"
@@ -31,12 +33,7 @@ func ConflictStrategyValues() []string {
} }
func IsConflictStrategy(strategy string) bool { func IsConflictStrategy(strategy string) bool {
for _, value := range ConflictStrategyValues() { return slices.Contains(ConflictStrategyValues(), strategy)
if strategy == value {
return true
}
}
return false
} }
// type TaskDataTGFiles struct { // type TaskDataTGFiles struct {
+1 -1
View File
@@ -103,7 +103,7 @@ func TestBatchUploadLimitAppliesPerFile(t *testing.T) {
data := []byte("\x00\x00\x00\x18ftypmp42\x00\x00\x00\x00mp42isom") data := []byte("\x00\x00\x00\x18ftypmp42\x00\x00\x00\x00mp42isom")
itemSize := int64(MaxUploadFileSize/2 + 1) itemSize := int64(MaxUploadFileSize/2 + 1)
for index := 0; index < 2; index++ { for index := range 2 {
item, err := telegramStorage.inspectBatchItem(tctx, storagetypes.BatchItem{ item, err := telegramStorage.inspectBatchItem(tctx, storagetypes.BatchItem{
Reader: bytes.NewReader(data), Reader: bytes.NewReader(data),
StoragePath: "video.mp4", StoragePath: "video.mp4",
+1 -1
View File
@@ -111,7 +111,7 @@ func splitLosslessVideo(
outputPattern := filepath.Join(outputDir, "part-%03d"+extension) outputPattern := filepath.Join(outputDir, "part-%03d"+extension)
var lastOversize int64 var lastOversize int64
for attempt := 0; attempt < videoSplitAttempts; attempt++ { for range videoSplitAttempts {
if err := clearVideoParts(outputDir); err != nil { if err := clearVideoParts(outputDir); err != nil {
return nil, err return nil, err
} }
+1 -1
View File
@@ -173,7 +173,7 @@ func TestSplitLosslessVideoRejectsMultipleAlbums(t *testing.T) {
return []byte("120.0\n"), nil return []byte("120.0\n"), nil
case "ffmpeg": case "ffmpeg":
pattern := args[len(args)-1] pattern := args[len(args)-1]
for index := 0; index < maxLosslessVideoParts+1; index++ { for index := range maxLosslessVideoParts + 1 {
partPath := strings.Replace(pattern, "%03d", fmt.Sprintf("%03d", index+1), 1) partPath := strings.Replace(pattern, "%03d", fmt.Sprintf("%03d", index+1), 1)
if err := os.WriteFile(partPath, make([]byte, 100), 0o600); err != nil { if err := os.WriteFile(partPath, make([]byte, 100), 0o600); err != nil {
return nil, err return nil, err
+6 -6
View File
@@ -119,21 +119,21 @@ func (c *Client) MkDir(ctx context.Context, dirPath string) error {
return nil return nil
} }
parts := strings.Split(dirPath, "/") parts := strings.Split(dirPath, "/")
currentPath := "" var currentPath strings.Builder
for i, part := range parts { for i, part := range parts {
if i > 0 { if i > 0 {
currentPath += "/" currentPath.WriteString("/")
} }
currentPath += part currentPath.WriteString(part)
exists, err := c.Exists(ctx, currentPath) exists, err := c.Exists(ctx, currentPath.String())
if err != nil { if err != nil {
return err return err
} }
if exists { if exists {
continue continue
} }
url := c.BaseURL + currentPath url := c.BaseURL + currentPath.String()
resp, err := c.doRequest(ctx, WebdavMethodMkcol, url, nil) resp, err := c.doRequest(ctx, WebdavMethodMkcol, url, nil)
if err != nil { if err != nil {
return err return err
@@ -141,7 +141,7 @@ func (c *Client) MkDir(ctx context.Context, dirPath string) error {
resp.Body.Close() resp.Body.Close()
if resp.StatusCode < 200 || resp.StatusCode >= 300 { if resp.StatusCode < 200 || resp.StatusCode >= 300 {
return fmt.Errorf("MKCOL %s: %s", currentPath, resp.Status) return fmt.Errorf("MKCOL %s: %s", currentPath.String(), resp.Status)
} }
} }
return nil return nil