feat(widget): support chatwoot direct upload attachments
This commit is contained in:
@@ -2,6 +2,7 @@ package v1
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
@@ -48,6 +49,23 @@ func (h *UploadHandler) Upload(c *gin.Context) {
|
||||
// DirectUpload handles POST /api/v1/widget/direct_uploads — widget direct file upload.
|
||||
// Reference: Chatwoot POST /widget/direct_uploads
|
||||
func (h *UploadHandler) DirectUpload(c *gin.Context) {
|
||||
if strings.Contains(c.GetHeader("Content-Type"), "application/json") {
|
||||
var req service.ActiveStorageDirectUploadRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
response.AbortWithStatusError(c, http.StatusBadRequest, response.ErrValidation, "invalid direct upload metadata")
|
||||
return
|
||||
}
|
||||
req.WebsiteToken = c.Query("website_token")
|
||||
req.AuthToken = c.GetHeader("X-Auth-Token")
|
||||
result, svcErr := h.svc.CreateWidgetDirectUpload(c.Request.Context(), req)
|
||||
if svcErr != nil {
|
||||
handleServiceError(c, svcErr)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, result)
|
||||
return
|
||||
}
|
||||
|
||||
fileHeader, err := c.FormFile("file")
|
||||
if err != nil {
|
||||
response.AbortWithStatusError(c, http.StatusBadRequest, response.ErrValidation, "file is required")
|
||||
@@ -65,6 +83,15 @@ func (h *UploadHandler) DirectUpload(c *gin.Context) {
|
||||
response.OK(c, result)
|
||||
}
|
||||
|
||||
func (h *UploadHandler) CompleteWidgetDirectUpload(c *gin.Context) {
|
||||
result, svcErr := h.svc.CompleteWidgetDirectUpload(c.Request.Context(), c.Param("upload_uuid"), c.Request.Body)
|
||||
if svcErr != nil {
|
||||
handleServiceError(c, svcErr)
|
||||
return
|
||||
}
|
||||
response.OK(c, result)
|
||||
}
|
||||
|
||||
// AccountDirectUpload handles POST /api/v1/accounts/:id/direct_uploads — account-level staged upload.
|
||||
// Returns a blob/UUID for later attachment to messages.
|
||||
// Reference: Chatwoot POST /api/v1/accounts/:account_id/direct_uploads
|
||||
@@ -90,4 +117,4 @@ func (h *UploadHandler) AccountDirectUpload(c *gin.Context) {
|
||||
}
|
||||
|
||||
response.OK(c, result)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user