summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'main.go')
-rw-r--r--main.go23
1 files changed, 21 insertions, 2 deletions
diff --git a/main.go b/main.go
index f3a9c22..0cf0827 100644
--- a/main.go
+++ b/main.go
@@ -102,18 +102,37 @@ func main() {
r.Get("/s/{id}", func(rw http.ResponseWriter, r *http.Request) {
id := chi.URLParam(r, "id")
- secret, err := s.Get(id, "")
if err != nil {
log.Println(err)
_ = tpl.Render("notfound.gohtml", nil, rw)
return
}
- if err := tpl.Render("memo.gohtml", renderer.Map{"secret": secret}, rw); err != nil {
+ _, err := s.IsEncrypted(id)
+ if err != nil {
+ log.Println(err)
+ _ = tpl.Render("notfound.gohtml", nil, rw)
+ return
+ }
+ if err := tpl.Render("memo.gohtml", renderer.Map{"id": id}, rw); err != nil {
log.Println(err)
_ = tpl.Render("error.gohtml", nil, rw)
}
})
+ r.Get("/api/s/{id}", func(rw http.ResponseWriter, r *http.Request) {
+ id := chi.URLParam(r, "id")
+ secret, err := s.Get(id, "")
+ if err != nil {
+ log.Println(err)
+ _ = tpl.Render("notfoundinline.gohtml", nil, rw)
+ return
+ }
+ if err := tpl.Render("secret.gohtml", renderer.Map{"secret": secret}, rw); err != nil {
+ log.Println(err)
+ _ = tpl.Render("notfoundinline.gohtml", nil, rw)
+ }
+ })
+
filesDir := http.Dir(filepath.Join(workDir, "public"))
r.Get("/*", func(w http.ResponseWriter, r *http.Request) {