diff --git a/Dockerfile b/Dockerfile index 6a26002..ebedd19 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,7 @@ FROM golang:1.20-alpine RUN apk add --no-cache gcc musl-dev +RUN apk add mailcap WORKDIR /app diff --git a/api/helper/save_media.go b/api/helper/save_media.go index a822091..4713506 100644 --- a/api/helper/save_media.go +++ b/api/helper/save_media.go @@ -17,12 +17,15 @@ func SaveMedia(instanceID string, fileName string, data []byte, mimetype string) if err != nil { return "", err } - path := fmt.Sprintf("%s/%s%s", dirPath, fileName, exts[0]) - err = os.WriteFile(path, data, 0600) - if err != nil { - return "", err + if len(exts) > 0 { + path := fmt.Sprintf("%s/%s%s", dirPath, fileName, exts[0]) + err = os.WriteFile(path, data, 0600) + if err != nil { + return "", err + } + return path, nil } - return path, nil + return "", fmt.Errorf("no extension found for MIME type: %s", mimetype) } diff --git a/api/model/message.go b/api/model/message.go index d4c722b..4d22256 100644 --- a/api/model/message.go +++ b/api/model/message.go @@ -11,7 +11,7 @@ type Message struct { SenderJID string `gorm:"column:sender_jid"` ChatJID string `gorm:"column:chat_jid"` InstanceID string - MessageID string `gorm:"uniqueIndex"` + MessageID string Timestamp time.Time Body string MediaType string // text, image, ptt, audio, document diff --git a/pkg/whatsapp/whatsapp.go b/pkg/whatsapp/whatsapp.go index 4dcee1f..c2d674b 100644 --- a/pkg/whatsapp/whatsapp.go +++ b/pkg/whatsapp/whatsapp.go @@ -49,7 +49,7 @@ const ( Image Document Sticker - Video + // Video ) func (m MediaType) String() string { @@ -60,8 +60,8 @@ func (m MediaType) String() string { return "document" case Sticker: return "sticker" - case Video: - return "video" + // case Video: + // return "video" case Image: return "image" } @@ -468,19 +468,19 @@ func (w *whatsApp) downloadMedia(instance *Instance, message *waProto.Message) ( }, nil } - video := message.GetVideoMessage() - if video != nil { - data, err := instance.Client.Download(video) - if err != nil { - return &DownloadResponse{Type: Video}, err - } + // video := message.GetVideoMessage() + // if video != nil { + // data, err := instance.Client.Download(video) + // if err != nil { + // return &DownloadResponse{Type: Video}, err + // } - return &DownloadResponse{ - Data: data, - Type: Video, - Mimetype: video.GetMimetype(), - }, nil - } + // return &DownloadResponse{ + // Data: data, + // Type: Video, + // Mimetype: video.GetMimetype(), + // }, nil + // } return nil, nil }