Working img viewer
This commit is contained in:
parent
5736b8de31
commit
c95501dbb7
@ -4,7 +4,6 @@ import (
|
|||||||
"personalwebsite/apps"
|
"personalwebsite/apps"
|
||||||
"personalwebsite/wde"
|
"personalwebsite/wde"
|
||||||
"personalwebsite/webfilesystem"
|
"personalwebsite/webfilesystem"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
@ -36,72 +35,32 @@ func (f *FinderApplication) Render(isMobile bool) gin.H {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (f *FinderApplication) RenderContextMenu(context string, data string) gin.H {
|
func (f *FinderApplication) RenderContextMenu(context string, data string) gin.H {
|
||||||
islands := [][]wde.ContexMenuRow{} //FIXME
|
islands := [][]wde.ContexMenuRow{}
|
||||||
switch context {
|
|
||||||
case "FileTileView":
|
islands = append(islands, []wde.ContexMenuRow{
|
||||||
islands = [][]wde.ContexMenuRow{
|
{Label: "Get Info", Action: "getInfo"},
|
||||||
{
|
})
|
||||||
{
|
if context == "FileTileView" {
|
||||||
Label: "Get Info",
|
return gin.H{
|
||||||
Action: strings.Join([]string{"getInfo"}[:], ","),
|
"Islands": islands,
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
{
|
|
||||||
Label: "New Directory",
|
|
||||||
Action: strings.Join([]string{"createDir"}[:], ","),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
case "directory":
|
|
||||||
islands = [][]wde.ContexMenuRow{
|
|
||||||
{
|
|
||||||
{
|
|
||||||
Label: "Test",
|
|
||||||
Action: strings.Join([]string{""}[:], ","),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Label: "Delete",
|
|
||||||
Action: strings.Join([]string{""}[:], ","),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
{
|
|
||||||
Label: "Get Info",
|
|
||||||
Action: strings.Join([]string{""}[:], ","),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
islands = [][]wde.ContexMenuRow{
|
|
||||||
{
|
|
||||||
{
|
|
||||||
Label: "temp Menu 1",
|
|
||||||
Action: strings.Join([]string{""}[:], ","),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Label: "temp Menu 2",
|
|
||||||
Action: strings.Join([]string{""}[:], ","),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Label: "temp Menu 3",
|
|
||||||
Action: strings.Join([]string{""}[:], ","),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Label: "temp Menu 4",
|
|
||||||
Action: strings.Join([]string{""}[:], ","),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
islands = append(islands, []wde.ContexMenuRow{
|
islands = append(islands, []wde.ContexMenuRow{
|
||||||
{
|
{Label: "Delete File", Action: "deleteFile"},
|
||||||
Label: "Delete File",
|
// {Label: "Get Info", Action: "getInfo"},
|
||||||
Action: strings.Join([]string{"deleteFile"}[:], ";"),
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
switch context {
|
||||||
|
case "directory":
|
||||||
|
|
||||||
|
default:
|
||||||
|
islands = append(islands, []wde.ContexMenuRow{
|
||||||
|
{Label: "temp Menu 1", Action: ""},
|
||||||
|
{Label: "temp Menu 2", Action: ""},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
return gin.H{
|
return gin.H{
|
||||||
"Islands": islands,
|
"Islands": islands,
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@ package imgviewer
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
websiteapp "personalwebsite/apps"
|
websiteapp "personalwebsite/apps"
|
||||||
"personalwebsite/libs"
|
|
||||||
"personalwebsite/webfilesystem"
|
"personalwebsite/webfilesystem"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
@ -54,17 +53,25 @@ func (p *ImgViewerApp) GetId() string {
|
|||||||
return p.manifest.AppId
|
return p.manifest.AppId
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *ImgViewerApp) Render(path string, isMobile bool) (gin.H, error) {
|
func (p *ImgViewerApp) Render(filePath string, isMobile bool) (gin.H, error) {
|
||||||
img, err := p.fs.NewRead(path)
|
// file, err := p.fs.NewRead(filePath)
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
return nil, err
|
// return nil, err
|
||||||
}
|
// }
|
||||||
data, err := libs.ReadImage(img)
|
// println(file.Data.(primitive.Binary).Data)
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
// img, err := p.fs.NewRead(path)
|
||||||
}
|
// if err != nil {
|
||||||
|
// return nil, err
|
||||||
|
// }
|
||||||
|
// data, err := libs.ReadImage(img)
|
||||||
|
// if err != nil {
|
||||||
|
// return nil, err
|
||||||
|
// }
|
||||||
|
// url := location.Get(ctx)
|
||||||
return gin.H{
|
return gin.H{
|
||||||
"header": data.Header,
|
"imgUrl": "/system/libs/img/get?path=" + filePath,
|
||||||
|
// "header": data.Header,
|
||||||
// "base64": data.Base64,
|
// "base64": data.Base64,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
@ -160,7 +160,8 @@ class Finder{
|
|||||||
// //TODO get real id
|
// //TODO get real id
|
||||||
// WebDesktopEnvironment.Open("personal-properties", [])
|
// WebDesktopEnvironment.Open("personal-properties", [])
|
||||||
// break;
|
// break;
|
||||||
case "base64img":
|
case "jpeg":
|
||||||
|
case "png":
|
||||||
WebDesktopEnvironment.Open("img-viewer", [this.path + "/" + fileName])
|
WebDesktopEnvironment.Open("img-viewer", [this.path + "/" + fileName])
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -204,6 +205,7 @@ class Finder{
|
|||||||
overlay.addEventListener('click',(event) => {
|
overlay.addEventListener('click',(event) => {
|
||||||
if (event.target.classList.contains("Row")){ //TODO add uuid id to rows to more accurate checks??
|
if (event.target.classList.contains("Row")){ //TODO add uuid id to rows to more accurate checks??
|
||||||
let fileType = target.getAttribute("fileType")
|
let fileType = target.getAttribute("fileType")
|
||||||
|
let fileName = target.getAttribute("name")
|
||||||
switch (event.target.children[0].getAttribute("action")) {
|
switch (event.target.children[0].getAttribute("action")) {
|
||||||
case "createDir":
|
case "createDir":
|
||||||
fetch(`/fs/createDir?` + new URLSearchParams({
|
fetch(`/fs/createDir?` + new URLSearchParams({
|
||||||
@ -211,13 +213,15 @@ class Finder{
|
|||||||
}))
|
}))
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
console.log(response.status)
|
console.log(response.status)
|
||||||
|
if (response.status == 200){
|
||||||
|
this.OpenDir(this.path)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
WebDesktopEnvironment.Alert(error);
|
WebDesktopEnvironment.Alert(error);
|
||||||
})
|
})
|
||||||
break
|
break
|
||||||
case "deleteFile":
|
case "deleteFile":
|
||||||
let fileName = target.getAttribute("name")
|
|
||||||
console.log(fileName)
|
console.log(fileName)
|
||||||
// break
|
// break
|
||||||
fetch(`/fs/delete?` + new URLSearchParams({
|
fetch(`/fs/delete?` + new URLSearchParams({
|
||||||
@ -225,11 +229,17 @@ class Finder{
|
|||||||
}))
|
}))
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
console.log(response.status)
|
console.log(response.status)
|
||||||
|
if (response.status == 200){
|
||||||
|
this.OpenDir(this.path)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
WebDesktopEnvironment.Alert(error);
|
WebDesktopEnvironment.Alert(error);
|
||||||
})
|
})
|
||||||
break
|
break
|
||||||
|
case "getInfo":
|
||||||
|
// console.log("Open Properties")
|
||||||
|
WebDesktopEnvironment.Open("props-viewer", `${this.path}/${fileName}`)
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -193,7 +193,7 @@ class WebDesktopEnvironment{
|
|||||||
* @param {string} alertText
|
* @param {string} alertText
|
||||||
*/
|
*/
|
||||||
static CreateAlertWindow(alertText){
|
static CreateAlertWindow(alertText){
|
||||||
console.log("alertWinfdo")
|
// console.log("alertWinfdo")
|
||||||
let newWindow = document.createElement("div")
|
let newWindow = document.createElement("div")
|
||||||
newWindow.setAttribute("class", "WindowFrameless")
|
newWindow.setAttribute("class", "WindowFrameless")
|
||||||
newWindow.setAttribute("windowId", "SuperUniqUUID") //TODO:
|
newWindow.setAttribute("windowId", "SuperUniqUUID") //TODO:
|
||||||
|
@ -21,7 +21,7 @@ func Route(route *gin.RouterGroup, wde *wde.WDE) {
|
|||||||
{
|
{
|
||||||
widgets.GET("/file-tile-view", func(ctx *gin.Context) {
|
widgets.GET("/file-tile-view", func(ctx *gin.Context) {
|
||||||
url := location.Get(ctx)
|
url := location.Get(ctx)
|
||||||
_ = url
|
// _ = url
|
||||||
path := ctx.Query("path")
|
path := ctx.Query("path")
|
||||||
if path == "" {
|
if path == "" {
|
||||||
ctx.JSON(http.StatusBadRequest, "TODO") //TODO json error struct
|
ctx.JSON(http.StatusBadRequest, "TODO") //TODO json error struct
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
Toolbar
|
Toolbar
|
||||||
</div> -->
|
</div> -->
|
||||||
|
|
||||||
<img class="Img-Viewer-Picture-Container"src="data:{{.header}},{{.base64}}">
|
<img class="Img-Viewer-Picture-Container"src="{{.imgUrl}}">
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
Loading…
Reference in New Issue
Block a user