start create frontend work of app
This commit is contained in:
parent
264a8d38d6
commit
28ccfb58c3
40
main.go
40
main.go
@ -7,12 +7,6 @@ import (
|
||||
"os"
|
||||
|
||||
"personalwebsite/apps"
|
||||
blogwriter "personalwebsite/apps/BlogWriter"
|
||||
"personalwebsite/apps/aboutme"
|
||||
"personalwebsite/apps/blogviewer"
|
||||
"personalwebsite/apps/finder"
|
||||
imgviewer "personalwebsite/apps/img-viewer"
|
||||
"personalwebsite/apps/sunboard"
|
||||
"personalwebsite/routes"
|
||||
"personalwebsite/wde"
|
||||
"personalwebsite/webfilesystem"
|
||||
@ -42,10 +36,10 @@ func main() {
|
||||
panic(err.Error())
|
||||
}
|
||||
|
||||
publicPort, err := FindEnv("PUBLIC_PORT")
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
// publicPort, err := FindEnv("PUBLIC_PORT")
|
||||
// if err != nil {
|
||||
// panic(err.Error())
|
||||
// }
|
||||
|
||||
privatePort, err := FindEnv("PRIVATE_PORT")
|
||||
if err != nil {
|
||||
@ -68,21 +62,21 @@ func main() {
|
||||
webde := wde.NewWDE(webfs)
|
||||
|
||||
//TODO Split to different apps init for private and public?
|
||||
persPropsApp := aboutme.NewAboutMeApp(webfs)
|
||||
finderApp := finder.NewFinderApplication(webfs)
|
||||
imgViewerApp := imgviewer.NewImgViewerApp(webfs)
|
||||
blogViewerApp := blogviewer.NewBlogViewerApp(webfs)
|
||||
blogWriterApp := blogwriter.NewBlogWriterApp(webfs)
|
||||
sunBoardApp := sunboard.NewSunboardApp(webfs, webde, appsStorage)
|
||||
// persPropsApp := aboutme.NewAboutMeApp(webfs)
|
||||
// finderApp := finder.NewFinderApplication(webfs)
|
||||
// imgViewerApp := imgviewer.NewImgViewerApp(webfs)
|
||||
// blogViewerApp := blogviewer.NewBlogViewerApp(webfs)
|
||||
// blogWriterApp := blogwriter.NewBlogWriterApp(webfs)
|
||||
// sunBoardApp := sunboard.NewSunboardApp(webfs, webde, appsStorage)
|
||||
|
||||
appsStorage.Apps["personal-properties"] = persPropsApp
|
||||
appsStorage.Apps["finder"] = finderApp
|
||||
appsStorage.Apps["img-viewer"] = imgViewerApp
|
||||
appsStorage.Apps[blogViewerApp.GetAppID()] = blogViewerApp
|
||||
appsStorage.Apps["BlogWriter"] = blogWriterApp
|
||||
appsStorage.Apps["Sunboard"] = sunBoardApp
|
||||
// appsStorage.Apps["personal-properties"] = persPropsApp
|
||||
// appsStorage.Apps["finder"] = finderApp
|
||||
// appsStorage.Apps["img-viewer"] = imgViewerApp
|
||||
// appsStorage.Apps[blogViewerApp.GetAppID()] = blogViewerApp
|
||||
// appsStorage.Apps["BlogWriter"] = blogWriterApp
|
||||
// appsStorage.Apps["Sunboard"] = sunBoardApp
|
||||
|
||||
go routes.PublicRoutes(publicPort, webfs, webde, appsStorage)
|
||||
// go routes.PublicRoutes(publicPort, webfs, webde, appsStorage)
|
||||
routes.PrivateRoutes(privatePort, webfs, webde, appsStorage)
|
||||
}
|
||||
|
||||
|
@ -31,58 +31,59 @@ func PrivateRoutes(port string, webfs *webfilesystem.WebFileSystem, webde *wde.W
|
||||
router.LoadHTMLGlob("templates/**/*")
|
||||
router.Static("/res", "res")
|
||||
router.Static("/front", "./front/")
|
||||
// router.Use(cors.New(cors.Config{
|
||||
// AllowOrigins: []string{"http://localhost:1234"},
|
||||
// AllowMethods: []string{"PUT", "PATCH"},
|
||||
// AllowHeaders: []string{"Origin"},
|
||||
// ExposeHeaders: []string{"Content-Length"},
|
||||
// AllowCredentials: true,
|
||||
// AllowOriginFunc: func(origin string) bool {
|
||||
// return origin == "http://localhost:1234"
|
||||
// },
|
||||
// MaxAge: 12 * time.Hour,
|
||||
// }))
|
||||
router.Use(cors.New(cors.Config{
|
||||
AllowOrigins: []string{"http://localhost:5173"},
|
||||
AllowMethods: []string{"PUT", "PATCH"},
|
||||
AllowHeaders: []string{"Origin"},
|
||||
ExposeHeaders: []string{"Content-Length"},
|
||||
AllowCredentials: true,
|
||||
AllowOriginFunc: func(origin string) bool {
|
||||
return origin == "http://localhost:5173"
|
||||
},
|
||||
MaxAge: 12 * time.Hour,
|
||||
}))
|
||||
// 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.Status(200)
|
||||
// appString := AppString{
|
||||
// AppPath: "/Applications/Finder.app",
|
||||
// Args: []string{"/home/user"},
|
||||
// }
|
||||
|
||||
appString := AppString{
|
||||
AppPath: "/Applications/BlogViewer.app",
|
||||
Args: []string{"/home/user/Blogs/blog1.blog"},
|
||||
}
|
||||
_ = appString
|
||||
aboutMe := AppString{
|
||||
AppPath: "/Applications/AboutMe.app",
|
||||
Args: []string{},
|
||||
}
|
||||
_ = aboutMe
|
||||
desktop := AppString{
|
||||
AppPath: "/Applications/Finder.app",
|
||||
Args: []string{"/", "--desktop", "desktop-layer"},
|
||||
}
|
||||
// appString := AppString{
|
||||
// AppPath: "/Applications/BlogViewer.app",
|
||||
// Args: []string{"/home/user/Blogs/blog1.blog"},
|
||||
// }
|
||||
// _ = appString
|
||||
// aboutMe := AppString{
|
||||
// AppPath: "/Applications/AboutMe.app",
|
||||
// Args: []string{},
|
||||
// }
|
||||
// _ = aboutMe
|
||||
// desktop := AppString{
|
||||
// AppPath: "/Applications/Finder.app",
|
||||
// Args: []string{"/", "--desktop", "desktop-layer"},
|
||||
// }
|
||||
|
||||
autostart := []AppString{desktop}
|
||||
d := mobile.GetDevice(ctx)
|
||||
switch {
|
||||
// Hey I'm a desktop!... or laptop but not a mobile or tablet!
|
||||
case d.Normal():
|
||||
ctx.HTML(http.StatusOK, "index.html", gin.H{
|
||||
"autostart": autostart,
|
||||
})
|
||||
// Hey I'm a mobile device!
|
||||
case d.Mobile():
|
||||
ctx.HTML(http.StatusOK, "mobile-desktop.html", gin.H{
|
||||
// "autostart": autostart,
|
||||
})
|
||||
// Woa I'm a tablet!
|
||||
case d.Tablet():
|
||||
ctx.JSON(http.StatusOK, "Hello I'm a tablet device")
|
||||
}
|
||||
// autostart := []AppString{desktop}
|
||||
// d := mobile.GetDevice(ctx)
|
||||
// switch {
|
||||
// // Hey I'm a desktop!... or laptop but not a mobile or tablet!
|
||||
// case d.Normal():
|
||||
// ctx.HTML(http.StatusOK, "index.html", gin.H{
|
||||
// "autostart": autostart,
|
||||
// })
|
||||
// // Hey I'm a mobile device!
|
||||
// case d.Mobile():
|
||||
// ctx.HTML(http.StatusOK, "mobile-desktop.html", gin.H{
|
||||
// // "autostart": autostart,
|
||||
// })
|
||||
// // Woa I'm a tablet!
|
||||
// case d.Tablet():
|
||||
// ctx.JSON(http.StatusOK, "Hello I'm a tablet device")
|
||||
// }
|
||||
|
||||
})
|
||||
systemGroup := router.Group("system")
|
||||
@ -114,6 +115,9 @@ func PrivateRoutes(port string, webfs *webfilesystem.WebFileSystem, webde *wde.W
|
||||
|
||||
fsGroup := systemGroup.Group("fs")
|
||||
{
|
||||
fsGroup.GET("/", func(ctx *gin.Context) {
|
||||
ctx.Status(http.StatusInternalServerError)
|
||||
})
|
||||
webfs.PrivateRoutes(fsGroup)
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
//TODO Transparently split to single data and header reading methods
|
||||
// TODO Transparently split to single data and header reading methods
|
||||
func (fs *WebFileSystem) readFSDocs(fileID primitive.ObjectID, fileData interface{}) (*FileHeader, error) {
|
||||
fileHeader := &FileHeader{}
|
||||
filter := primitive.M{
|
||||
@ -28,6 +28,27 @@ func (fs *WebFileSystem) readFSDocs(fileID primitive.ObjectID, fileData interfac
|
||||
return fileHeader, nil
|
||||
}
|
||||
|
||||
// New method
|
||||
func (fs *WebFileSystem) readFileData(fileID primitive.ObjectID) (fileData interface{}, err error) {
|
||||
fileHeader := &FileHeader{}
|
||||
filter := primitive.M{
|
||||
"_id": fileID,
|
||||
}
|
||||
|
||||
err = fs.webfsFilesTable.FindOne(fs.ctx, filter).Decode(fileHeader)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
filterData := primitive.M{
|
||||
"_id": fileHeader.Data,
|
||||
}
|
||||
err = fs.webfsFilesData.FindOne(fs.ctx, filterData).Decode(fileData)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return fileData, nil
|
||||
}
|
||||
|
||||
func (fs *WebFileSystem) writeFileToMongo(file *FileHeader, data interface{}) (primitive.ObjectID, primitive.ObjectID, error) {
|
||||
resData, err := fs.webfsFilesData.InsertOne(fs.ctx, data)
|
||||
if err != nil {
|
||||
@ -71,7 +92,7 @@ func (fs *WebFileSystem) removeFromMongo(fileId primitive.ObjectID) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
//Deprecated
|
||||
// Deprecated
|
||||
func (fs *WebFileSystem) Validate() error {
|
||||
// filter := primitive.D{
|
||||
// {
|
||||
|
@ -16,6 +16,36 @@ func (fs *WebFileSystem) Read(filePath string, fileData interface{}) (*FileHeade
|
||||
return fileHeader, nil
|
||||
}
|
||||
|
||||
// Oboslete method
|
||||
func (fs *WebFileSystem) ReadData(filePath string, fileData interface{}) (*FileHeader, error) {
|
||||
fileId, err := fs.FindFile(filePath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
fileHeader, err := fs.ReadByObjectID(fileId, fileData)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return fileHeader, nil
|
||||
}
|
||||
|
||||
// New method
|
||||
func (fs *WebFileSystem) readData(filePath string) (interface{}, error) {
|
||||
fileId, err := fs.FindFile(filePath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
fileData, err := fs.readFileData(fileId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return fileData, nil
|
||||
}
|
||||
|
||||
func (fs *WebFileSystem) ReadByObjectID(fileID primitive.ObjectID, fileData interface{}) (*FileHeader, error) {
|
||||
fileHeader, err := fs.readFSDocs(fileID, fileData)
|
||||
if err != nil {
|
||||
|
@ -117,7 +117,7 @@ func (fs *WebFileSystem) PrivateRoutes(route *gin.RouterGroup) {
|
||||
ctx.JSON(http.StatusOK, "OK")
|
||||
})
|
||||
|
||||
route.GET("list", func(ctx *gin.Context) {
|
||||
route.GET("listDir", func(ctx *gin.Context) {
|
||||
path := ctx.Query("path")
|
||||
if path == "" {
|
||||
ctx.JSON(http.StatusBadRequest, "TODO") //TODO json error struct
|
||||
@ -149,6 +149,23 @@ func (fs *WebFileSystem) PrivateRoutes(route *gin.RouterGroup) {
|
||||
ctx.JSON(http.StatusOK, &file)
|
||||
})
|
||||
|
||||
route.GET("readFileData", func(ctx *gin.Context) {
|
||||
path := ctx.Query("path")
|
||||
if path == "" {
|
||||
ctx.JSON(http.StatusBadRequest, "TODO") //TODO json error struct
|
||||
return
|
||||
}
|
||||
|
||||
// data :=
|
||||
file, err := fs.readData(path)
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusInternalServerError, "TODO") //TODO json error struct
|
||||
return
|
||||
}
|
||||
// fs.
|
||||
ctx.JSON(http.StatusOK, &file)
|
||||
})
|
||||
|
||||
route.GET("validate", func(ctx *gin.Context) {
|
||||
err := fs.validate()
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user