31 lines
762 B
Go
31 lines
762 B
Go
package controllers
|
|
|
|
import (
|
|
"gitea.tbdevent.eu/TBD/reforger_crawler_main/initializers"
|
|
"gitea.tbdevent.eu/TBD/reforger_crawler_main/models"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func AddWhitelistedHash(c *gin.Context) {
|
|
hash := c.PostForm("hash")
|
|
if hash == "" {
|
|
c.JSON(400, gin.H{"error": "Hash is required"})
|
|
return
|
|
}
|
|
|
|
hashAddon := models.WhitelistedHash{Hash: hash}
|
|
|
|
ret := initializers.DB.Find(&models.WhitelistedHash{}, "hash = ?", hash)
|
|
if ret.RowsAffected > 0 {
|
|
c.JSON(400, gin.H{"error": "Hash already whitelisted"})
|
|
return
|
|
}
|
|
|
|
if err := initializers.DB.Create(&hashAddon).Error; err != nil {
|
|
c.JSON(500, gin.H{"error": "Failed to add whitelisted hash"})
|
|
return
|
|
}
|
|
|
|
c.JSON(200, gin.H{"message": "Whitelisted hash added successfully"})
|
|
}
|