From 3636cb86e245645985eec301dcc7150719e181c6 Mon Sep 17 00:00:00 2001 From: Gregory Brzezinski Date: Sat, 22 Jul 2023 18:55:23 +0300 Subject: [PATCH] New icons format --- apps/appCtx/appContext.go | 1 + libs/imglib.go | 17 +++++++++++++++++ main.go | 1 + test-img/16.png | 3 +++ test-img/32.png | 3 +++ wde/wde.go | 12 ++++++------ 6 files changed, 31 insertions(+), 6 deletions(-) create mode 100644 test-img/16.png create mode 100644 test-img/32.png diff --git a/apps/appCtx/appContext.go b/apps/appCtx/appContext.go index 44c4f9a..72690ce 100644 --- a/apps/appCtx/appContext.go +++ b/apps/appCtx/appContext.go @@ -1,5 +1,6 @@ package appCtx +//TODO to websiteapp package type AppContext struct { IsMobile bool `json:"isMobile"` BundlePath string `json:"bundlePath"` diff --git a/libs/imglib.go b/libs/imglib.go index 9ec9eb9..061a206 100644 --- a/libs/imglib.go +++ b/libs/imglib.go @@ -2,6 +2,7 @@ package libs import ( "net/http" + "path" "personalwebsite/webfilesystem" "github.com/gin-gonic/gin" @@ -35,6 +36,22 @@ func (l *ImagLib) PublicRoutes(route *gin.RouterGroup) { ctx.Data(http.StatusOK, "image/jpeg", imgData.Bin) }) + iconGroup := route.Group("icon") + iconGroup.GET("get", func(ctx *gin.Context) { + iconPath := ctx.Query("path") + iconType := ctx.Query("type") + _ = iconType + iconSize := ctx.Query("size") + + imgData := Img{} + _, err := l.fs.Read(path.Join(iconPath, "color", iconSize+".png"), &imgData) + if err != nil { + ctx.Status(http.StatusInternalServerError) + return + } + ctx.Data(http.StatusOK, "image/jpeg", imgData.Bin) + }) + } func GetBase64Image(img *Base64Img, min string) (string, error) { diff --git a/main.go b/main.go index 73a1dae..9666ba3 100644 --- a/main.go +++ b/main.go @@ -74,6 +74,7 @@ func main() { blogViewerApp := blogviewer.NewBlogViewerApp(webfs) blogWriterApp := blogwriter.NewBlogWriterApp(webfs) sunBoardApp := sunboard.NewSunboardApp(webfs, appsStorage) + appsStorage.Apps["personal-properties"] = persPropsApp appsStorage.Apps["finder"] = finderApp appsStorage.Apps["img-viewer"] = imgViewerApp diff --git a/test-img/16.png b/test-img/16.png new file mode 100644 index 0000000..48c03b8 --- /dev/null +++ b/test-img/16.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e5372e8f8659b9c1b70def20ffdbc418710eb96503a44992e13246941a589d6e +size 567 diff --git a/test-img/32.png b/test-img/32.png new file mode 100644 index 0000000..4e95f49 --- /dev/null +++ b/test-img/32.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:83a18ca489a0483d157c7d7728f902bfef6ae0305a8a4ed40e72075b7e1b5705 +size 1238 diff --git a/wde/wde.go b/wde/wde.go index 2103996..9f89d33 100644 --- a/wde/wde.go +++ b/wde/wde.go @@ -28,28 +28,28 @@ func (w *WDE) RenderFileTileView(directory string, host string) (gin.H, error) { } for _, file := range list { - file.Icon = w.GetIconPathForFile(file, directory) + file.Icon = w.GetIconPathForFile(file, directory, "32") } return gin.H{ "Files": list, }, nil } -func (w *WDE) GetIconPathForFile(fileHeader *webfilesystem.FileHeader, parentDir string) string { +func (w *WDE) GetIconPathForFile(fileHeader *webfilesystem.FileHeader, parentDir string, size string) string { if fileHeader.Icon != "" { - return "/system/libs/img/get?path=" + fileHeader.Icon + return "/system/libs/img/icon/get?path=" + fileHeader.Icon } switch fileHeader.GetType() { case "directory": - return "/system/libs/img/get?path=/wde/icons/macos9/folder.png" + return "/system/libs/img/icon/get?path=/Icons2/GenericFolder.icn&size=" + size case "jpeg": fallthrough case "png": fallthrough case "jpg": - return "/system/libs/img/get?path=" + path.Join(parentDir, fileHeader.Name) + return "/system/libs/img/icon/get?path=" + path.Join(parentDir, fileHeader.Name) + "&size=" + size default: - return "/system/libs/img/get?path=/wde/icons/macos9/folder.png" + return "/system/libs/img/icon/get?path=/Icons2/GenericFolder.icn&size=" + size } }