Create public and private modes for website

This commit is contained in:
cyber-dream 2023-05-16 13:51:28 +03:00
parent d2ea95a182
commit 6a93f418d5
17 changed files with 509 additions and 227 deletions

View File

@ -2,7 +2,6 @@ package blogviewer
import (
"net/http"
"personalwebsite/apps"
"personalwebsite/webfilesystem"
"github.com/gin-gonic/gin"
@ -10,28 +9,24 @@ import (
)
type BlogViewerApplication struct {
fs *webfilesystem.WebFileSystem
manifest apps.ApplicationManifest
fs *webfilesystem.WebFileSystem
appID string
}
func NewBlogViewerApp(webFs *webfilesystem.WebFileSystem) *BlogViewerApplication {
return &BlogViewerApplication{
fs: webFs,
manifest: apps.ApplicationManifest{
AppId: "blog-viewer",
},
fs: webFs,
appID: "BlogViewer",
}
}
func (b *BlogViewerApplication) GetManifest() apps.ApplicationManifest {
return b.manifest
func (b *BlogViewerApplication) GetAppID() string {
return b.appID
}
func (b *BlogViewerApplication) GetId() string {
return b.manifest.AppId
func (b *BlogViewerApplication) PrivateRoutes(route *gin.RouterGroup) {
b.PublicRoutes(route)
}
func (b *BlogViewerApplication) Route(route *gin.RouterGroup) {
func (b *BlogViewerApplication) PublicRoutes(route *gin.RouterGroup) {
route.GET("writeMockBlog", func(ctx *gin.Context) {
path := ctx.Query("path")
if path == "" {

View File

@ -10,12 +10,14 @@ import (
type FinderApplication struct {
fs *webfilesystem.WebFileSystem
appID string
manifest apps.ApplicationManifest
}
func NewFinderApplication(webFs *webfilesystem.WebFileSystem) *FinderApplication {
return &FinderApplication{
fs: webFs,
fs: webFs,
appID: "Finder",
manifest: apps.ApplicationManifest{
AppId: "finder",
},
@ -24,15 +26,15 @@ func NewFinderApplication(webFs *webfilesystem.WebFileSystem) *FinderApplication
func (f *FinderApplication) GetManifest() apps.ApplicationManifest {
return f.manifest
}
func (f *FinderApplication) GetId() string {
return f.manifest.AppId
func (f *FinderApplication) GetAppID() string {
return f.appID
}
func (f *FinderApplication) Render(isMobile bool) gin.H {
return gin.H{}
}
func (f *FinderApplication) RenderContextMenu(context string, filePath string, data string) gin.H {
func (f *FinderApplication) RenderPrivateContextMenu(context string, filePath string, data string) gin.H {
islands := [][]wde.ContexMenuRow{}
islands = append(islands, []wde.ContexMenuRow{})
@ -68,6 +70,27 @@ func (f *FinderApplication) RenderContextMenu(context string, filePath string, d
"Islands": islands,
}
}
func (f *FinderApplication) RenderPublicContextMenu(context string, filePath string, data string) gin.H {
islands := [][]wde.ContexMenuRow{}
islands = append(islands, []wde.ContexMenuRow{})
islands = append(islands, []wde.ContexMenuRow{
{Label: "Get Info", Action: "getInfo"},
})
if context == "FileTileView" {
return gin.H{
"Islands": islands,
}
}
switch context {
default:
}
return gin.H{
"Islands": islands,
}
}
func (f *FinderApplication) RenderProps(filePath string) (gin.H, error) {
// file, err := f.fs.NewReadDeprecated(filePath)

View File

@ -6,19 +6,9 @@ import (
"github.com/gin-gonic/gin"
)
func (f *FinderApplication) Routes(routes *gin.RouterGroup) {
func (f *FinderApplication) PublicRoutes(routes *gin.RouterGroup) {
routes.GET("render", func(ctx *gin.Context) {
isMobileParam := ctx.Query("isMobile")
isMobile := isMobileParam == "true"
admin := true
if isMobile {
ctx.HTML(http.StatusOK, "finder/mobile-app.tmpl", f.Render(isMobile))
return
}
if admin {
ctx.HTML(http.StatusOK, "finder/admin-app.tmpl", f.Render(isMobile))
return
}
isMobile := ctx.Query("isMobile") == "true"
ctx.HTML(http.StatusOK, "finder/app.tmpl", f.Render(isMobile))
})
@ -46,7 +36,49 @@ func (f *FinderApplication) Routes(routes *gin.RouterGroup) {
return
}
data := ctx.Query("data")
ginH := f.RenderContextMenu(context, filePath, data)
// ginH := f.RenderPrivateContextMenu(context, filePath, data)
ginH := f.RenderPublicContextMenu(context, filePath, data)
ctx.HTML(http.StatusOK, "wde-widgets/context-menu.tmpl", ginH)
})
routes.GET("renderProps", func(ctx *gin.Context) {
filePath := ctx.Query("path")
ginH, err := f.RenderProps(filePath)
if err != nil {
ctx.Status(http.StatusInternalServerError)
return
}
ctx.HTML(http.StatusOK, "finder/props.tmpl", ginH)
})
}
func (f *FinderApplication) PrivateRoutes(routes *gin.RouterGroup) {
routes.GET("render", func(ctx *gin.Context) {
isMobile := ctx.Query("isMobile") == "true"
ctx.HTML(http.StatusOK, "finder/admin-app.tmpl", f.Render(isMobile))
})
routes.GET("renderMobileDesktop", func(ctx *gin.Context) {
ctx.HTML(http.StatusOK, "finder/mobile-desktop.tmpl", gin.H{})
})
routes.GET("renderDesktop", func(ctx *gin.Context) {
path := ctx.Query("path")
if path == "" {
ctx.JSON(http.StatusBadRequest, "no path provided")
return
}
ctx.HTML(http.StatusOK, "finder/desktop.tmpl", gin.H{})
})
routes.GET("contextMenu", func(ctx *gin.Context) {
context := ctx.Query("context")
filePath := ctx.Query("path")
if filePath == "" {
ctx.Status(http.StatusBadRequest)
return
}
data := ctx.Query("data")
ginH := f.RenderPrivateContextMenu(context, filePath, data)
ctx.HTML(http.StatusOK, "wde-widgets/context-menu.tmpl", ginH)
})

View File

@ -2,28 +2,27 @@ package imgviewer
import (
"net/http"
websiteapp "personalwebsite/apps"
"personalwebsite/webfilesystem"
"github.com/gin-gonic/gin"
)
type ImgViewerApp struct {
fs *webfilesystem.WebFileSystem
manifest websiteapp.ApplicationManifest
fs *webfilesystem.WebFileSystem
appID string
}
func NewImgViewerApp(webFs *webfilesystem.WebFileSystem) ImgViewerApp {
func NewImgViewerApp(webFs *webfilesystem.WebFileSystem) *ImgViewerApp {
newApp := ImgViewerApp{
fs: webFs,
manifest: websiteapp.ApplicationManifest{
AppId: "img-viewer",
},
fs: webFs,
appID: "ImgViewer",
}
return newApp
return &newApp
}
func (p *ImgViewerApp) Route(route *gin.RouterGroup) {
func (p *ImgViewerApp) PrivateRoutes(route *gin.RouterGroup) {
p.PublicRoutes(route)
}
func (p *ImgViewerApp) PublicRoutes(route *gin.RouterGroup) {
route.GET("render", func(ctx *gin.Context) {
isMobileParam := ctx.Query("isMobile")
isMobile := isMobileParam == "true"
@ -45,11 +44,8 @@ func (p *ImgViewerApp) Route(route *gin.RouterGroup) {
})
}
func (p *ImgViewerApp) GetManifest() websiteapp.ApplicationManifest {
return p.manifest
}
func (p *ImgViewerApp) GetId() string {
return p.manifest.AppId
func (p *ImgViewerApp) GetAppID() string {
return p.appID
}
func (p *ImgViewerApp) Render(filePath string, isMobile bool) (gin.H, error) {

View File

@ -2,36 +2,27 @@ package personalprops
import (
"net/http"
websiteapp "personalwebsite/apps"
"personalwebsite/webfilesystem"
"github.com/gin-gonic/gin"
"go.mongodb.org/mongo-driver/bson/primitive"
)
//TODO Rename to AboutMe
type PersonalPropertiesApp struct {
fs *webfilesystem.WebFileSystem
manifest websiteapp.ApplicationManifest
fs *webfilesystem.WebFileSystem
appID string
}
func NewPersPropsApp(webFs *webfilesystem.WebFileSystem) PersonalPropertiesApp {
func NewPersPropsApp(webFs *webfilesystem.WebFileSystem) *PersonalPropertiesApp {
newApp := PersonalPropertiesApp{
fs: webFs,
manifest: websiteapp.ApplicationManifest{
AppId: "personal-properties",
},
fs: webFs,
appID: "AboutMe",
}
return newApp
return &newApp
}
func (p *PersonalPropertiesApp) Route(route *gin.RouterGroup) {
route.GET("writeMock", func(ctx *gin.Context) {
err := p.WriteMock()
if err != nil {
ctx.Status(http.StatusInternalServerError)
}
ctx.Status(http.StatusOK)
})
func (p *PersonalPropertiesApp) PublicRoutes(route *gin.RouterGroup) {
route.GET("render", func(ctx *gin.Context) {
isMobileParam := ctx.Query("isMobile")
isMobile := isMobileParam == "true"
@ -53,11 +44,20 @@ func (p *PersonalPropertiesApp) Route(route *gin.RouterGroup) {
})
}
func (p *PersonalPropertiesApp) GetManifest() websiteapp.ApplicationManifest {
return p.manifest
func (p *PersonalPropertiesApp) PrivateRoutes(router *gin.RouterGroup) {
p.PublicRoutes(router)
router.GET("writeMock", func(ctx *gin.Context) {
err := p.WriteMock()
if err != nil {
ctx.Status(http.StatusInternalServerError)
}
ctx.Status(http.StatusOK)
})
}
func (p *PersonalPropertiesApp) GetId() string {
return p.manifest.AppId
func (p *PersonalPropertiesApp) GetAppID() string {
return p.appID
}
func (p *PersonalPropertiesApp) WriteMock() error {

View File

@ -12,9 +12,12 @@ import (
//TODO to libs
type WebDEApplication interface {
// Render()
GetManifest() ApplicationManifest
GetAppID() string
PublicRoutes(*gin.RouterGroup)
PrivateRoutes(*gin.RouterGroup)
// GetManifest() ApplicationManifest //TODO: Delete
// GEtHtml()
GetId() string
// GetId() string
}
type ApplicationManifest struct {
@ -58,12 +61,6 @@ func (as *ApplicationsStorage) createApp(appName string, appId string, appPath s
return nil
}
// func NewApplicationsStorage() *ApplicationsStorage {
// newStorage := ApplicationsStorage{}
// return &newStorage
// }
func (aStorage *ApplicationsStorage) Route(route *gin.RouterGroup) {
route.GET("/get", func(ctx *gin.Context) {
appId := ctx.Query("appid")
@ -71,12 +68,13 @@ func (aStorage *ApplicationsStorage) Route(route *gin.RouterGroup) {
ctx.Status(http.StatusBadRequest)
return
}
app, isExist := aStorage.Apps[appId]
if !isExist {
ctx.Status(http.StatusNoContent)
return
}
ctx.JSON(http.StatusOK, app.GetManifest())
// app, isExist := aStorage.Apps[appId]
// if !isExist {
// ctx.Status(http.StatusNoContent)
// return
// }
// ctx.JSON(http.StatusOK, app.GetManifest())
ctx.String(http.StatusMovedPermanently, "Obsolete")
})
route.GET("/loadApp", func(ctx *gin.Context) {

View File

@ -38,7 +38,7 @@ func (c *Cat) Get(filePath string) (string, error) {
return fileData.Data, nil
}
func (c *Cat) Route(route *gin.RouterGroup) {
func (c *Cat) PublicRoutes(route *gin.RouterGroup) {
route.GET("get", func(ctx *gin.Context) {
path := ctx.Query("path")
if path == "" {
@ -52,7 +52,13 @@ func (c *Cat) Route(route *gin.RouterGroup) {
return
}
ctx.String(http.StatusOK, "plaintext", data)
})
mode := ctx.Query("mode")
switch mode {
case "json":
ctx.JSON(http.StatusOK, data)
default:
ctx.String(http.StatusOK, "plaintext", data)
}
})
}

View File

@ -17,7 +17,7 @@ func NewImgLib(webfs *webfilesystem.WebFileSystem) *ImagLib {
}
}
func (l *ImagLib) Route(route *gin.RouterGroup) {
func (l *ImagLib) PublicRoutes(route *gin.RouterGroup) {
route.GET("get", func(ctx *gin.Context) {
path := ctx.Query("path")
if path == "" {
@ -31,10 +31,6 @@ func (l *ImagLib) Route(route *gin.RouterGroup) {
ctx.Status(http.StatusInternalServerError)
return
}
// _, err = l.fs.readFSDocs(fileId, &imgData)
// if err != nil {
// ctx.Status(http.StatusInternalServerError)
// }
ctx.Data(http.StatusOK, "image/jpeg", imgData.Bin)
})

213
main.go
View File

@ -4,23 +4,17 @@ import (
"context"
"errors"
"log"
"net/http"
"os"
"time"
"personalwebsite/apps"
"personalwebsite/apps/blogviewer"
"personalwebsite/apps/finder"
imgviewer "personalwebsite/apps/img-viewer"
"personalwebsite/apps/personalprops"
"personalwebsite/libs"
"personalwebsite/routewde"
"personalwebsite/routes"
"personalwebsite/wde"
"personalwebsite/webfilesystem"
"github.com/gin-contrib/cors"
"github.com/gin-contrib/location"
"github.com/gin-gonic/gin"
"github.com/joho/godotenv"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
@ -56,122 +50,127 @@ func main() {
log.Fatal(err)
}
router := gin.New()
router.Use(location.Default())
router.LoadHTMLGlob("templates/**/*")
router.Static("/res", "resources")
// Set a lower memory limit for multipart forms (default is 32 MiB)
router.MaxMultipartMemory = 8 << 20 // 8 MiB
router.GET("/", func(ctx *gin.Context) {
ctx.HTML(http.StatusOK, "index.tmpl", gin.H{})
})
webfs := webfilesystem.NewWebFileSystem(client, dBName, webFsCollection)
appsStorage := apps.NewApplicationsStorage(map[string]apps.WebDEApplication{}, webfs)
// router := gin.New()
// router.Use(location.Default())
// router.LoadHTMLGlob("templates/**/*")
// router.Static("/res", "resources")
// // Set a lower memory limit for multipart forms (default is 32 MiB)
// router.MaxMultipartMemory = 8 << 20 // 8 MiB
// router.GET("/", func(ctx *gin.Context) {
// ctx.HTML(http.StatusOK, "index.tmpl", gin.H{})
// })
webde := wde.NewWDE(webfs)
persPropsApp := personalprops.NewPersPropsApp(webfs)
// finderApp := finder.FinderApplication{}
finderApp := finder.NewFinderApplication(webfs)
imgViewerApp := imgviewer.NewImgViewerApp(webfs)
blogViewerApp := blogviewer.NewBlogViewerApp(webfs)
appsStorage := apps.NewApplicationsStorage(map[string]apps.WebDEApplication{}, webfs)
appsStorage.Apps["personal-properties"] = &persPropsApp
appsStorage.Apps["personal-properties"] = persPropsApp
appsStorage.Apps["finder"] = finderApp
appsStorage.Apps["img-viewer"] = &imgViewerApp
appsStorage.Apps["img-viewer"] = imgViewerApp
appsStorage.Apps["blog-viewer"] = blogViewerApp
system := router.Group("system")
{
libsGroup := system.Group("libs")
{
imgLibGroup := libsGroup.Group("img")
{
imgLib := libs.NewImgLib(webfs)
imgLib.Route(imgLibGroup)
}
go routes.PublicRoutes(webfs, webde, appsStorage)
routes.PrivateRoutes(webfs, webde, appsStorage)
catLibGroup := libsGroup.Group("cat")
{
catLib := libs.NewCatLib(webfs)
catLib.Route(catLibGroup)
}
// system := router.Group("system")
// {
// libsGroup := system.Group("libs")
// {
// imgLibGroup := libsGroup.Group("img")
// {
// imgLib := libs.NewImgLib(webfs)
// imgLib.PublicRoutes(imgLibGroup)
// }
appsStorageGroup := libsGroup.Group("apps")
{
appsStorage.Route(appsStorageGroup)
}
}
// catLibGroup := libsGroup.Group("cat")
// {
// catLib := libs.NewCatLib(webfs)
// catLib.PublicRoutes(catLibGroup)
// }
wdeGroup := system.Group("wde")
{
routewde.Route(wdeGroup, webde)
}
apps := system.Group("applications") //TODO to libs
{
apps.GET("/:appid/:method", func(ctx *gin.Context) {
appId := ctx.Param("appid")
method := ctx.Param("method")
// appsStorageGroup := libsGroup.Group("apps")
// {
// appsStorage.Route(appsStorageGroup)
// }
// }
app, isExist := appsStorage.Apps[appId]
if !isExist {
ctx.Status(http.StatusNoContent)
return
}
switch method {
case "getmanifest":
ctx.JSON(http.StatusOK, app.GetManifest())
case "app.js":
ctx.File("resources/sys/" + appId + "/" + appId + ".js")
case "app.css":
ctx.File("resources/sys/" + appId + "/" + appId + ".css")
default:
ctx.Status(http.StatusBadRequest)
}
})
}
}
// wdeGroup := system.Group("wde")
// {
// routewde.PublicRoutes(wdeGroup, webde)
// }
// apps := system.Group("applications") //TODO to libs
// {
// apps.GET("/:appid/:method", func(ctx *gin.Context) {
// appId := ctx.Param("appid")
// method := ctx.Param("method")
fs := router.Group("fs")
{
webfs.Route(fs)
}
app := router.Group("app")
{
persPropApp := app.Group("AboutMe")
{
persPropsApp.Route(persPropApp)
}
finderAppRoute := app.Group("Finder")
{
finderApp.Routes(finderAppRoute)
}
imgViewerRoute := app.Group("img-viewer")
{
imgViewerApp.Route(imgViewerRoute)
}
blogViewerRoute := app.Group("blog-viewer")
{
blogViewerApp.Route(blogViewerRoute)
}
// app, isExist := appsStorage.Apps[appId]
// if !isExist {
// ctx.Status(http.StatusNoContent)
// return
// }
// switch method {
// case "getmanifest":
// ctx.JSON(http.StatusOK, app.GetManifest())
// case "app.js":
// ctx.File("resources/sys/" + appId + "/" + appId + ".js")
// case "app.css":
// ctx.File("resources/sys/" + appId + "/" + appId + ".css")
// default:
// ctx.Status(http.StatusBadRequest)
// }
// })
// }
// }
router.Use(cors.New(cors.Config{
AllowAllOrigins: true,
// AllowOrigins: []string{"http://localhost:8080", "http://localhost:9090"},
// AllowMethods: []string{"PUT", "PATCH"},
// AllowHeaders: []string{"Origin"},
ExposeHeaders: []string{"Content-Length"},
AllowCredentials: true,
// AllowOriginFunc: func(origin string) bool {
// return origin == "https://github.com"
// },
MaxAge: 12 * time.Hour,
}))
err = router.Run(":8080")
if err != nil {
log.Panicf("error: %s", err)
}
}
// fs := router.Group("fs")
// {
// fsGroup := systemGroup.Group("fs")
// {
// webfs.PublicRoutes(fsGroup)
// }
// }
// app := router.Group("app")
// {
// persPropApp := app.Group("AboutMe")
// {
// persPropsApp.Route(persPropApp)
// }
// finderAppRoute := app.Group("Finder")
// {
// finderApp.Routes(finderAppRoute)
// }
// imgViewerRoute := app.Group("img-viewer")
// {
// imgViewerApp.Route(imgViewerRoute)
// }
// blogViewerRoute := app.Group("blog-viewer")
// {
// blogViewerApp.Route(blogViewerRoute)
// }
// router.Use(cors.New(cors.Config{
// AllowAllOrigins: true,
// // AllowOrigins: []string{"http://localhost:8080", "http://localhost:9090"},
// // AllowMethods: []string{"PUT", "PATCH"},
// // AllowHeaders: []string{"Origin"},
// ExposeHeaders: []string{"Content-Length"},
// AllowCredentials: true,
// // AllowOriginFunc: func(origin string) bool {
// // return origin == "https://github.com"
// // },
// MaxAge: 12 * time.Hour,
// }))
// err = router.Run(":8080")
// if err != nil {
// log.Panicf("error: %s", err)
// }
// }
}
// func index(c *gin.Context) {

View File

@ -14,21 +14,24 @@ class Finder{
* @returns {boolean}
*/
static async RenderProperites(path){
if (path == null || path ==""){
return
}
const params = new URLSearchParams({
path: path
})
const response = await fetch(`/application/${Finder.AppId}/renderProps?` + params)
const response = await fetch(`/app/${Finder.AppId}/renderProps?` + params)
if (response.status != 200){
WebDesktopEnvironment.Alert("Error in properties render") //TODO
return false
}
const html = response.text()
const html = await response.text()
let newWindow = WebDesktopEnvironment.CreateNewWindow(Finder.AppId, 350, 500 )
newWindow.innerHTML = html
newWindow.querySelector("#closeWindowButton").addEventListener('click', function (params) {
WebDesktopEnvironment.CloseWindow(newWindow)
})
}
}
}
@ -96,7 +99,6 @@ class FinderWindow{
let scrollBar = new WdeScrollBar(newWindow.querySelector(".ScrollbarPlace"), newWindow.querySelector(".FileTileView"))
this.windowElem = newWindow
this.RenderDir(args[0])
}
@ -199,7 +201,7 @@ class FinderWindow{
*/
async CreateContextMenu(target, pos){
let context = ""
const fileName = target.getAttribute("name")
const fileName = target.getAttribute("name") //TODO check for null
const fileType = target.getAttribute("fileType")
if (target.classList.contains("FileTileView"))
{
@ -207,7 +209,14 @@ class FinderWindow{
} else {
context = fileType
}
const params = new URLSearchParams({context: context, path: `${this.curPath}/${fileName}`})
let path = ""
if (fileName === null){
console.log(fileName)
path = this.curPath
} else {
path = `${this.curPath}/${fileName}`
}
const params = new URLSearchParams({context: context, path: path})
const response = await fetch(`/app/${Finder.AppId}/contextMenu?` + params)
if (response.status != 200){
WebDesktopEnvironment.Alert("ERROR in Context menu TODO"); //TODO
@ -252,11 +261,11 @@ class FinderWindow{
}
break
case "getInfo":
res = await Finder.RenderProperites(`${this.curPath}/${fileName}`)
Finder.RenderProperites(path)
break
case "openAsDir":
WebDesktopEnvironment.Open(`/Applications/${Finder.AppId}.app`,[`${this.curPath}/${fileName}`])
break
case "openAsDir":
WebDesktopEnvironment.Open(`/Applications/${Finder.AppId}.app`,[`${this.curPath}/${fileName}`])
break
default:
break;
}

View File

@ -82,11 +82,13 @@ class WebDesktopEnvironment{
* @returns {Object | undefined} //FIXME
*/
static async fetchApp(path){
const params = new URLSearchParams({path: path})
const response = await fetch(`/system/libs/apps/loadApp?` + params)
console.log("path: " + path )
const params = new URLSearchParams({path: path, mode: "json"})
const response = await fetch(`/system/loadApp?` + params)
if (response.status != 200){
return undefined
}
//TODO Validate manifest
const appManifest = response.json()
return appManifest
}

119
routes/private.go Normal file
View File

@ -0,0 +1,119 @@
package routes
import (
"log"
"net/http"
"path"
"personalwebsite/apps"
"personalwebsite/libs"
"personalwebsite/routewde"
"personalwebsite/wde"
"personalwebsite/webfilesystem"
"time"
"github.com/gin-contrib/cors"
"github.com/gin-contrib/location"
"github.com/gin-gonic/gin"
)
func PrivateRoutes(webfs *webfilesystem.WebFileSystem, webde *wde.WDE, appsStorage *apps.ApplicationsStorage) {
router := gin.New()
router.Use(location.Default())
router.LoadHTMLGlob("templates/**/*")
router.Static("/res", "resources")
// Set a lower memory limit for multipart forms (default is 32 MiB)
router.MaxMultipartMemory = 8 << 20 // 8 MiB
router.GET("/", func(ctx *gin.Context) {
ctx.HTML(http.StatusOK, "index.tmpl", gin.H{})
})
systemGroup := router.Group("system")
{
libsGroup := systemGroup.Group("libs")
{
imgLibGroup := libsGroup.Group("img")
{
imgLib := libs.NewImgLib(webfs)
imgLib.PublicRoutes(imgLibGroup)
}
catLibGroup := libsGroup.Group("cat")
{
catLib := libs.NewCatLib(webfs)
catLib.PublicRoutes(catLibGroup)
}
appsStorageGroup := libsGroup.Group("apps")
{
appsStorage.Route(appsStorageGroup)
}
}
wdeGroup := systemGroup.Group("wde")
{
routewde.PublicRoutes(wdeGroup, webde)
}
fsGroup := systemGroup.Group("fs")
{
webfs.PrivateRoutes(fsGroup)
}
systemGroup.GET("/loadApp", func(ctx *gin.Context) {
appPath := ctx.Query("path")
if appPath == "" {
ctx.Status(http.StatusBadRequest)
return
}
appBundleData := webfilesystem.DirectoryData{}
appBundle, err := webfs.Read(appPath, &appBundleData)
if err != nil {
ctx.Status(http.StatusInternalServerError)
return
}
if appBundle.Type != "directory" {
ctx.Status(http.StatusBadRequest)
return
}
appManifestData := apps.ApplicationManifest{}
appManifestHeader, err := webfs.Read(path.Join(appPath, ".appmanifest"), &appManifestData)
if err != nil {
ctx.Status(http.StatusInternalServerError)
return
}
if appManifestHeader.Type != "application-manifest" {
ctx.Status(http.StatusBadRequest)
return
}
ctx.JSON(http.StatusOK, appManifestData)
})
}
appsGroup := router.Group("app")
{
for _, app := range appsStorage.Apps {
appsRoutes := appsGroup.Group(app.GetAppID())
app.PrivateRoutes(appsRoutes)
}
}
router.Use(cors.New(cors.Config{
AllowAllOrigins: true,
// AllowOrigins: []string{"http://localhost:8080", "http://localhost:9090"},
// AllowMethods: []string{"PUT", "PATCH"},
// AllowHeaders: []string{"Origin"},
ExposeHeaders: []string{"Content-Length"},
AllowCredentials: true,
// AllowOriginFunc: func(origin string) bool {
// return origin == "https://github.com"
// },
MaxAge: 12 * time.Hour,
}))
err := router.Run(":8080")
if err != nil {
log.Panicf("error: %s", err)
}
}

101
routes/public.go Normal file
View File

@ -0,0 +1,101 @@
package routes
import (
"log"
"net/http"
"path"
"personalwebsite/apps"
"personalwebsite/libs"
"personalwebsite/routewde"
"personalwebsite/wde"
"personalwebsite/webfilesystem"
"github.com/gin-contrib/location"
"github.com/gin-gonic/gin"
)
func PublicRoutes(webfs *webfilesystem.WebFileSystem, webde *wde.WDE, appsStorage *apps.ApplicationsStorage) {
router := gin.New()
router.Use(location.Default())
router.LoadHTMLGlob("templates/**/*")
router.Static("/res", "resources")
router.GET("/", func(ctx *gin.Context) {
ctx.HTML(http.StatusOK, "index.tmpl", gin.H{})
})
systemGroup := router.Group("system")
{
libsGroup := systemGroup.Group("libs")
{
imgLibGroup := libsGroup.Group("img")
{
imgLib := libs.NewImgLib(webfs)
imgLib.PublicRoutes(imgLibGroup)
}
catLibGroup := libsGroup.Group("cat")
{
catLib := libs.NewCatLib(webfs)
catLib.PublicRoutes(catLibGroup)
}
}
wdeGroup := systemGroup.Group("wde")
{
routewde.PublicRoutes(wdeGroup, webde)
}
systemGroup.GET("/loadApp", func(ctx *gin.Context) {
appPath := ctx.Query("path")
if appPath == "" {
ctx.Status(http.StatusBadRequest)
return
}
appBundleData := webfilesystem.DirectoryData{}
appBundle, err := webfs.Read(appPath, &appBundleData)
if err != nil {
ctx.Status(http.StatusInternalServerError)
return
}
if appBundle.Type != "directory" {
ctx.Status(http.StatusBadRequest)
return
}
appManifestData := apps.ApplicationManifest{}
appManifestHeader, err := webfs.Read(path.Join(appPath, ".appmanifest"), &appManifestData)
if err != nil {
ctx.Status(http.StatusInternalServerError)
return
}
if appManifestHeader.Type != "application-manifest" {
ctx.Status(http.StatusBadRequest)
return
}
ctx.JSON(http.StatusOK, appManifestData)
})
// fsGroup := systemGroup.Group("fs")
// {
// webfs.PublicRoutes(fsGroup)
// }
}
appGroup := router.Group("app")
{
for _, app := range appsStorage.Apps {
appRoutes := appGroup.Group(app.GetAppID())
app.PublicRoutes(appRoutes)
}
}
err := router.Run(":7070")
if err != nil {
log.Panicf("error: %s", err)
}
}

View File

@ -8,8 +8,8 @@ import (
"github.com/gin-gonic/gin"
)
func Route(route *gin.RouterGroup, wde *wde.WDE) {
route.GET("/getbasicwindow", func(ctx *gin.Context) {
func PublicRoutes(route *gin.RouterGroup, wde *wde.WDE) {
route.GET("/getbasicwindow", func(ctx *gin.Context) { //TODO Rename to renderGenericWindowFrame
ctx.HTML(http.StatusOK, "basic-window.html", nil)
})
@ -21,7 +21,6 @@ func Route(route *gin.RouterGroup, wde *wde.WDE) {
{
widgets.GET("/file-tile-view", func(ctx *gin.Context) {
url := location.Get(ctx)
// _ = url
path := ctx.Query("path")
if path == "" {
ctx.JSON(http.StatusBadRequest, "TODO") //TODO json error struct

View File

@ -1,24 +1,27 @@
{{ define "finder/app.tmpl" }}
<div class="TitleBar DragArea">
<button id="closeWindowButton" class="Button" title="Close Window"></button>
<div class="TitleBarTest">
<div id="Drag" class="VisualDragArea"></div>
<div class="Lable">
Files
Finder
</div>
<div id="Drag" class="VisualDragArea"></div>
</div>
</div>
<div class="ToolBar">
<button id="BackButton">Back</button>
<button id="HomeButton">Home</button>
</div>
<div class="ContentBorder ConvexElement">
<div class="FileTileView">
<div id="ContentBorder" class="ContentBorder AdjectiveElement">
<div class="FinderContent">
<!-- TODO Fix ConvexElement -->
<div class="ToolBar ConvexElement">
</div>
<div class="FinderFileView">
<div class="FileTileView">
</div>
{{template "wde-widgets/scrollbar.tmpl" .}}
</div>
</div>
{{template "wde-widgets/scrollbar.tmpl" .}}
</div>
{{ end }}

View File

@ -7,9 +7,9 @@ import (
)
type DirectoryData struct {
MongoId primitive.ObjectID `bson:"_id"`
Parent primitive.ObjectID `bson:"parent_id"`
Children []primitive.ObjectID `bson:"children_id"`
MongoId primitive.ObjectID `bson:"_id" json:"-"`
Parent primitive.ObjectID `bson:"parent_id" json:"parent"`
Children []primitive.ObjectID `bson:"children_id" json:"children"`
}
func (fs *WebFileSystem) CreateDirectory(dirPath string) (primitive.ObjectID, primitive.ObjectID, error) {

View File

@ -6,7 +6,7 @@ import (
"github.com/gin-gonic/gin"
)
func (fs *WebFileSystem) Route(route *gin.RouterGroup) {
func (fs *WebFileSystem) PrivateRoutes(route *gin.RouterGroup) {
route.POST("/upload", func(ctx *gin.Context) { //TODO To PUT request
// fileName := ctx.Query("fileName")
// if fileName == "" {
@ -189,3 +189,7 @@ func (fs *WebFileSystem) Route(route *gin.RouterGroup) {
ctx.Status(http.StatusOK)
})
}
func (fs *WebFileSystem) PublicRoutes(route *gin.RouterGroup) {
}