2023-07-14 00:18:44 +08:00
|
|
|
package telegram
|
|
|
|
|
|
|
|
import (
|
2024-02-29 23:54:43 +08:00
|
|
|
"log/slog"
|
2023-12-29 07:50:15 +08:00
|
|
|
"path/filepath"
|
2023-07-14 00:18:44 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
type Attachment struct {
|
|
|
|
FileName string
|
|
|
|
MimeType string
|
|
|
|
FileSize int64
|
|
|
|
Data []byte
|
|
|
|
}
|
|
|
|
|
|
|
|
var mimeTypes = map[string]string{
|
|
|
|
".jpg": "image/jpeg",
|
|
|
|
".png": "image/png",
|
|
|
|
".mp4": "video/mp4", // for video note
|
|
|
|
".oga": "audio/ogg", // for voice
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b Attachment) GetMimeType() string {
|
|
|
|
if b.MimeType != "" {
|
|
|
|
return b.MimeType
|
|
|
|
}
|
|
|
|
|
2023-12-29 07:50:15 +08:00
|
|
|
mime, ok := mimeTypes[filepath.Ext(b.FileName)]
|
2023-07-14 00:18:44 +08:00
|
|
|
if !ok {
|
2024-02-29 23:54:43 +08:00
|
|
|
slog.Warn("Unknown file extension", slog.String("file", b.FileName))
|
2023-07-14 00:18:44 +08:00
|
|
|
return "application/octet-stream"
|
|
|
|
}
|
|
|
|
|
|
|
|
return mime
|
|
|
|
}
|