Skip to content

Commit

Permalink
fix: generate file name from hash if empty in FileFromMedia function
Browse files Browse the repository at this point in the history
  • Loading branch information
krau committed Jan 4, 2025
1 parent 2b0bfac commit 3b42ba8
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion bot/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package bot

import (
"context"
"crypto/md5"
"fmt"

"github.com/celestix/gotgproto"
Expand Down Expand Up @@ -84,10 +85,14 @@ func FileFromMedia(media tg.MessageMediaClass) (*types.File, error) {
var fileName string
for _, attribute := range document.Attributes {
if name, ok := attribute.(*tg.DocumentAttributeFilename); ok {
fileName = name.FileName
fileName = name.GetFileName()
break
}
}
if fileName == "" {
fileName = fmt.Sprintf("%x", md5.Sum(document.GetFileReference()))
logger.L.Warnf("File name is empty, using hash: %s", fileName)
}
return &types.File{
Location: document.AsInputDocumentFileLocation(),
FileSize: document.Size,
Expand Down

0 comments on commit 3b42ba8

Please sign in to comment.