base64 images
This commit is contained in:
parent
0a8e438d4d
commit
5f07c9a52c
16
main.go
16
main.go
@ -66,7 +66,7 @@ func main() {
|
|||||||
persPropsApp := personalprops.NewPersPropsApp()
|
persPropsApp := personalprops.NewPersPropsApp()
|
||||||
// finderApp := finder.FinderApplication{}
|
// finderApp := finder.FinderApplication{}
|
||||||
finderApp := finder.NewFinderApplication(webfs)
|
finderApp := finder.NewFinderApplication(webfs)
|
||||||
imgViewerApp := imgviewer.NewImgViewerApp()
|
imgViewerApp := imgviewer.NewImgViewerApp(webfs)
|
||||||
blogViewerApp := blogviewer.NewBlogViewerApp(webfs)
|
blogViewerApp := blogviewer.NewBlogViewerApp(webfs)
|
||||||
appsStorage := websiteapp.ApplicationsStorage{
|
appsStorage := websiteapp.ApplicationsStorage{
|
||||||
Apps: map[string]websiteapp.WebDEApplication{},
|
Apps: map[string]websiteapp.WebDEApplication{},
|
||||||
@ -214,10 +214,20 @@ func main() {
|
|||||||
imgViewerRoute.GET("render", func(ctx *gin.Context) {
|
imgViewerRoute.GET("render", func(ctx *gin.Context) {
|
||||||
isMobileParam := ctx.Query("isMobile")
|
isMobileParam := ctx.Query("isMobile")
|
||||||
isMobile := isMobileParam == "true"
|
isMobile := isMobileParam == "true"
|
||||||
|
path := ctx.Query("path")
|
||||||
|
if path == "" {
|
||||||
|
ctx.JSON(http.StatusBadRequest, "no path provided")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ginH, err := imgViewerApp.Render(path, isMobile)
|
||||||
|
if err != nil {
|
||||||
|
ctx.JSON(http.StatusInternalServerError, "TODO")
|
||||||
|
return
|
||||||
|
}
|
||||||
if isMobile {
|
if isMobile {
|
||||||
ctx.HTML(http.StatusOK, "img-viewer/mobile-app.tmpl", imgViewerApp.Render(isMobile))
|
ctx.HTML(http.StatusOK, "img-viewer/mobile-app.tmpl", ginH)
|
||||||
} else {
|
} else {
|
||||||
ctx.HTML(http.StatusOK, "img-viewer/app.tmpl", imgViewerApp.Render(isMobile))
|
ctx.HTML(http.StatusOK, "img-viewer/app.tmpl", ginH)
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
|
@ -89,9 +89,9 @@ class Finder{
|
|||||||
// //TODO get real id
|
// //TODO get real id
|
||||||
// WebDesktopEnvironment.Open("personal-properties", [])
|
// WebDesktopEnvironment.Open("personal-properties", [])
|
||||||
// break;
|
// break;
|
||||||
// case "img":
|
case "base64img":
|
||||||
// WebDesktopEnvironment.Open("img-viewer", ["pizda"])
|
WebDesktopEnvironment.Open("img-viewer", [this.path + "/" + fileName])
|
||||||
// break;
|
break;
|
||||||
default:
|
default:
|
||||||
console.log("Unsupported file type")
|
console.log("Unsupported file type")
|
||||||
break;
|
break;
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
class ImgViewer{
|
class ImgViewer{
|
||||||
appId = "img-viewer"
|
appId = "img-viewer"
|
||||||
/**
|
/**
|
||||||
* @param {string} path
|
* @param {string[]} args
|
||||||
*/
|
*/
|
||||||
NewWindow(path){
|
NewWindow(args){
|
||||||
fetch(`${window.location.origin}/application/${this.appId}/render?`+ new URLSearchParams({
|
fetch(`${window.location.origin}/application/${this.appId}/render?`+ new URLSearchParams({
|
||||||
isMobile: WebDesktopEnvironment.isMobile,
|
isMobile: WebDesktopEnvironment.isMobile,
|
||||||
|
path: args[0]
|
||||||
}))
|
}))
|
||||||
.then((response) => response.text())
|
.then((response) => response.text())
|
||||||
.then((html) => {
|
.then((html) => {
|
||||||
@ -24,7 +25,3 @@ class ImgViewer{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class test{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
{{ define "img-viewer/app.tmpl" }}
|
{{ define "img-viewer/app.tmpl" }}
|
||||||
<div id="TestWindowHeader" class="WindowFrameTopBar">
|
<div id="TestWindowHeader" class="WindowFrameTopBar DragArea">
|
||||||
<button id="closeWindowButton" class="WindowFrameTopBarButton" title="Close Window"></button>
|
<button id="closeWindowButton" class="WindowFrameTopBarButton" title="Close Window"></button>
|
||||||
<div id="Drag" class="WindowDragArea"></div>
|
<div id="Drag" class="WindowDragArea"></div>
|
||||||
<div class="WindowFrameTitle">
|
<div class="WindowFrameTitle">
|
||||||
@ -12,7 +12,7 @@
|
|||||||
Toolbar
|
Toolbar
|
||||||
</div> -->
|
</div> -->
|
||||||
<div class="Img-Viewer-Picture-Container">
|
<div class="Img-Viewer-Picture-Container">
|
||||||
<div class="Img-Viewer-Picture">
|
<img src="data:image/jpeg;base64,{{.base64}}">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
@ -1,17 +1,22 @@
|
|||||||
package imgviewer
|
package imgviewer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
|
"personalwebsite/webfilesystem"
|
||||||
"personalwebsite/websiteapp"
|
"personalwebsite/websiteapp"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ImgViewerApp struct {
|
type ImgViewerApp struct {
|
||||||
|
fs *webfilesystem.WebFileSystem
|
||||||
manifest websiteapp.ApplicationManifest
|
manifest websiteapp.ApplicationManifest
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewImgViewerApp() ImgViewerApp {
|
func NewImgViewerApp(webFs *webfilesystem.WebFileSystem) ImgViewerApp {
|
||||||
newApp := ImgViewerApp{
|
newApp := ImgViewerApp{
|
||||||
|
fs: webFs,
|
||||||
manifest: websiteapp.ApplicationManifest{
|
manifest: websiteapp.ApplicationManifest{
|
||||||
AppId: "img-viewer",
|
AppId: "img-viewer",
|
||||||
WindowName: "About me", //TODO: delete
|
WindowName: "About me", //TODO: delete
|
||||||
@ -27,9 +32,21 @@ func (p *ImgViewerApp) GetId() string {
|
|||||||
return p.manifest.AppId
|
return p.manifest.AppId
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *ImgViewerApp) Render(isMobile bool) gin.H {
|
func (p *ImgViewerApp) Render(path string, isMobile bool) (gin.H, error) {
|
||||||
return gin.H{
|
img, err := p.fs.Read(path)
|
||||||
"Name": "Greg Brzezinski",
|
if err != nil {
|
||||||
"BasicBio": "Born 27.09.1998 at Saint-Petersburg",
|
return nil, err
|
||||||
}
|
}
|
||||||
|
header, ok := img.Data.(primitive.D).Map()["header"]
|
||||||
|
if !ok {
|
||||||
|
return nil, errors.New("error in file decoding")
|
||||||
|
}
|
||||||
|
base64, ok := img.Data.(primitive.D).Map()["base64"]
|
||||||
|
if !ok {
|
||||||
|
return nil, errors.New("error in file decoding")
|
||||||
|
}
|
||||||
|
return gin.H{
|
||||||
|
"header": header,
|
||||||
|
"base64": base64,
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user