Change hash types

This commit is contained in:
2020-04-12 13:11:55 -04:00
parent 25a19ab557
commit 91f0c9b1f9
8 changed files with 470 additions and 174 deletions

View File

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