feat: reallow similar images to be uploaded

This commit is contained in:
Damillora 2025-02-22 16:07:12 +00:00
parent 3d40add1b2
commit 44075dbab9
2 changed files with 22 additions and 21 deletions

View File

@ -107,17 +107,6 @@ func uploadBlob(c *gin.Context) {
hashSlice := make([]byte, 8) hashSlice := make([]byte, 8)
binary.LittleEndian.PutUint64(hashSlice, hashInt) 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) filename := id + filepath.Ext(file.Filename)
filePath := filepath.Join(dataDir, folder1, folder2, filename) filePath := filepath.Join(dataDir, folder1, folder2, filename)
err = c.SaveUploadedFile(file, filePath) err = c.SaveUploadedFile(file, filePath)
@ -197,11 +186,22 @@ func uploadBlob(c *gin.Context) {
database.DB.Create(&blob) database.DB.Create(&blob)
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{ c.JSON(http.StatusOK, models.BlobResponse{
ID: id, ID: id,
Width: width, Width: width,
Height: height, Height: height,
PreviewUrl: "/data/" + blob.PreviewFilePath, PreviewUrl: "/data/" + blob.PreviewFilePath,
}) })
}
return return
} }

View File

@ -25,6 +25,7 @@ type BlobSimilarResponse struct {
ID string `json:"id"` ID string `json:"id"`
Width int `json:"width"` Width int `json:"width"`
Height int `json:"height"` Height int `json:"height"`
PreviewUrl string `json:"previewUrl"`
Similar []PostSimilarityListItem `json:"similar"` Similar []PostSimilarityListItem `json:"similar"`
} }
type PostPaginationResponse struct { type PostPaginationResponse struct {