aboutsummaryrefslogtreecommitdiff
path: root/pkg/view/filesystem.go
diff options
context:
space:
mode:
authorGabriel Arakaki Giovanini <mail@gabrielgio.me>2023-02-26 19:54:48 +0100
committerGabriel Arakaki Giovanini <mail@gabrielgio.me>2023-06-18 16:30:36 +0200
commitc8e1328164e9ffbd681c3c0e449f1e6b9856b896 (patch)
treefaee639a4c55c5dc3bfc59a5400026822c40221d /pkg/view/filesystem.go
downloadlens-c8e1328164e9ffbd681c3c0e449f1e6b9856b896.tar.gz
lens-c8e1328164e9ffbd681c3c0e449f1e6b9856b896.tar.bz2
lens-c8e1328164e9ffbd681c3c0e449f1e6b9856b896.zip
feat: Inicial commit
It contains rough template for the server and runners. It contains rough template for the server and runners.
Diffstat (limited to 'pkg/view/filesystem.go')
-rw-r--r--pkg/view/filesystem.go66
1 files changed, 66 insertions, 0 deletions
diff --git a/pkg/view/filesystem.go b/pkg/view/filesystem.go
new file mode 100644
index 0000000..f10d788
--- /dev/null
+++ b/pkg/view/filesystem.go
@@ -0,0 +1,66 @@
+package view
+
+import (
+ "github.com/valyala/fasthttp"
+
+ "git.sr.ht/~gabrielgio/img"
+ "git.sr.ht/~gabrielgio/img/pkg/components/filesystem"
+ "git.sr.ht/~gabrielgio/img/pkg/components/settings"
+ "git.sr.ht/~gabrielgio/img/pkg/ext"
+)
+
+type (
+ FileSystemView struct {
+ controller filesystem.Controller
+ settings settings.Repository
+ }
+ FilePage struct {
+ Page *filesystem.Page
+ ShowMode bool
+ ShowOwner bool
+ }
+)
+
+func NewFileSystemView(
+ controller filesystem.Controller,
+ settingsRepository settings.Repository,
+) *FileSystemView {
+ return &FileSystemView{
+ controller: controller,
+ settings: settingsRepository,
+ }
+}
+
+func (self *FileSystemView) Index(ctx *fasthttp.RequestCtx) error {
+ pathValue := string(ctx.FormValue("path"))
+
+ page, err := self.controller.GetPage(pathValue)
+ if err != nil {
+ return err
+ }
+
+ settings, err := self.settings.Load(ctx)
+ if err != nil {
+ return err
+ }
+
+ err = img.Render(ctx, "fs.html", &img.HTMLView[*FilePage]{
+ Title: pathValue,
+ Data: &FilePage{
+ Page: page,
+ ShowMode: settings.ShowMode,
+ ShowOwner: settings.ShowOwner,
+ },
+ })
+ if err != nil {
+ return err
+ }
+ return nil
+}
+
+func (self *FileSystemView) SetMyselfIn(r *ext.Router) {
+ r.GET("/", self.Index)
+ r.POST("/", self.Index)
+ r.GET("/fs/", self.Index)
+ r.POST("/fs/", self.Index)
+}