download: delete files on error
This commit is contained in:
parent
c6cb552dc8
commit
6a790440de
1 changed files with 15 additions and 0 deletions
|
@ -3,6 +3,7 @@ package core
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"sync"
|
||||
|
@ -31,6 +32,18 @@ func downloadMediaItem(
|
|||
var filePath string
|
||||
var thumbnailFilePath string
|
||||
|
||||
cleanup := true
|
||||
defer func() {
|
||||
if cleanup {
|
||||
if filePath != "" {
|
||||
os.Remove(filePath)
|
||||
}
|
||||
if thumbnailFilePath != "" {
|
||||
os.Remove(thumbnailFilePath)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
if format.Type != enums.MediaTypePhoto {
|
||||
if len(format.Segments) == 0 {
|
||||
path, err := util.DownloadFile(
|
||||
|
@ -77,6 +90,8 @@ func downloadMediaItem(
|
|||
filePath = path
|
||||
}
|
||||
|
||||
// all good, no need to delete files
|
||||
cleanup = false
|
||||
return &models.DownloadedMedia{
|
||||
FilePath: filePath,
|
||||
ThumbnailFilePath: thumbnailFilePath,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue