diff options
author | Alexander Kiryukhin <a.kiryukhin@mail.ru> | 2021-03-18 03:01:46 +0300 |
---|---|---|
committer | Alexander Kiryukhin <a.kiryukhin@mail.ru> | 2021-03-18 03:01:46 +0300 |
commit | 37c250d538893ff8178bd9c9e4dde225a991ce76 (patch) | |
tree | 379350cdfe47d3691fef9c8c5ef91acddfba36d3 /main.go | |
parent | 6f31f35c7b38fbf63d7a0c9322458e0b75828495 (diff) |
pevent access from messengers
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 23 |
1 files changed, 21 insertions, 2 deletions
@@ -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) { |