attachment.go 660 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package telegram
  2. import (
  3. "path"
  4. "github.com/usememos/memos/common/log"
  5. "go.uber.org/zap"
  6. )
  7. type Attachment struct {
  8. FileName string
  9. MimeType string
  10. FileSize int64
  11. Data []byte
  12. }
  13. var mimeTypes = map[string]string{
  14. ".jpg": "image/jpeg",
  15. ".png": "image/png",
  16. ".mp4": "video/mp4", // for video note
  17. ".oga": "audio/ogg", // for voice
  18. }
  19. func (b Attachment) GetMimeType() string {
  20. if b.MimeType != "" {
  21. return b.MimeType
  22. }
  23. mime, ok := mimeTypes[path.Ext(b.FileName)]
  24. if !ok {
  25. // Handle unknown file extension
  26. log.Warn("Unknown file type for ", zap.String("filename", b.FileName))
  27. return "application/octet-stream"
  28. }
  29. return mime
  30. }