Basic global hash whitelist
This commit is contained in:
@@ -1,2 +1,30 @@
|
||||
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"})
|
||||
}
|
||||
|
||||
@@ -73,10 +73,23 @@ func GetDuplicates(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// Extract all hashes from source addon files
|
||||
// Get all whitelisted hashes
|
||||
var whitelistedHashes []string
|
||||
if err := initializers.DB.Model(&models.WhitelistedHash{}).Pluck("hash", &whitelistedHashes).Error; err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to fetch whitelisted hashes"})
|
||||
return
|
||||
}
|
||||
|
||||
// Create a map for faster lookup
|
||||
whitelistMap := make(map[string]bool)
|
||||
for _, hash := range whitelistedHashes {
|
||||
whitelistMap[hash] = true
|
||||
}
|
||||
|
||||
// Extract all hashes from source addon files, excluding whitelisted ones
|
||||
var sourceHashes []string
|
||||
for _, file := range sourceAddon.AddonFiles {
|
||||
if file.Hash != "" {
|
||||
if file.Hash != "" && !whitelistMap[file.Hash] {
|
||||
sourceHashes = append(sourceHashes, file.Hash)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user