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)
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
}

View File

@ -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"`