chore: format code for consistency and readability

This commit is contained in:
krau
2026-03-05 17:20:45 +08:00
parent 70f7172162
commit f377ee3ca4
4 changed files with 15 additions and 14 deletions

View File

@@ -42,7 +42,7 @@ func FormatSize(bytes int64) string {
MB = KB * 1024
GB = MB * 1024
)
switch {
case bytes >= GB:
return fmt.Sprintf("%.2f GB", float64(bytes)/float64(GB))

View File

@@ -1,5 +1,6 @@
package tasktype
//go:generate go-enum --values --names --flag --nocase
// ENUM(tgfiles,tphpics,parseditem,directlinks,aria2,ytdlp,transfer)
//
//go:generate go-enum --values --names --flag --nocase
type TaskType string

View File

@@ -87,12 +87,12 @@ func (l *Local) Exists(ctx context.Context, storagePath string) bool {
// ListFiles implements StorageListable interface
func (l *Local) ListFiles(ctx context.Context, dirPath string) ([]storagetypes.FileInfo, error) {
absPath := l.JoinStoragePath(dirPath)
entries, err := os.ReadDir(absPath)
if err != nil {
return nil, fmt.Errorf("failed to read directory %s: %w", absPath, err)
}
files := make([]storagetypes.FileInfo, 0, len(entries))
for _, entry := range entries {
info, err := entry.Info()
@@ -100,7 +100,7 @@ func (l *Local) ListFiles(ctx context.Context, dirPath string) ([]storagetypes.F
l.logger.Warnf("Failed to get file info for %s: %v", entry.Name(), err)
continue
}
filePath := filepath.Join(dirPath, entry.Name())
files = append(files, storagetypes.FileInfo{
Name: entry.Name(),
@@ -110,24 +110,24 @@ func (l *Local) ListFiles(ctx context.Context, dirPath string) ([]storagetypes.F
ModTime: info.ModTime(),
})
}
return files, nil
}
// OpenFile implements StorageReadable interface
func (l *Local) OpenFile(ctx context.Context, filePath string) (io.ReadCloser, int64, error) {
absPath := l.JoinStoragePath(filePath)
file, err := os.Open(absPath)
if err != nil {
return nil, 0, fmt.Errorf("failed to open file %s: %w", absPath, err)
}
stat, err := file.Stat()
if err != nil {
file.Close()
return nil, 0, fmt.Errorf("failed to stat file %s: %w", absPath, err)
}
return file, stat.Size(), nil
}

View File

@@ -41,15 +41,15 @@ type Response struct {
}
type Propstat struct {
Prop Prop `xml:"prop"`
Prop Prop `xml:"prop"`
Status string `xml:"status"`
}
type Prop struct {
ResourceType ResourceType `xml:"resourcetype"`
GetContentLength int64 `xml:"getcontentlength"`
GetLastModified string `xml:"getlastmodified"`
DisplayName string `xml:"displayname"`
ResourceType ResourceType `xml:"resourcetype"`
GetContentLength int64 `xml:"getcontentlength"`
GetLastModified string `xml:"getlastmodified"`
DisplayName string `xml:"displayname"`
}
type ResourceType struct {