mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
feat: format message from telegram and upload attachments (#1924)
* feat: format message from telegram and download documents * fix: remove bool in expression * refactor: convert to markdown * refactor: resolve remarks and add support new message types * refactor: resolve remarks * feat: add test for mime type --------- Co-authored-by: Александр Тумайкин <AATumaykin@tsum.ru>
This commit is contained in:
committed by
GitHub
parent
f074bb1be2
commit
c5a1f4c839
38
plugin/telegram/attachment.go
Normal file
38
plugin/telegram/attachment.go
Normal file
@ -0,0 +1,38 @@
|
||||
package telegram
|
||||
|
||||
import (
|
||||
"path"
|
||||
|
||||
"github.com/usememos/memos/common/log"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
mime, ok := mimeTypes[path.Ext(b.FileName)]
|
||||
if !ok {
|
||||
// Handle unknown file extension
|
||||
log.Warn("Unknown file type for ", zap.String("filename", b.FileName))
|
||||
|
||||
return "application/octet-stream"
|
||||
}
|
||||
|
||||
return mime
|
||||
}
|
Reference in New Issue
Block a user