@@ -3,7 +3,6 @@ package fileicon
33import (
44 "context"
55 "html/template"
6- "os"
76 "path"
87 "strings"
98
@@ -72,39 +71,31 @@ func getFileIconNames(entry *git.TreeEntry) []string {
7271 return nil
7372}
7473
75- func loadCustomIcon (iconPath string ) (string , error ) {
76- log .Debug ("Loading custom icon from %s" , iconPath )
77-
78- if icon , ok := fileIconCache .Get (iconPath ); ok {
79- return icon , nil
80- }
81-
82- // Try to load the icon from the filesystem
83- if _ , err := os .Stat (iconPath ); err != nil {
84- return "" , err
85- }
86-
87- iconData , err := os .ReadFile (iconPath )
88- if err != nil {
89- return "" , err
90- }
91-
92- fileIconCache .Add (iconPath , string (iconData ))
93-
94- return string (iconData ), nil
74+ type fileIconBackend interface {
75+ GetIcon (string ) (string , error )
9576}
9677
9778// FileIcon returns a custom icon from a folder or the default octicon for displaying files/directories
9879func FileIcon (ctx context.Context , entry * git.TreeEntry ) template.HTML {
80+ backend := & fileIconHTTPBackend {
81+ theme : setting .UI .FileIconTheme ,
82+ baseURL : "https://raw.githubusercontent.com/anbraten/gitea-icons/refs/heads/master/gitea/" ,
83+ }
84+
9985 iconTheme := setting .UI .FileIconTheme
10086 if iconTheme != "" {
10187 iconNames := getFileIconNames (entry )
10288
10389 // Try to load the custom icon
10490 for _ , iconName := range iconNames {
105- iconPath := path .Join (setting .AppDataPath , "icons" , iconTheme , iconName + ".svg" )
106- if icon , err := loadCustomIcon (iconPath ); err == nil {
107- return svg .RenderHTMLFromString (icon )
91+ if icon , err := backend .GetIcon (iconName ); err == nil {
92+ if icon , ok := fileIconCache .Get (iconName ); ok {
93+ return svg .RenderHTMLFromString (icon )
94+ }
95+
96+ fileIconCache .Add (iconName , string (icon ))
97+
98+ return svg .RenderHTMLFromString (string (icon ))
10899 }
109100 }
110101 }
0 commit comments