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 MB = KB * 1024
GB = MB * 1024 GB = MB * 1024
) )
switch { switch {
case bytes >= GB: case bytes >= GB:
return fmt.Sprintf("%.2f GB", float64(bytes)/float64(GB)) return fmt.Sprintf("%.2f GB", float64(bytes)/float64(GB))

View File

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

View File

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

View File

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