main: fixes downloads cleanup

This commit is contained in:
stefanodvx 2025-04-15 10:18:45 +02:00
parent aefb4ce673
commit 26452d0f53
6 changed files with 20 additions and 112 deletions

View file

@ -88,6 +88,15 @@ func SendMedias(
for _, chunk := range mediaGroupChunks {
var inputMediaList []gotgbot.InputMedia
for idx, media := range chunk {
// always clean up files, in case of error
defer func() {
if media.FilePath != "" {
os.Remove(media.FilePath)
}
if media.ThumbnailFilePath != "" {
os.Remove(media.ThumbnailFilePath)
}
}()
var caption string
if idx == 0 {
@ -114,15 +123,6 @@ func SendMedias(
return nil, err
}
for _, media := range chunk {
if media.FilePath != "" {
os.Remove(media.FilePath)
}
if media.ThumbnailFilePath != "" {
os.Remove(media.ThumbnailFilePath)
}
}
sentMessages = append(sentMessages, msgs...)
if sentMessages[0].Chat.Type != "private" {
if len(mediaGroupChunks) > 1 {