Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielolivrp committed Feb 28, 2024
1 parent e50a4af commit 6d455b9
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 21 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
FROM golang:1.20-alpine

RUN apk add --no-cache gcc musl-dev
RUN apk add mailcap

WORKDIR /app

Expand Down
13 changes: 8 additions & 5 deletions api/helper/save_media.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
2 changes: 1 addition & 1 deletion api/model/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 15 additions & 15 deletions pkg/whatsapp/whatsapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const (
Image
Document
Sticker
Video
// Video
)

func (m MediaType) String() string {
Expand All @@ -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"
}
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 6d455b9

Please sign in to comment.