Ignore default windows icons
This commit is contained in:
@@ -19,6 +19,9 @@ import (
|
||||
// Must not be changed once set.
|
||||
var ProfileIconStoragePath = ""
|
||||
|
||||
// IconIgnored is returned when the icon should be ignored.
|
||||
var IconIgnored = errors.New("icon is ignored")
|
||||
|
||||
// GetProfileIcon returns the profile icon with the given ID and extension.
|
||||
func GetProfileIcon(name string) (data []byte, err error) {
|
||||
// Check if enabled.
|
||||
@@ -26,6 +29,11 @@ func GetProfileIcon(name string) (data []byte, err error) {
|
||||
return nil, errors.New("api icon storage not configured")
|
||||
}
|
||||
|
||||
// Check if icon should be ignored.
|
||||
if IgnoreIcon(name) {
|
||||
return nil, IconIgnored
|
||||
}
|
||||
|
||||
// Build storage path.
|
||||
iconPath := filepath.Clean(
|
||||
filepath.Join(ProfileIconStoragePath, name),
|
||||
@@ -59,6 +67,11 @@ func UpdateProfileIcon(data []byte, ext string) (filename string, err error) {
|
||||
}
|
||||
sum := hex.EncodeToString(h.Sum(nil))
|
||||
|
||||
// Check if icon should be ignored.
|
||||
if IgnoreIcon(sum) {
|
||||
return "", IconIgnored
|
||||
}
|
||||
|
||||
// Check ext.
|
||||
ext = strings.ToLower(ext)
|
||||
switch ext {
|
||||
|
||||
30
service/profile/binmeta/ignore.go
Normal file
30
service/profile/binmeta/ignore.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package binmeta
|
||||
|
||||
import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
var ignoreIcons = map[string]struct{}{
|
||||
// Windows Default Icons.
|
||||
"a27898ddfa4e0481b62c69faa196919a738fcade": {},
|
||||
"5a3eea8bcd08b9336ce9c5083f26185164268ee9": {},
|
||||
"573393d6ad238d255b20dc1c1b303c95debe6965": {},
|
||||
"d459b2cb23c27cc31ccab5025533048d5d8301bf": {},
|
||||
"d35a0d91ebfda81df5286f68ec5ddb1d6ad6b850": {},
|
||||
"cc33187385498384f1b648e23be5ef1a2e9f5f71": {},
|
||||
}
|
||||
|
||||
// IgnoreIcon returns whether an icon should be ignored or not.
|
||||
func IgnoreIcon(name string) bool {
|
||||
// Make lower case.
|
||||
name = strings.ToLower(name)
|
||||
// Remove extension.
|
||||
extIndex := strings.Index(name, ".")
|
||||
if extIndex > 0 {
|
||||
name = name[:extIndex]
|
||||
}
|
||||
|
||||
// Check if ID is in list.
|
||||
_, found := ignoreIcons[name]
|
||||
return found
|
||||
}
|
||||
Reference in New Issue
Block a user