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
83
plugin/telegram/attachment_test.go
Normal file
83
plugin/telegram/attachment_test.go
Normal file
@ -0,0 +1,83 @@
|
||||
package telegram
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestGetMimeType(t *testing.T) {
|
||||
tests := []struct {
|
||||
mimeType string
|
||||
fileName string
|
||||
expected string
|
||||
}{
|
||||
{
|
||||
fileName: "file.jpg",
|
||||
mimeType: "image/jpeg",
|
||||
expected: "image/jpeg",
|
||||
},
|
||||
{
|
||||
fileName: "file.png",
|
||||
mimeType: "image/png",
|
||||
expected: "image/png",
|
||||
},
|
||||
{
|
||||
fileName: "file.pdf",
|
||||
mimeType: "application/pdf",
|
||||
expected: "application/pdf",
|
||||
},
|
||||
{
|
||||
fileName: "file.php",
|
||||
mimeType: "application/x-php",
|
||||
expected: "application/x-php",
|
||||
},
|
||||
{
|
||||
fileName: "file.xlsx",
|
||||
mimeType: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
||||
expected: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
||||
},
|
||||
{
|
||||
fileName: "file.oga",
|
||||
mimeType: "audio/ogg",
|
||||
expected: "audio/ogg",
|
||||
},
|
||||
{
|
||||
fileName: "file.jpg",
|
||||
expected: "image/jpeg",
|
||||
},
|
||||
{
|
||||
fileName: "file.png",
|
||||
expected: "image/png",
|
||||
},
|
||||
{
|
||||
fileName: "file.mp4",
|
||||
expected: "video/mp4",
|
||||
},
|
||||
{
|
||||
fileName: "file.pdf",
|
||||
expected: "application/octet-stream",
|
||||
},
|
||||
{
|
||||
fileName: "file.oga",
|
||||
expected: "audio/ogg",
|
||||
},
|
||||
{
|
||||
fileName: "file.xlsx",
|
||||
expected: "application/octet-stream",
|
||||
},
|
||||
{
|
||||
fileName: "file.txt",
|
||||
expected: "application/octet-stream",
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
attachment := Attachment{
|
||||
FileName: test.fileName,
|
||||
MimeType: test.mimeType,
|
||||
}
|
||||
|
||||
require.Equal(t, test.expected, attachment.GetMimeType())
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user