summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorAlexander Kiryukhin <a.kiryukhin@mail.ru>2021-03-18 03:01:46 +0300
committerAlexander Kiryukhin <a.kiryukhin@mail.ru>2021-03-18 03:01:46 +0300
commit37c250d538893ff8178bd9c9e4dde225a991ce76 (patch)
tree379350cdfe47d3691fef9c8c5ef91acddfba36d3 /main.go
parent6f31f35c7b38fbf63d7a0c9322458e0b75828495 (diff)
pevent access from messengers
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) {