New icons format

This commit is contained in:
Gregory Brzezinski 2023-07-22 18:55:23 +03:00
parent 9f60c185ad
commit 3636cb86e2
6 changed files with 31 additions and 6 deletions

View File

@ -1,5 +1,6 @@
package appCtx package appCtx
//TODO to websiteapp package
type AppContext struct { type AppContext struct {
IsMobile bool `json:"isMobile"` IsMobile bool `json:"isMobile"`
BundlePath string `json:"bundlePath"` BundlePath string `json:"bundlePath"`

View File

@ -2,6 +2,7 @@ package libs
import ( import (
"net/http" "net/http"
"path"
"personalwebsite/webfilesystem" "personalwebsite/webfilesystem"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
@ -35,6 +36,22 @@ func (l *ImagLib) PublicRoutes(route *gin.RouterGroup) {
ctx.Data(http.StatusOK, "image/jpeg", imgData.Bin) 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) { func GetBase64Image(img *Base64Img, min string) (string, error) {

View File

@ -74,6 +74,7 @@ func main() {
blogViewerApp := blogviewer.NewBlogViewerApp(webfs) blogViewerApp := blogviewer.NewBlogViewerApp(webfs)
blogWriterApp := blogwriter.NewBlogWriterApp(webfs) blogWriterApp := blogwriter.NewBlogWriterApp(webfs)
sunBoardApp := sunboard.NewSunboardApp(webfs, appsStorage) sunBoardApp := sunboard.NewSunboardApp(webfs, appsStorage)
appsStorage.Apps["personal-properties"] = persPropsApp appsStorage.Apps["personal-properties"] = persPropsApp
appsStorage.Apps["finder"] = finderApp appsStorage.Apps["finder"] = finderApp
appsStorage.Apps["img-viewer"] = imgViewerApp appsStorage.Apps["img-viewer"] = imgViewerApp

BIN
test-img/16.png (Stored with Git LFS) Normal file

Binary file not shown.

BIN
test-img/32.png (Stored with Git LFS) Normal file

Binary file not shown.

View File

@ -28,28 +28,28 @@ func (w *WDE) RenderFileTileView(directory string, host string) (gin.H, error) {
} }
for _, file := range list { for _, file := range list {
file.Icon = w.GetIconPathForFile(file, directory) file.Icon = w.GetIconPathForFile(file, directory, "32")
} }
return gin.H{ return gin.H{
"Files": list, "Files": list,
}, nil }, 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 != "" { if fileHeader.Icon != "" {
return "/system/libs/img/get?path=" + fileHeader.Icon return "/system/libs/img/icon/get?path=" + fileHeader.Icon
} }
switch fileHeader.GetType() { switch fileHeader.GetType() {
case "directory": 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": case "jpeg":
fallthrough fallthrough
case "png": case "png":
fallthrough fallthrough
case "jpg": 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: default:
return "/system/libs/img/get?path=/wde/icons/macos9/folder.png" return "/system/libs/img/icon/get?path=/Icons2/GenericFolder.icn&size=" + size
} }
} }