mirror of
https://github.com/krau/SaveAny-Bot.git
synced 2026-08-11 15:43:36 +08:00
style: format codebase
This commit is contained in:
@@ -11,23 +11,23 @@ import (
|
||||
// guarded by mu. It implements taskevent.Sink so the task layer can update it
|
||||
// without knowing about the API.
|
||||
type TaskProgressInfo struct {
|
||||
mu sync.Mutex
|
||||
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
|
||||
StartedAt time.Time
|
||||
Webhook string
|
||||
webhookNotified bool
|
||||
mu sync.Mutex
|
||||
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
|
||||
StartedAt time.Time
|
||||
Webhook string
|
||||
webhookNotified bool
|
||||
}
|
||||
|
||||
// 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{}
|
||||
}
|
||||
|
||||
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) OnDone(err error) {}
|
||||
func (p *ProgressTracker) GetInfo() *TaskProgressInfo { return nil }
|
||||
func (p *ProgressTracker) UpdateProgressBytes(bytes int64) {}
|
||||
func (p *ProgressTracker) UpdateProgressFiles(files int) {}
|
||||
func (p *ProgressTracker) OnDone(err error) {}
|
||||
func (p *ProgressTracker) GetInfo() *TaskProgressInfo { return nil }
|
||||
func (p *ProgressTracker) UpdateProgressBytes(bytes int64) {}
|
||||
func (p *ProgressTracker) UpdateProgressFiles(files int) {}
|
||||
|
||||
@@ -13,8 +13,8 @@ import (
|
||||
"github.com/krau/SaveAny-Bot/client/bot/handlers/utils/shortcut"
|
||||
"github.com/krau/SaveAny-Bot/common/i18n"
|
||||
"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/database"
|
||||
"github.com/krau/SaveAny-Bot/pkg/tcbdata"
|
||||
"github.com/krau/SaveAny-Bot/pkg/tfile"
|
||||
"github.com/krau/SaveAny-Bot/storage"
|
||||
|
||||
@@ -220,17 +220,13 @@ func TestUploadProgressNotificationsRemainOrdered(t *testing.T) {
|
||||
second := task.uploadCallback(t.Context(), "second")
|
||||
|
||||
var wait sync.WaitGroup
|
||||
wait.Add(1)
|
||||
go func() {
|
||||
defer wait.Done()
|
||||
wait.Go(func() {
|
||||
first(100, 100)
|
||||
}()
|
||||
})
|
||||
<-recorder.firstEntered
|
||||
wait.Add(1)
|
||||
go func() {
|
||||
defer wait.Done()
|
||||
wait.Go(func() {
|
||||
second(100, 100)
|
||||
}()
|
||||
})
|
||||
|
||||
overtook := false
|
||||
select {
|
||||
|
||||
@@ -63,11 +63,9 @@ func TestUploadProgressConcurrentCallbacks(t *testing.T) {
|
||||
var wg sync.WaitGroup
|
||||
for uploaded := int64(1 << 20); uploaded <= total; uploaded += 1 << 20 {
|
||||
uploaded := uploaded
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
wg.Go(func() {
|
||||
progress.OnUploadProgress(ctx, info, uploaded, total)
|
||||
}()
|
||||
})
|
||||
}
|
||||
wg.Wait()
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package tcbdata
|
||||
|
||||
import (
|
||||
"slices"
|
||||
|
||||
"github.com/krau/SaveAny-Bot/pkg/enums/tasktype"
|
||||
"github.com/krau/SaveAny-Bot/pkg/parser"
|
||||
"github.com/krau/SaveAny-Bot/pkg/telegraph"
|
||||
@@ -31,12 +33,7 @@ func ConflictStrategyValues() []string {
|
||||
}
|
||||
|
||||
func IsConflictStrategy(strategy string) bool {
|
||||
for _, value := range ConflictStrategyValues() {
|
||||
if strategy == value {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
return slices.Contains(ConflictStrategyValues(), strategy)
|
||||
}
|
||||
|
||||
// type TaskDataTGFiles struct {
|
||||
|
||||
@@ -103,7 +103,7 @@ func TestBatchUploadLimitAppliesPerFile(t *testing.T) {
|
||||
data := []byte("\x00\x00\x00\x18ftypmp42\x00\x00\x00\x00mp42isom")
|
||||
itemSize := int64(MaxUploadFileSize/2 + 1)
|
||||
|
||||
for index := 0; index < 2; index++ {
|
||||
for index := range 2 {
|
||||
item, err := telegramStorage.inspectBatchItem(tctx, storagetypes.BatchItem{
|
||||
Reader: bytes.NewReader(data),
|
||||
StoragePath: "video.mp4",
|
||||
|
||||
@@ -111,7 +111,7 @@ func splitLosslessVideo(
|
||||
outputPattern := filepath.Join(outputDir, "part-%03d"+extension)
|
||||
|
||||
var lastOversize int64
|
||||
for attempt := 0; attempt < videoSplitAttempts; attempt++ {
|
||||
for range videoSplitAttempts {
|
||||
if err := clearVideoParts(outputDir); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -173,7 +173,7 @@ func TestSplitLosslessVideoRejectsMultipleAlbums(t *testing.T) {
|
||||
return []byte("120.0\n"), nil
|
||||
case "ffmpeg":
|
||||
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)
|
||||
if err := os.WriteFile(partPath, make([]byte, 100), 0o600); err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -119,21 +119,21 @@ func (c *Client) MkDir(ctx context.Context, dirPath string) error {
|
||||
return nil
|
||||
}
|
||||
parts := strings.Split(dirPath, "/")
|
||||
currentPath := ""
|
||||
var currentPath strings.Builder
|
||||
for i, part := range parts {
|
||||
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 {
|
||||
return err
|
||||
}
|
||||
if exists {
|
||||
continue
|
||||
}
|
||||
url := c.BaseURL + currentPath
|
||||
url := c.BaseURL + currentPath.String()
|
||||
resp, err := c.doRequest(ctx, WebdavMethodMkcol, url, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -141,7 +141,7 @@ func (c *Client) MkDir(ctx context.Context, dirPath string) error {
|
||||
resp.Body.Close()
|
||||
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user