Store hashed ips. Display unique ip count in catalog
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"net"
|
||||
"net/http"
|
||||
"strings"
|
||||
@@ -43,3 +45,8 @@ func GetIP(r *http.Request) string {
|
||||
}
|
||||
return ip
|
||||
}
|
||||
|
||||
func HashIp(ip string) string {
|
||||
checksum := sha256.Sum256([]byte(ip))
|
||||
return hex.EncodeToString(checksum[:])
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/disintegration/imaging"
|
||||
"github.com/dominicf2001/comfychan/internal/database"
|
||||
)
|
||||
|
||||
// 10 MB memory limit
|
||||
@@ -102,3 +103,11 @@ func SavePostFile(file *multipart.File, filename string) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func SumUniquePostIps(posts []database.Post) int {
|
||||
uniqueIpHashes := map[string]bool{}
|
||||
for _, post := range posts {
|
||||
uniqueIpHashes[post.IpHash] = true
|
||||
}
|
||||
return len(uniqueIpHashes)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user