Relatives patches, appContext in backend and temp favicon

This commit is contained in:
cyber-dream 2023-05-18 01:45:39 +03:00
parent 9cc2dc5a42
commit 5d160bddd9
10 changed files with 49 additions and 15 deletions

View File

@ -0,0 +1,7 @@
package appCtx
type AppContext struct {
IsMobile bool `json:"isMobile"`
BundlePath string `json:"bundlePath"`
RunPath string `json:"runPath"`
}

View File

@ -2,6 +2,7 @@ package personalprops
import (
"net/http"
"personalwebsite/apps/appCtx"
"personalwebsite/webfilesystem"
"github.com/gin-gonic/gin"
@ -23,20 +24,25 @@ func NewPersPropsApp(webFs *webfilesystem.WebFileSystem) *PersonalPropertiesApp
}
func (p *PersonalPropertiesApp) PublicRoutes(route *gin.RouterGroup) {
route.GET("render", func(ctx *gin.Context) {
isMobileParam := ctx.Query("isMobile")
isMobile := isMobileParam == "true"
route.POST("render", func(ctx *gin.Context) {
filePath := ctx.Query("path")
if filePath == "" {
ctx.Status(http.StatusBadRequest)
return
}
ginH, err := p.Render(filePath)
appCtx := appCtx.AppContext{}
err := ctx.BindJSON(&appCtx)
if err != nil {
ctx.Status(http.StatusBadRequest)
return
}
ginH, err := p.Render(appCtx, filePath)
if err != nil {
ctx.JSON(http.StatusInternalServerError, "TODO") //TODO
return
}
if isMobile {
if appCtx.IsMobile {
ctx.HTML(http.StatusOK, "personal-properties/mobile-app.tmpl", ginH)
} else {
ctx.HTML(http.StatusOK, "personal-properties/app.tmpl", ginH)
@ -101,13 +107,14 @@ func (p *PersonalPropertiesApp) WriteMock() error {
return err
}
func (p *PersonalPropertiesApp) Render(filePath string) (gin.H, error) {
func (p *PersonalPropertiesApp) Render(appCtx appCtx.AppContext, filePath string) (gin.H, error) {
propsData := PropertiesFileData{}
filePath = p.fs.RelativeToAbsolute(appCtx, filePath)
_, err := p.fs.Read(filePath, &propsData)
if err != nil {
return nil, err
}
propsData.Header.IconPath = p.fs.RelativeToAbsolute(appCtx, propsData.Header.IconPath)
return gin.H{
"headerProps": propsData.Header,
"allprops": propsData.Props,

1
go.mod
View File

@ -40,6 +40,7 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
github.com/thinkerou/favicon v0.2.0
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.9 // indirect
go.mongodb.org/mongo-driver v1.11.4

2
go.sum
View File

@ -98,6 +98,8 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/thinkerou/favicon v0.2.0 h1:/qO//fFevzhx68pAAPjuiOwB2ykoKwLcZW9luMZ8PEU=
github.com/thinkerou/favicon v0.2.0/go.mod h1:PM31DMRkXDVi9/sGwb/a/evMB536N9VfVNC+Dtf4iDQ=
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=

View File

@ -12,13 +12,13 @@ class AboutMe{
* @param {Object} runContext
*/
async NewWindow(args, runContext){
console.log(runContext)
const params = new URLSearchParams({
isMobile: WebDesktopEnvironment.isMobile,
path: `${runContext.bundlePath}/aboutme.props`,
runContext: runContext,
path: `:/aboutme.props`,
})
const response = await fetch(`/app/${AboutMe.appID}/render?`+ params,{
method: "POST",
body: JSON.stringify(runContext)
})
const response = await fetch(`/app/${AboutMe.appID}/render?`+ params)
if (response.status != 200){
WebDesktopEnvironment.Alert("Error TODO") //TODO
return

View File

@ -41,7 +41,6 @@ class FinderWindow{
windowElem = undefined
async Init(args){
console.log(args)
if (args[1] === "-desktop"){
//todo pass div id, not div in args[]
const params = new URLSearchParams({

View File

@ -49,6 +49,7 @@ class WebDesktopEnvironment{
if (appManifest === undefined) return //TODO return err
const runContext = {
isMobile: false,
bundlePath: appPath,
runPath: "todo" //TODO
}
@ -76,8 +77,7 @@ class WebDesktopEnvironment{
script.setAttribute("src", appManifest.js[0]) //FIXME path by fs read
script.setAttribute("async", "false") //TODO Possible may creates a problems??
appElem.appendChild(script)
console.log(appElem)
document.getElementById("applications").appendChild(appElem)
script.addEventListener('load', (event) => {
let newApp = eval(`new ${appManifest.appId}()`);

View File

@ -15,11 +15,13 @@ import (
"github.com/gin-contrib/cors"
"github.com/gin-contrib/location"
"github.com/gin-gonic/gin"
"github.com/thinkerou/favicon"
)
func PrivateRoutes(webfs *webfilesystem.WebFileSystem, webde *wde.WDE, appsStorage *apps.ApplicationsStorage) {
router := gin.New()
router.Use(location.Default())
router.Use(favicon.New("./resources/sys/wde/icons/ohno.png")) // set favicon middleware
router.LoadHTMLGlob("templates/**/*")
router.Static("/res", "resources")
// Set a lower memory limit for multipart forms (default is 32 MiB)

View File

@ -12,12 +12,14 @@ import (
"github.com/gin-contrib/location"
"github.com/gin-gonic/gin"
"github.com/thinkerou/favicon"
)
func PublicRoutes(webfs *webfilesystem.WebFileSystem, webde *wde.WDE, appsStorage *apps.ApplicationsStorage) {
router := gin.New()
router.Use(location.Default())
router.LoadHTMLGlob("templates/**/*")
router.Use(favicon.New("./resources/sys/wde/icons/ohno.png")) // set favicon middleware
router.Static("/res", "resources")
router.GET("/", func(ctx *gin.Context) {

View File

@ -3,6 +3,8 @@ package webfilesystem
import (
"context"
"errors"
"path"
"personalwebsite/apps/appCtx"
"strings"
"go.mongodb.org/mongo-driver/bson"
@ -361,3 +363,15 @@ func (fs *WebFileSystem) CheckFileExist(filePath string) bool {
}
return false
}
func (fs *WebFileSystem) RelativeToAbsolute(appCtx appCtx.AppContext, filePath string) string {
switch filePath[0] {
case '.':
return path.Join(appCtx.RunPath, filePath)
case ':':
filePath = strings.ReplaceAll(filePath, ":", "")
return path.Join(appCtx.BundlePath, filePath)
default:
return filePath
}
}