personal-website/apps/finder/routes.go

123 lines
3.2 KiB
Go
Raw Normal View History

2023-05-05 14:44:03 +00:00
package finder
import (
"net/http"
2023-05-18 01:57:44 +00:00
"personalwebsite/apps/appCtx"
"personalwebsite/errormessage"
2023-05-05 14:44:03 +00:00
2023-07-22 22:00:51 +00:00
mobile "github.com/floresj/go-contrib-mobile"
2023-05-05 14:44:03 +00:00
"github.com/gin-gonic/gin"
)
func (f *FinderApplication) PublicRoutes(routes *gin.RouterGroup) {
2023-05-18 01:57:44 +00:00
routes.POST("render", func(ctx *gin.Context) {
appCtx := appCtx.AppContext{}
err := ctx.BindJSON(&appCtx)
if err != nil {
ctx.JSON(http.StatusBadRequest, errormessage.ErrorMessage{
Message: "Error in decoding app bundle",
})
return
}
2023-07-22 22:00:51 +00:00
d := mobile.GetDevice(ctx)
switch {
case d.Mobile():
ctx.HTML(http.StatusOK, "templates/finder/mobile-app.tmpl", gin.H{
// "autostart": autostart,
})
default:
ctx.HTML(http.StatusOK, "finder/app.tmpl", f.Render(appCtx))
}
2023-05-05 14:44:03 +00:00
})
2023-07-22 18:15:17 +00:00
//Obsolete
2023-05-05 14:44:03 +00:00
routes.GET("renderMobileDesktop", func(ctx *gin.Context) {
ctx.HTML(http.StatusOK, "finder/mobile-desktop.tmpl", gin.H{})
})
2023-07-22 18:15:17 +00:00
2023-06-06 22:49:26 +00:00
routes.POST("renderDesktop", func(ctx *gin.Context) {
2023-05-05 14:44:03 +00:00
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")
2023-05-09 03:17:34 +00:00
filePath := ctx.Query("path")
if filePath == "" {
ctx.Status(http.StatusBadRequest)
return
}
2023-05-05 14:44:03 +00:00
data := ctx.Query("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) {
2023-05-18 01:57:44 +00:00
routes.POST("render", func(ctx *gin.Context) {
appCtx := appCtx.AppContext{}
err := ctx.BindJSON(&appCtx)
if err != nil {
ctx.JSON(http.StatusBadRequest, errormessage.ErrorMessage{
2023-06-06 22:49:26 +00:00
Message: "Error in decoding app bundle",
2023-05-18 01:57:44 +00:00
})
return
}
2023-07-22 22:00:51 +00:00
d := mobile.GetDevice(ctx)
switch {
case d.Mobile():
ctx.HTML(http.StatusOK, "finder/mobile-app.tmpl", f.Render(appCtx))
default:
ctx.HTML(http.StatusOK, "finder/admin-app.tmpl", f.Render(appCtx))
}
})
2023-06-06 22:49:26 +00:00
routes.GET("renderMobileDesktop", func(ctx *gin.Context) {
ctx.HTML(http.StatusOK, "finder/mobile-desktop.tmpl", gin.H{})
})
routes.POST("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)
2023-05-05 14:44:03 +00:00
ctx.HTML(http.StatusOK, "wde-widgets/context-menu.tmpl", ginH)
})
2023-05-05 22:07:09 +00:00
routes.GET("renderProps", func(ctx *gin.Context) {
filePath := ctx.Query("path")
2023-05-07 21:20:40 +00:00
ginH, err := f.RenderProps(filePath)
if err != nil {
ctx.Status(http.StatusInternalServerError)
return
}
2023-05-05 22:07:09 +00:00
ctx.HTML(http.StatusOK, "finder/props.tmpl", ginH)
})
2023-05-05 14:44:03 +00:00
}