This commit is contained in:
@@ -6,8 +6,6 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// HTTPDownloader реализует интерфейс interfaces.FileDownloader.
|
||||
@@ -40,8 +38,8 @@ func (d *HTTPDownloader) Download(ctx context.Context, url string) (string, erro
|
||||
return "", fmt.Errorf("bad status code on download: %s", resp.Status)
|
||||
}
|
||||
|
||||
// Создаем временный файл с правильным расширением
|
||||
tmpFile, err := os.CreateTemp("", "track-*.tmp")
|
||||
// Создаем временный файл с правильным расширением .mp3
|
||||
tmpFile, err := os.CreateTemp("", "track-*.mp3")
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to create temp file: %w", err)
|
||||
}
|
||||
@@ -54,11 +52,5 @@ func (d *HTTPDownloader) Download(ctx context.Context, url string) (string, erro
|
||||
return "", fmt.Errorf("failed to write to temp file: %w", err)
|
||||
}
|
||||
|
||||
// Переименовываем файл, чтобы убрать .tmp расширение (не обязательно, но красиво)
|
||||
finalPath := strings.TrimSuffix(tmpFile.Name(), filepath.Ext(tmpFile.Name()))
|
||||
if err := os.Rename(tmpFile.Name(), finalPath); err != nil {
|
||||
return "", fmt.Errorf("failed to rename temp file: %w", err)
|
||||
}
|
||||
|
||||
return finalPath, nil
|
||||
return tmpFile.Name(), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user