diff --git a/pkg/app/blob_routes.go b/pkg/app/blob_routes.go index 52ee017..376bf86 100644 --- a/pkg/app/blob_routes.go +++ b/pkg/app/blob_routes.go @@ -107,17 +107,6 @@ func uploadBlob(c *gin.Context) { hashSlice := make([]byte, 8) binary.LittleEndian.PutUint64(hashSlice, hashInt) - if len(similarPosts) > 0 { - c.JSON(http.StatusOK, - models.BlobSimilarResponse{ - ID: id, - Width: width, - Height: height, - Similar: similarPosts, - }) - return - } - filename := id + filepath.Ext(file.Filename) filePath := filepath.Join(dataDir, folder1, folder2, filename) err = c.SaveUploadedFile(file, filePath) @@ -197,11 +186,22 @@ func uploadBlob(c *gin.Context) { database.DB.Create(&blob) - c.JSON(http.StatusOK, models.BlobResponse{ - ID: id, - Width: width, - Height: height, - PreviewUrl: "/data/" + blob.PreviewFilePath, - }) + if len(similarPosts) > 0 { + c.JSON(http.StatusOK, + models.BlobSimilarResponse{ + ID: id, + Width: width, + Height: height, + PreviewUrl: "/data/" + blob.PreviewFilePath, + Similar: similarPosts, + }) + } else { + c.JSON(http.StatusOK, models.BlobResponse{ + ID: id, + Width: width, + Height: height, + PreviewUrl: "/data/" + blob.PreviewFilePath, + }) + } return } diff --git a/pkg/models/responses.go b/pkg/models/responses.go index 63097d6..e999360 100644 --- a/pkg/models/responses.go +++ b/pkg/models/responses.go @@ -22,10 +22,11 @@ type BlobResponse struct { } type BlobSimilarResponse struct { - ID string `json:"id"` - Width int `json:"width"` - Height int `json:"height"` - Similar []PostSimilarityListItem `json:"similar"` + ID string `json:"id"` + Width int `json:"width"` + Height int `json:"height"` + PreviewUrl string `json:"previewUrl"` + Similar []PostSimilarityListItem `json:"similar"` } type PostPaginationResponse struct { CurrentPage int `json:"currentPage"`