56 lines
1.2 KiB
Go
56 lines
1.2 KiB
Go
package wde
|
|
|
|
import (
|
|
"path"
|
|
"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 {
|
|
}
|
|
|
|
func (w *WDE) RenderFileTileView(directory string, host string) (gin.H, error) {
|
|
list, err := w.fs.ListDir(directory)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
for _, file := range list {
|
|
file.Icon = w.GetIconPathForFile(file, directory, "32")
|
|
}
|
|
return gin.H{
|
|
"Files": list,
|
|
}, nil
|
|
}
|
|
|
|
func (w *WDE) GetIconPathForFile(fileHeader *webfilesystem.FileHeader, parentDir string, size string) string {
|
|
if fileHeader.Icon != "" {
|
|
return "/system/libs/img/icon/get?path=" + fileHeader.Icon
|
|
}
|
|
|
|
switch fileHeader.GetType() {
|
|
case "directory":
|
|
return "/system/libs/img/icon/get?path=/Icons2/GenericFolder.icn&size=" + size
|
|
case "jpeg":
|
|
fallthrough
|
|
case "png":
|
|
fallthrough
|
|
case "jpg":
|
|
return "/system/libs/img/icon/get?path=" + path.Join(parentDir, fileHeader.Name) + "&size=" + size
|
|
default:
|
|
return "/system/libs/img/icon/get?path=/Icons2/GenericFolder.icn&size=" + size
|
|
}
|
|
}
|