mirror of
https://github.com/Damillora/Shioriko.git
synced 2025-02-23 09:23:38 +00:00
feat: make sure similar posts get marked before saving anything
This commit is contained in:
parent
50bf4efc75
commit
0b50cede44
1
go.mod
1
go.mod
@ -101,6 +101,7 @@ require (
|
|||||||
github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de4 // indirect
|
github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de4 // indirect
|
||||||
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
|
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
|
||||||
github.com/grpc-ecosystem/grpc-gateway v1.9.5 // indirect
|
github.com/grpc-ecosystem/grpc-gateway v1.9.5 // indirect
|
||||||
|
github.com/h2non/bimg v1.1.9 // indirect
|
||||||
github.com/hashicorp/consul/api v1.3.0 // indirect
|
github.com/hashicorp/consul/api v1.3.0 // indirect
|
||||||
github.com/hashicorp/consul/sdk v0.3.0 // indirect
|
github.com/hashicorp/consul/sdk v0.3.0 // indirect
|
||||||
github.com/hashicorp/errwrap v1.0.0 // indirect
|
github.com/hashicorp/errwrap v1.0.0 // indirect
|
||||||
|
2
go.sum
2
go.sum
@ -184,6 +184,8 @@ github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgf
|
|||||||
github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
|
github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
|
||||||
github.com/h2non/bimg v1.1.5 h1:o3xsUBxM8s7+e7PmpiWIkEYdeYayJ94eh4cJLx67m1k=
|
github.com/h2non/bimg v1.1.5 h1:o3xsUBxM8s7+e7PmpiWIkEYdeYayJ94eh4cJLx67m1k=
|
||||||
github.com/h2non/bimg v1.1.5/go.mod h1:R3+UiYwkK4rQl6KVFTOFJHitgLbZXBZNFh2cv3AEbp8=
|
github.com/h2non/bimg v1.1.5/go.mod h1:R3+UiYwkK4rQl6KVFTOFJHitgLbZXBZNFh2cv3AEbp8=
|
||||||
|
github.com/h2non/bimg v1.1.9 h1:WH20Nxko9l/HFm4kZCA3Phbgu2cbHvYzxwxn9YROEGg=
|
||||||
|
github.com/h2non/bimg v1.1.9/go.mod h1:R3+UiYwkK4rQl6KVFTOFJHitgLbZXBZNFh2cv3AEbp8=
|
||||||
github.com/hashicorp/consul/api v1.3.0/go.mod h1:MmDNSzIMUjNpY/mQ398R4bk2FnqQLoPndWW5VkKPlCE=
|
github.com/hashicorp/consul/api v1.3.0/go.mod h1:MmDNSzIMUjNpY/mQ398R4bk2FnqQLoPndWW5VkKPlCE=
|
||||||
github.com/hashicorp/consul/sdk v0.3.0/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8=
|
github.com/hashicorp/consul/sdk v0.3.0/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8=
|
||||||
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
|
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
|
||||||
|
@ -107,6 +107,28 @@ 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)
|
||||||
|
filePath := filepath.Join(dataDir, folder1, folder2, filename)
|
||||||
|
err = c.SaveUploadedFile(file, filePath)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusBadRequest, models.ErrorResponse{
|
||||||
|
Code: http.StatusBadRequest,
|
||||||
|
Message: err.Error(),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
previewImage := imaging.Resize(originalImage, 1000, 0, imaging.Lanczos)
|
previewImage := imaging.Resize(originalImage, 1000, 0, imaging.Lanczos)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(http.StatusBadRequest, models.ErrorResponse{
|
c.JSON(http.StatusBadRequest, models.ErrorResponse{
|
||||||
@ -158,17 +180,6 @@ func uploadBlob(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
filename := id + filepath.Ext(file.Filename)
|
|
||||||
filePath := filepath.Join(dataDir, folder1, folder2, filename)
|
|
||||||
err = c.SaveUploadedFile(file, filePath)
|
|
||||||
if err != nil {
|
|
||||||
c.JSON(http.StatusBadRequest, models.ErrorResponse{
|
|
||||||
Code: http.StatusBadRequest,
|
|
||||||
Message: err.Error(),
|
|
||||||
})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
blob := database.Blob{
|
blob := database.Blob{
|
||||||
ID: id,
|
ID: id,
|
||||||
FilePath: filepath.Join(folder1, folder2, filename),
|
FilePath: filepath.Join(folder1, folder2, filename),
|
||||||
@ -184,21 +195,10 @@ func uploadBlob(c *gin.Context) {
|
|||||||
|
|
||||||
database.DB.Create(&blob)
|
database.DB.Create(&blob)
|
||||||
|
|
||||||
if len(similarPosts) > 0 {
|
c.JSON(http.StatusOK, models.BlobResponse{
|
||||||
c.JSON(http.StatusOK,
|
ID: id,
|
||||||
models.BlobSimilarResponse{
|
Width: width,
|
||||||
ID: id,
|
Height: height,
|
||||||
Width: width,
|
})
|
||||||
Height: height,
|
return
|
||||||
Similar: similarPosts,
|
|
||||||
})
|
|
||||||
return
|
|
||||||
} else {
|
|
||||||
c.JSON(http.StatusOK, models.BlobResponse{
|
|
||||||
ID: id,
|
|
||||||
Width: width,
|
|
||||||
Height: height,
|
|
||||||
})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user