mirror of
https://github.com/simon987/imhashdb.git
synced 2025-12-15 23:49:01 +00:00
Change hash types
This commit is contained in:
29
web/api.go
29
web/api.go
@@ -14,6 +14,23 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
func CORSMiddleware() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
c.Writer.Header().Set("Access-Control-Allow-Origin", "*")
|
||||
c.Writer.Header().Set("Access-Control-Max-Age", "86400")
|
||||
c.Writer.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE, UPDATE")
|
||||
c.Writer.Header().Set("Access-Control-Allow-Headers", "X-Requested-With, Content-Type, Origin, Authorization, Accept, Client-Security-Token, Accept-Encoding, x-access-token")
|
||||
c.Writer.Header().Set("Access-Control-Expose-Headers", "Content-Length")
|
||||
c.Writer.Header().Set("Access-Control-Allow-Credentials", "true")
|
||||
|
||||
if c.Request.Method == "OPTIONS" {
|
||||
c.AbortWithStatus(200)
|
||||
} else {
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func submitQuery(value string) bool {
|
||||
if Rdb.SIsMember(wipQueue, value).Val() {
|
||||
return false
|
||||
@@ -80,17 +97,18 @@ func hash(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if req.Data == nil {
|
||||
c.JSON(400, gin.H{"err": "Invalid request"})
|
||||
return
|
||||
}
|
||||
|
||||
h, err := ComputeHash(req.Data)
|
||||
if err != nil {
|
||||
c.JSON(500, gin.H{"err": "Couldn't compute image hash"})
|
||||
return
|
||||
}
|
||||
|
||||
b, _ := easyjson.Marshal(HashResp{
|
||||
AHash: h.AHash.Bytes, DHash: h.DHash.Bytes,
|
||||
MHash: h.MHash.Bytes, PHash: h.PHash.Bytes,
|
||||
WHash: h.WHash.Bytes,
|
||||
})
|
||||
b, _ := easyjson.Marshal(h)
|
||||
c.Data(200, gin.MIMEJSON, b)
|
||||
}
|
||||
|
||||
@@ -110,6 +128,7 @@ func main() {
|
||||
}()
|
||||
|
||||
r := gin.Default()
|
||||
r.Use(CORSMiddleware())
|
||||
r.POST("/api/hash", hash)
|
||||
r.POST("/api/query", query)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user