diff options
Diffstat (limited to 'pkg/view')
-rw-r--r-- | pkg/view/filesystem.go | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/pkg/view/filesystem.go b/pkg/view/filesystem.go index 9071ec0..f78f8a6 100644 --- a/pkg/view/filesystem.go +++ b/pkg/view/filesystem.go @@ -1,7 +1,9 @@ package view import ( + "mime" "net/http" + "path/filepath" "git.sr.ht/~gabrielgio/img/pkg/database/repository" "git.sr.ht/~gabrielgio/img/pkg/ext" @@ -37,7 +39,24 @@ func (self *FileSystemView) Index(w http.ResponseWriter, r *http.Request) error user = ext.GetUserFromCtx(r) ) - page, err := self.fsService.GetPage(r.Context(), user.ID, pathValue) + fullpath, err := self.fsService.GetFullpath(r.Context(), user.ID, pathValue) + if err != nil { + return err + } + + isFile, err := self.fsService.IsFile(r.Context(), fullpath) + if err != nil { + return err + } + + if isFile { + mimetype := mime.TypeByExtension(filepath.Ext(fullpath)) + w.Header().Set("Content-Type", mimetype) + http.ServeFile(w, r, fullpath) + return nil + } + + page, err := self.fsService.GetPage(r.Context(), pathValue, fullpath) if err != nil { return err } |