fix(attachments): accept images and return after error responses
This commit is contained in:
@@ -21,7 +21,7 @@ SELECT
|
|||||||
sqlc.arg(size_bytes)::int,
|
sqlc.arg(size_bytes)::int,
|
||||||
sqlc.arg(sha256)::text,
|
sqlc.arg(sha256)::text,
|
||||||
sqlc.arg(status)::attachment_status,
|
sqlc.arg(status)::attachment_status,
|
||||||
sqlc.arg(error_code)::text
|
NULLIF(sqlc.arg(error_code)::text, '')
|
||||||
WHERE EXISTS (
|
WHERE EXISTS (
|
||||||
SELECT 1 FROM chat_members
|
SELECT 1 FROM chat_members
|
||||||
WHERE chat_id = sqlc.arg(chat_id)
|
WHERE chat_id = sqlc.arg(chat_id)
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ SELECT
|
|||||||
$7::int,
|
$7::int,
|
||||||
$8::text,
|
$8::text,
|
||||||
$9::attachment_status,
|
$9::attachment_status,
|
||||||
$10::text
|
NULLIF($10::text, '')
|
||||||
WHERE EXISTS (
|
WHERE EXISTS (
|
||||||
SELECT 1 FROM chat_members
|
SELECT 1 FROM chat_members
|
||||||
WHERE chat_id = $2
|
WHERE chat_id = $2
|
||||||
|
|||||||
@@ -63,10 +63,13 @@ func (h *AttachmentHandler) Upload(w http.ResponseWriter, r *http.Request) {
|
|||||||
switch {
|
switch {
|
||||||
case errors.Is(err, service.ErrInvalidSize):
|
case errors.Is(err, service.ErrInvalidSize):
|
||||||
httpx.WriteError(w, http.StatusRequestEntityTooLarge, dto.ErrorCodeInvalidRequest, "file too large", requestID)
|
httpx.WriteError(w, http.StatusRequestEntityTooLarge, dto.ErrorCodeInvalidRequest, "file too large", requestID)
|
||||||
|
return
|
||||||
case errors.Is(err, service.ErrInvalidImage):
|
case errors.Is(err, service.ErrInvalidImage):
|
||||||
httpx.WriteError(w, http.StatusUnsupportedMediaType, dto.ErrorCodeInvalidRequest, "invalid image", requestID)
|
httpx.WriteError(w, http.StatusUnsupportedMediaType, dto.ErrorCodeInvalidRequest, "invalid image", requestID)
|
||||||
|
return
|
||||||
case errors.Is(err, service.ErrAttachmentNotFound):
|
case errors.Is(err, service.ErrAttachmentNotFound):
|
||||||
httpx.WriteError(w, http.StatusNotFound, dto.ErrorCodeNotFound, "not found", requestID)
|
httpx.WriteError(w, http.StatusNotFound, dto.ErrorCodeNotFound, "not found", requestID)
|
||||||
|
return
|
||||||
case err != nil:
|
case err != nil:
|
||||||
httpx.WriteInternalError(w, requestID, err)
|
httpx.WriteInternalError(w, requestID, err)
|
||||||
return
|
return
|
||||||
@@ -89,6 +92,7 @@ func (h *AttachmentHandler) Get(w http.ResponseWriter, r *http.Request) {
|
|||||||
switch {
|
switch {
|
||||||
case errors.Is(err, service.ErrAttachmentNotFound):
|
case errors.Is(err, service.ErrAttachmentNotFound):
|
||||||
httpx.WriteError(w, http.StatusNotFound, dto.ErrorCodeNotFound, "not found", requestID)
|
httpx.WriteError(w, http.StatusNotFound, dto.ErrorCodeNotFound, "not found", requestID)
|
||||||
|
return
|
||||||
case err != nil:
|
case err != nil:
|
||||||
httpx.WriteInternalError(w, requestID, err)
|
httpx.WriteInternalError(w, requestID, err)
|
||||||
return
|
return
|
||||||
@@ -111,6 +115,7 @@ func (h *AttachmentHandler) GetContent(w http.ResponseWriter, r *http.Request) {
|
|||||||
switch {
|
switch {
|
||||||
case errors.Is(err, service.ErrAttachmentNotFound):
|
case errors.Is(err, service.ErrAttachmentNotFound):
|
||||||
httpx.WriteError(w, http.StatusNotFound, dto.ErrorCodeNotFound, "not found", requestID)
|
httpx.WriteError(w, http.StatusNotFound, dto.ErrorCodeNotFound, "not found", requestID)
|
||||||
|
return
|
||||||
case err != nil:
|
case err != nil:
|
||||||
httpx.WriteInternalError(w, requestID, err)
|
httpx.WriteInternalError(w, requestID, err)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ import (
|
|||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"errors"
|
"errors"
|
||||||
"image"
|
"image"
|
||||||
|
_ "image/jpeg"
|
||||||
|
_ "image/png"
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
|
|||||||
Reference in New Issue
Block a user