diff --git a/wde/wde.go b/wde/wde.go index 7898ab5..ebc6a75 100644 --- a/wde/wde.go +++ b/wde/wde.go @@ -21,6 +21,7 @@ func NewWDE(webFs *webfilesystem.WebFileSystem) *WDE { type FilesWidget struct { } +// Deprecated func (w *WDE) Render(path string) (gin.H, error) { // list, err := w.fs.NewListDeprecated(path) // if err != nil { @@ -32,6 +33,7 @@ func (w *WDE) Render(path string) (gin.H, error) { }, nil } +// Deprecated func (w *WDE) RenderContextMenu() (gin.H, error) { // list, err := w.fs.List(path) // if err != nil { @@ -50,20 +52,28 @@ func (w *WDE) RenderFileTileView(directory string, host string) (gin.H, error) { } for _, file := range list { - switch file.Type { - case "directory": - file.Icon = host + "/system/libs/img/get?path=/wde/icons/macos9/folder.png" //FIXME - case "jpeg": - fallthrough - case "png": - fallthrough - case "jpg": - file.Icon = host + "/system/libs/img/get?path=" + path.Join(directory, file.Name) //FIXME - default: - file.Icon = host + "/system/libs/img/get?path=/wde/icons/macos9/folder.png" //FIXME - } + 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" + } +} diff --git a/webfilesystem/webfilesystem.go b/webfilesystem/webfilesystem.go index a10f475..a7675b7 100644 --- a/webfilesystem/webfilesystem.go +++ b/webfilesystem/webfilesystem.go @@ -30,9 +30,15 @@ type FileHeader struct { MongoId primitive.ObjectID `bson:"_id" json:"-"` Name string `bson:"name" json:"name"` Type string `bson:"type" json:"type"` - Icon string `bson:"-" json:"icon"` + Icon string `bson:"icon" json:"icon"` Data primitive.ObjectID `bson:"data_id" json:"-"` } + +func (fh *FileHeader) GetType() string { + //TODO return by extension and etc + return fh.Type +} + type BinaryFileData struct { MongoId primitive.ObjectID `bson:"_id" json:"-"` Bin []byte `bson:"bin" json:"-"`