From 37c250d538893ff8178bd9c9e4dde225a991ce76 Mon Sep 17 00:00:00 2001 From: Alexander Kiryukhin Date: Thu, 18 Mar 2021 03:01:46 +0300 Subject: pevent access from messengers --- main.go | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'main.go') 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) { -- cgit v1.2.3