2023-07-14 00:18:44 +08:00
|
|
|
package telegram
|
|
|
|
|
|
|
|
import (
|
2023-12-29 07:50:15 +08:00
|
|
|
"path/filepath"
|
2023-07-14 00:18:44 +08:00
|
|
|
|
|
|
|
"go.uber.org/zap"
|
2023-09-17 22:55:13 +08:00
|
|
|
|
2023-10-26 09:02:50 +08:00
|
|
|
"github.com/usememos/memos/internal/log"
|
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 {
|
|
|
|
// Handle unknown file extension
|
|
|
|
log.Warn("Unknown file type for ", zap.String("filename", b.FileName))
|
|
|
|
|
|
|
|
return "application/octet-stream"
|
|
|
|
}
|
|
|
|
|
|
|
|
return mime
|
|
|
|
}
|