mirror of
https://github.com/krau/SaveAny-Bot.git
synced 2026-06-06 16:14:59 +08:00
fix: enhance filename generation by using media file name if available
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/celestix/gotgproto/ext"
|
"github.com/celestix/gotgproto/ext"
|
||||||
|
"github.com/celestix/gotgproto/functions"
|
||||||
"github.com/duke-git/lancet/v2/maputil"
|
"github.com/duke-git/lancet/v2/maputil"
|
||||||
|
|
||||||
"github.com/duke-git/lancet/v2/mathutil"
|
"github.com/duke-git/lancet/v2/mathutil"
|
||||||
@@ -19,6 +20,9 @@ import (
|
|||||||
"github.com/rs/xid"
|
"github.com/rs/xid"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// generate a file name from the message content and media type
|
||||||
|
//
|
||||||
|
// it will never return an empty string
|
||||||
func GenFileNameFromMessage(message tg.Message) string {
|
func GenFileNameFromMessage(message tg.Message) string {
|
||||||
ext := func(media tg.MessageMediaClass) string {
|
ext := func(media tg.MessageMediaClass) string {
|
||||||
switch media := media.(type) {
|
switch media := media.(type) {
|
||||||
@@ -82,7 +86,13 @@ func GenFileNameFromMessage(message tg.Message) string {
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
if filename == "" {
|
if filename == "" {
|
||||||
filename = fmt.Sprintf("%d_%s", message.GetID(), xid.New().String())
|
mname, err := functions.GetMediaFileNameWithId(message.Media)
|
||||||
|
if err != nil {
|
||||||
|
filename = fmt.Sprintf("%d_%s", message.GetID(), xid.New().String())
|
||||||
|
} else {
|
||||||
|
filename = mname
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return filename + ext
|
return filename + ext
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user