[server] Sending 204 instead of 404 for no data (#5880)

## Description

## Tests
This commit is contained in:
Neeraj
2025-05-12 16:59:44 +05:30
committed by GitHub
4 changed files with 15 additions and 2 deletions

View File

@@ -63,8 +63,9 @@ func (g *GetFilesData) Validate() error {
}
type GetFileData struct {
FileID int64 `form:"fileID" binding:"required"`
Type ente.ObjectType `form:"type" binding:"required"`
FileID int64 `form:"fileID" binding:"required"`
Type ente.ObjectType `form:"type" binding:"required"`
PreferNoContent bool `form:"preferNoContent"`
}
func (g *GetFileData) Validate() error {

View File

@@ -109,6 +109,10 @@ func (h *FileHandler) GetFileData(ctx *gin.Context) {
handler.Error(ctx, err)
return
}
if resp == nil {
ctx.Status(http.StatusNoContent)
return
}
ctx.JSON(http.StatusOK, gin.H{
"data": resp,
})

View File

@@ -79,6 +79,10 @@ func (h *PublicCollectionHandler) GetFileData(c *gin.Context) {
handler.Error(c, err)
return
}
if resp == nil {
c.Status(http.StatusNoContent)
return
}
c.JSON(http.StatusOK, gin.H{
"data": resp,
})

View File

@@ -2,6 +2,7 @@ package filedata
import (
"context"
"database/sql"
"errors"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/s3"
@@ -138,6 +139,9 @@ func (c *Controller) GetFileData(ctx *gin.Context, actorUser int64, req fileData
}
doRows, err := c.Repo.GetFilesData(ctx, req.Type, []int64{req.FileID})
if err != nil {
if errors.Is(err, sql.ErrNoRows) && req.PreferNoContent {
return nil, nil
}
return nil, stacktrace.Propagate(err, "")
}
if len(doRows) == 0 || doRows[0].IsDeleted {