personal-website/wde/wde.go

56 lines
1.1 KiB
Go
Raw Permalink Normal View History

2023-04-29 13:58:39 +00:00
package wde
import (
2023-05-02 00:12:43 +00:00
"path"
2023-04-29 13:58:39 +00:00
"personalwebsite/webfilesystem"
"github.com/gin-gonic/gin"
)
type WDE struct {
fs *webfilesystem.WebFileSystem
FilesWidget FilesWidget
}
func NewWDE(webFs *webfilesystem.WebFileSystem) *WDE {
return &WDE{
fs: webFs,
}
}
type FilesWidget struct {
}
2023-05-02 00:59:11 +00:00
func (w *WDE) RenderFileTileView(directory string, host string) (gin.H, error) {
2023-05-07 01:00:22 +00:00
list, err := w.fs.ListDir(directory)
2023-05-01 12:32:41 +00:00
if err != nil {
return nil, err
}
2023-05-07 00:14:30 +00:00
2023-05-01 12:32:41 +00:00
for _, file := range list {
2023-05-07 20:20:16 +00:00
file.Icon = w.GetIconPathForFile(file, directory)
2023-05-01 12:32:41 +00:00
}
return gin.H{
"Files": list,
}, nil
}
2023-05-07 20:20:16 +00:00
func (w *WDE) GetIconPathForFile(fileHeader *webfilesystem.FileHeader, parentDir string) string {
if fileHeader.Icon != "" {
return "/system/libs/img/get?path=" + fileHeader.Icon
}
switch fileHeader.GetType() {
case "directory":
return "/system/libs/img/get?path=/wde/icons/macos9/folder.png"
case "jpeg":
fallthrough
case "png":
fallthrough
case "jpg":
return "/system/libs/img/get?path=" + path.Join(parentDir, fileHeader.Name)
default:
return "/system/libs/img/get?path=/wde/icons/macos9/folder.png"
}
}