Fix download URL mismatch
This commit is contained in:
@@ -20,12 +20,44 @@ type DownloadStatus struct {
|
||||
Err error // Error, if any
|
||||
}
|
||||
|
||||
// ensureDir checks if a dire
|
||||
func ensureDir(path string) error {
|
||||
info, err := os.Stat(path)
|
||||
if err == nil {
|
||||
if !info.IsDir() {
|
||||
return fmt.Errorf("path exists but is not a directory: %s", path)
|
||||
}
|
||||
fmt.Printf("Directory already exists: %s\n", path)
|
||||
return nil
|
||||
}
|
||||
|
||||
if !os.IsNotExist(err) {
|
||||
return fmt.Errorf("error checking path: %w", err)
|
||||
}
|
||||
|
||||
// 0760 = rwxrw---- (owner: rwx, group: rw-, others: ---)
|
||||
if err := os.MkdirAll(path, 0760); err != nil {
|
||||
return fmt.Errorf("failed to create directory: %w", err)
|
||||
}
|
||||
|
||||
logger.Info("Directory created: %s\n", path)
|
||||
return nil
|
||||
}
|
||||
|
||||
// DownloadAudioFiles downloads multiple audio files and sends progress updates
|
||||
// to the provided channel. The channel is closed when all downloads are complete.
|
||||
func DownloadAudioFiles(progressChan chan<- DownloadStatus, filenames []string, destDir string) {
|
||||
defer close(progressChan)
|
||||
|
||||
urlBase := "https://files.rhemawavetech.com/audio/"
|
||||
if err := ensureDir(destDir); err != nil {
|
||||
logger.Error("failed to ensureDir %s %v", destDir, err)
|
||||
progressChan <- DownloadStatus{
|
||||
Msg: fmt.Sprintf("Failed to ensure directory exists: %v", err),
|
||||
Err: err,
|
||||
}
|
||||
}
|
||||
|
||||
urlBase := "https://files.radiantwavetech.com/audio/"
|
||||
|
||||
// First, calculate the total size of files that need to be downloaded
|
||||
totalSize := int64(0)
|
||||
@@ -87,6 +119,8 @@ func DownloadAudioFiles(progressChan chan<- DownloadStatus, filenames []string,
|
||||
url := urlBase + filename
|
||||
destPath := filepath.Join(destDir, filename)
|
||||
|
||||
// Ensure the destination directory exists
|
||||
|
||||
// Create the destination file
|
||||
out, err := os.Create(destPath)
|
||||
if err != nil {
|
||||
@@ -158,13 +192,6 @@ func DownloadAudioFiles(progressChan chan<- DownloadStatus, filenames []string,
|
||||
}
|
||||
|
||||
out.Close()
|
||||
|
||||
// Send completion for this file
|
||||
progressChan <- DownloadStatus{
|
||||
Max: totalSize,
|
||||
Cur: totalDownloaded,
|
||||
Msg: "Finished Downloading",
|
||||
}
|
||||
}
|
||||
|
||||
// Send final status
|
||||
|
||||
Reference in New Issue
Block a user