custom icons support

This commit is contained in:
cyber-dream 2023-05-07 23:20:16 +03:00
parent ea65976d01
commit 113b7ebc37
2 changed files with 29 additions and 13 deletions

View File

@ -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"
}
}

View File

@ -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:"-"`