mirror of
https://github.com/krau/SaveAny-Bot.git
synced 2026-07-07 23:21:23 +08:00
fix: generate file name from hash if empty in FileFromMedia function
This commit is contained in:
@@ -2,6 +2,7 @@ package bot
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"crypto/md5"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/celestix/gotgproto"
|
"github.com/celestix/gotgproto"
|
||||||
@@ -84,10 +85,14 @@ func FileFromMedia(media tg.MessageMediaClass) (*types.File, error) {
|
|||||||
var fileName string
|
var fileName string
|
||||||
for _, attribute := range document.Attributes {
|
for _, attribute := range document.Attributes {
|
||||||
if name, ok := attribute.(*tg.DocumentAttributeFilename); ok {
|
if name, ok := attribute.(*tg.DocumentAttributeFilename); ok {
|
||||||
fileName = name.FileName
|
fileName = name.GetFileName()
|
||||||
break
|
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{
|
return &types.File{
|
||||||
Location: document.AsInputDocumentFileLocation(),
|
Location: document.AsInputDocumentFileLocation(),
|
||||||
FileSize: document.Size,
|
FileSize: document.Size,
|
||||||
|
|||||||
Reference in New Issue
Block a user