aboutsummaryrefslogtreecommitdiff
path: root/pkg/view
diff options
context:
space:
mode:
authorGabriel Arakaki Giovanini <mail@gabrielgio.me>2023-10-01 16:29:10 +0200
committerGabriel Arakaki Giovanini <mail@gabrielgio.me>2023-10-01 16:29:10 +0200
commit91f7c40479aa9ef18c7927913be49a014a8a3115 (patch)
tree4f1dc8e8cad47311071e15bcc92b9e812a7eb2c2 /pkg/view
parenta87e03ac1b777be4169f0d27c69e17505d96802b (diff)
downloadlens-91f7c40479aa9ef18c7927913be49a014a8a3115.tar.gz
lens-91f7c40479aa9ef18c7927913be49a014a8a3115.tar.bz2
lens-91f7c40479aa9ef18c7927913be49a014a8a3115.zip
feat: Add detail page
Diffstat (limited to 'pkg/view')
-rw-r--r--pkg/view/media.go39
1 files changed, 39 insertions, 0 deletions
diff --git a/pkg/view/media.go b/pkg/view/media.go
index 8a10fe0..88ecaf2 100644
--- a/pkg/view/media.go
+++ b/pkg/view/media.go
@@ -3,6 +3,7 @@ package view
import (
"net/http"
"strconv"
+ "strings"
"git.sr.ht/~gabrielgio/img/pkg/database/repository"
"git.sr.ht/~gabrielgio/img/pkg/ext"
@@ -103,6 +104,41 @@ func (self *MediaView) Index(w http.ResponseWriter, r *http.Request) error {
return nil
}
+func (self *MediaView) Detail(w http.ResponseWriter, r *http.Request) error {
+ user := ext.GetUserFromCtx(r)
+
+ userPath, err := self.userRepository.GetPathFromUserID(r.Context(), user.ID)
+ if err != nil {
+ return err
+ }
+
+ pathHash := r.FormValue("path_hash")
+
+ media, err := self.mediaRepository.Get(r.Context(), pathHash)
+ if err != nil {
+ return err
+ }
+
+ if !strings.Contains(media.Path, userPath) {
+ ext.NotFound(w)
+ return nil
+ }
+
+ settings, err := self.settingsRepository.Load(r.Context())
+ if err != nil {
+ return err
+ }
+
+ page := &templates.DetailPage{
+ Settings: settings,
+ Media: media,
+ }
+
+ templates.WritePageTemplate(w, page, user.IsAdmin)
+
+ return nil
+}
+
func (self *MediaView) GetImage(w http.ResponseWriter, r *http.Request) error {
pathHash := r.FormValue("path_hash")
@@ -135,6 +171,9 @@ func (self *MediaView) SetMyselfIn(r *ext.Router) {
r.GET("/media", self.Index)
r.POST("/media", self.Index)
+ r.GET("/detail", self.Detail)
+ r.POST("/detail", self.Detail)
+
r.GET("/media/image", self.GetImage)
r.GET("/media/thumbnail", self.GetThumbnail)
}