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 { } // Deprecated func (w *WDE) Render(path string) (gin.H, error) { // list, err := w.fs.NewListDeprecated(path) // if err != nil { // return nil, err // } return gin.H{ "Name": "Greg Brzezinski", // "Files": list, }, nil } // Deprecated func (w *WDE) RenderContextMenu() (gin.H, error) { // list, err := w.fs.List(path) // if err != nil { // return nil, err // } return gin.H{ "Name": "Greg Brzezinski", // "Files": list, }, nil } 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) } return gin.H{ "Files": list, }, nil } 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" } }