moving browser to a separate page so it can be a new tab/window if wanted
parent
6b2e01d0fc
commit
b2cf2c81d3
|
@ -2,29 +2,29 @@ package templates
|
|||
|
||||
import "fmt"
|
||||
|
||||
templ BrowserFileDiv() {
|
||||
templ browserFileDiv(browserUUID string) {
|
||||
<div class="section is-medium" id="browser-div">
|
||||
<div class="columns is-centered">
|
||||
<div class="column is-two-thirds">
|
||||
<div class="container">
|
||||
@uploadForm()
|
||||
@browserIframe(browserUUID)
|
||||
</div>
|
||||
</div>
|
||||
<div class="column is-one-third">
|
||||
@BrowserFilePicker()
|
||||
@browserFilePicker()
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
templ BrowserFilePicker() {
|
||||
templ browserFilePicker() {
|
||||
<div class="container" id="file-picker"></div>
|
||||
}
|
||||
|
||||
templ BrowserIframe(browserUUID string) {
|
||||
templ browserIframe(browserUUID string) {
|
||||
<div class="container" id="browser">
|
||||
<iframe
|
||||
src={ fmt.Sprintf("/browser/%s", browserUUID) }
|
||||
src={ fmt.Sprintf("/ct/%s/", browserUUID) }
|
||||
title="Browser"
|
||||
allow="fullscreen"
|
||||
sandbox
|
||||
|
|
|
@ -12,7 +12,7 @@ import "bytes"
|
|||
|
||||
import "fmt"
|
||||
|
||||
func BrowserFileDiv() templ.Component {
|
||||
func browserFileDiv(browserUUID string) templ.Component {
|
||||
return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) {
|
||||
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer)
|
||||
if !templ_7745c5c3_IsBuffer {
|
||||
|
@ -29,7 +29,7 @@ func BrowserFileDiv() templ.Component {
|
|||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = uploadForm().Render(ctx, templ_7745c5c3_Buffer)
|
||||
templ_7745c5c3_Err = browserIframe(browserUUID).Render(ctx, templ_7745c5c3_Buffer)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ func BrowserFileDiv() templ.Component {
|
|||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = BrowserFilePicker().Render(ctx, templ_7745c5c3_Buffer)
|
||||
templ_7745c5c3_Err = browserFilePicker().Render(ctx, templ_7745c5c3_Buffer)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ func BrowserFileDiv() templ.Component {
|
|||
})
|
||||
}
|
||||
|
||||
func BrowserFilePicker() templ.Component {
|
||||
func browserFilePicker() templ.Component {
|
||||
return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) {
|
||||
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer)
|
||||
if !templ_7745c5c3_IsBuffer {
|
||||
|
@ -76,7 +76,7 @@ func BrowserFilePicker() templ.Component {
|
|||
})
|
||||
}
|
||||
|
||||
func BrowserIframe(browserUUID string) templ.Component {
|
||||
func browserIframe(browserUUID string) templ.Component {
|
||||
return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) {
|
||||
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer)
|
||||
if !templ_7745c5c3_IsBuffer {
|
||||
|
|
|
@ -95,5 +95,11 @@ templ NewFilePage(metaContent utils.MetaContent, title string, err error) {
|
|||
}
|
||||
|
||||
templ Empty() {
|
||||
<div></div>
|
||||
<div id="empty"></div>
|
||||
}
|
||||
|
||||
templ Browser(metaContent utils.MetaContent, title string, browserUUID string,err error) {
|
||||
@wrapBase(metaContent, title, err) {
|
||||
@browserFileDiv(browserUUID)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -362,7 +362,46 @@ func Empty() templ.Component {
|
|||
templ_7745c5c3_Var17 = templ.NopComponent
|
||||
}
|
||||
ctx = templ.ClearChildren(ctx)
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<div></div>")
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<div id=\"empty\"></div>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
if !templ_7745c5c3_IsBuffer {
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W)
|
||||
}
|
||||
return templ_7745c5c3_Err
|
||||
})
|
||||
}
|
||||
|
||||
func Browser(metaContent utils.MetaContent, title string, browserUUID string, err error) templ.Component {
|
||||
return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) {
|
||||
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer)
|
||||
if !templ_7745c5c3_IsBuffer {
|
||||
templ_7745c5c3_Buffer = templ.GetBuffer()
|
||||
defer templ.ReleaseBuffer(templ_7745c5c3_Buffer)
|
||||
}
|
||||
ctx = templ.InitializeContext(ctx)
|
||||
templ_7745c5c3_Var18 := templ.GetChildren(ctx)
|
||||
if templ_7745c5c3_Var18 == nil {
|
||||
templ_7745c5c3_Var18 = templ.NopComponent
|
||||
}
|
||||
ctx = templ.ClearChildren(ctx)
|
||||
templ_7745c5c3_Var19 := templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) {
|
||||
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer)
|
||||
if !templ_7745c5c3_IsBuffer {
|
||||
templ_7745c5c3_Buffer = templ.GetBuffer()
|
||||
defer templ.ReleaseBuffer(templ_7745c5c3_Buffer)
|
||||
}
|
||||
templ_7745c5c3_Err = browserFileDiv(browserUUID).Render(ctx, templ_7745c5c3_Buffer)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
if !templ_7745c5c3_IsBuffer {
|
||||
_, templ_7745c5c3_Err = io.Copy(templ_7745c5c3_W, templ_7745c5c3_Buffer)
|
||||
}
|
||||
return templ_7745c5c3_Err
|
||||
})
|
||||
templ_7745c5c3_Err = wrapBase(metaContent, title, err).Render(templ.WithChildren(ctx, templ_7745c5c3_Var19), templ_7745c5c3_Buffer)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
|
|
|
@ -1,31 +1,19 @@
|
|||
package ui
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"git.jmbit.de/filegate/filegate/db"
|
||||
"git.jmbit.de/filegate/filegate/utils"
|
||||
"git.jmbit.de/filegate/filegate/web/templates"
|
||||
)
|
||||
|
||||
func getBrowser(c *gin.Context) {
|
||||
id := c.Param("id")
|
||||
//TODO: save to session instead of hitting DB for this
|
||||
container, err := db.ContainerByFolder(id)
|
||||
port := container.Port
|
||||
if err != nil {
|
||||
log.Printf("could not get container from Folder UUID: %v", err)
|
||||
c.HTML(http.StatusNotFound, "", templates.Index(utils.GenMetaContent(c), err))
|
||||
}
|
||||
targetURL := fmt.Sprintf("http://localhost:%d/", port)
|
||||
proxy, err := createReverseProxy(targetURL)
|
||||
if err != nil {
|
||||
log.Printf("could not get container from Folder UUID: %v", err)
|
||||
c.HTML(http.StatusNotFound, "", templates.Index(utils.GenMetaContent(c), err))
|
||||
}
|
||||
proxy.ServeHTTP(c.Writer, c.Request)
|
||||
c.HTML(
|
||||
http.StatusOK,
|
||||
"",
|
||||
templates.Browser(utils.GenMetaContent(c), "Filegate Browser", id, nil),
|
||||
)
|
||||
}
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
package ui
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"git.jmbit.de/filegate/filegate/db"
|
||||
"git.jmbit.de/filegate/filegate/utils"
|
||||
"git.jmbit.de/filegate/filegate/web/templates"
|
||||
)
|
||||
|
||||
func getContainer(c *gin.Context) {
|
||||
id := c.Param("id")
|
||||
//TODO: save to session instead of hitting DB for this
|
||||
container, err := db.ContainerByFolder(id)
|
||||
port := container.Port
|
||||
if err != nil {
|
||||
log.Printf("could not get container from Folder UUID: %v", err)
|
||||
c.HTML(http.StatusNotFound, "", templates.Index(utils.GenMetaContent(c), err))
|
||||
}
|
||||
targetURL := fmt.Sprintf("http://localhost:%d/", port)
|
||||
proxy, err := createReverseProxy(targetURL)
|
||||
if err != nil {
|
||||
log.Printf("could not get container from Folder UUID: %v", err)
|
||||
c.HTML(http.StatusNotFound, "", templates.Index(utils.GenMetaContent(c), err))
|
||||
}
|
||||
proxy.ServeHTTP(c.Writer, c.Request)
|
||||
}
|
|
@ -10,14 +10,16 @@ func GroupWeb(router *gin.Engine) *gin.Engine {
|
|||
router.POST("/", index)
|
||||
router.GET("/login.html", getLogin)
|
||||
router.POST("/login.html", postLogin)
|
||||
file := router.Group("/file/")
|
||||
file := router.Group("/file")
|
||||
file.GET("/", getFileListPage)
|
||||
file.GET("/empty.html", empty)
|
||||
file.GET("/new/", getNewFile)
|
||||
file.POST("/new/upload", postNewFileUpload)
|
||||
file.POST("/new/download", postNewFileDownload)
|
||||
file.POST("/new/browser", postNewFileBrowser)
|
||||
router.Any("/browser/:id/*any", getBrowser)
|
||||
browser := router.Group("/browser")
|
||||
browser.GET("/:id", getBrowser)
|
||||
router.Any("/ct/:id/*any", getContainer)
|
||||
|
||||
return router
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue