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 (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sort"
|
"sort"
|
||||||
"sync"
|
"sync"
|
||||||
|
@ -31,6 +32,18 @@ func downloadMediaItem(
|
||||||
var filePath string
|
var filePath string
|
||||||
var thumbnailFilePath 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 format.Type != enums.MediaTypePhoto {
|
||||||
if len(format.Segments) == 0 {
|
if len(format.Segments) == 0 {
|
||||||
path, err := util.DownloadFile(
|
path, err := util.DownloadFile(
|
||||||
|
@ -77,6 +90,8 @@ func downloadMediaItem(
|
||||||
filePath = path
|
filePath = path
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// all good, no need to delete files
|
||||||
|
cleanup = false
|
||||||
return &models.DownloadedMedia{
|
return &models.DownloadedMedia{
|
||||||
FilePath: filePath,
|
FilePath: filePath,
|
||||||
ThumbnailFilePath: thumbnailFilePath,
|
ThumbnailFilePath: thumbnailFilePath,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue