package view import ( "github.com/valyala/fasthttp" "git.sr.ht/~gabrielgio/img" "git.sr.ht/~gabrielgio/img/pkg/database/repository" "git.sr.ht/~gabrielgio/img/pkg/ext" "git.sr.ht/~gabrielgio/img/pkg/service" ) type ( FileSystemView struct { fsService service.FileSystemController settings repository.SettingsRepository } FilePage struct { Page *service.Page ShowMode bool ShowOwner bool } ) func NewFileSystemView( controller service.FileSystemController, settingsRepository repository.SettingsRepository, ) *FileSystemView { return &FileSystemView{ fsService: controller, settings: settingsRepository, } } func (self *FileSystemView) Index(ctx *fasthttp.RequestCtx) error { pathValue := string(ctx.FormValue("path")) token := ext.GetTokenFromCtx(ctx) page, err := self.fsService.GetPage(ctx, token.UserID, 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) }