diff --git a/service/profile/api.go b/service/profile/api.go index 7b02e914..b7fa8079 100644 --- a/service/profile/api.go +++ b/service/profile/api.go @@ -100,7 +100,12 @@ func handleGetProfileIcon(ar *api.Request) (data []byte, err error) { // Get profile icon. data, err = binmeta.GetProfileIcon(name) - if err != nil { + switch { + case err == nil: + // Continue + case errors.Is(err, binmeta.IconIgnored): + return nil, api.ErrorWithStatus(err, http.StatusNotFound) + default: return nil, err } diff --git a/service/profile/binmeta/icons.go b/service/profile/binmeta/icons.go index 595fbb10..04a8bcb2 100644 --- a/service/profile/binmeta/icons.go +++ b/service/profile/binmeta/icons.go @@ -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 { diff --git a/service/profile/binmeta/ignore.go b/service/profile/binmeta/ignore.go new file mode 100644 index 00000000..e708ae84 --- /dev/null +++ b/service/profile/binmeta/ignore.go @@ -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 +} diff --git a/service/profile/profile.go b/service/profile/profile.go index fff41908..a97cd38c 100644 --- a/service/profile/profile.go +++ b/service/profile/profile.go @@ -515,7 +515,13 @@ func (profile *Profile) updateMetadataFromSystem(ctx context.Context, md Matchin // Get binary icon and name. newIcon, newName, err := binmeta.GetIconAndName(ctx, profile.PresentationPath, home) - if err != nil { + switch { + case err == nil: + // Continue + case errors.Is(err, binmeta.IconIgnored): + newIcon = nil + // Continue + default: log.Warningf("profile: failed to get binary icon/name for %s: %s", profile.PresentationPath, err) }