package view import ( "net/http" "git.sr.ht/~gabrielgio/img/pkg/database/repository" "git.sr.ht/~gabrielgio/img/pkg/ext" "git.sr.ht/~gabrielgio/img/pkg/service" "git.sr.ht/~gabrielgio/img/templates" ) 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(w http.ResponseWriter, r *http.Request) error { var ( pathValue = r.FormValue("path") token = ext.GetTokenFromCtx(w, r) ) page, err := self.fsService.GetPage(r.Context(), token.UserID, pathValue) if err != nil { return err } settings, err := self.settings.Load(r.Context()) if err != nil { return err } templates.WritePageTemplate(w, &templates.FilePage{ Page: page, ShowMode: settings.ShowMode, ShowOwner: settings.ShowOwner, }) 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) }