attachment.go 661 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. package telegram
  2. import (
  3. "path"
  4. "go.uber.org/zap"
  5. "github.com/usememos/memos/common/log"
  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. }