From 9be88f83c29f42d97e1acd4cdaaa7de383f064f5 Mon Sep 17 00:00:00 2001 From: Eliot Whalan Date: Sun, 19 Jun 2016 16:44:46 +1000 Subject: [PATCH] Add dupe paste checking --- main.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/main.go b/main.go index 3d59c70..5259d9c 100644 --- a/main.go +++ b/main.go @@ -79,6 +79,15 @@ func save(raw []byte) []string { check(err) sha := hash(p) + query, err := db.Query("select id, hash, paste, delkey from pastebin") + for query.Next() { + var id, hash, paste, delkey string + err := query.Scan(&id, hash, paste, delkey) + check(err) + if hash == sha { + return []string{id, hash, paste, delkey} + } + } id := generateName() url := ADDRESS + "/p/" + id delKey := uniuri.NewLen(40) @@ -94,6 +103,9 @@ func save(raw []byte) []string { } func delHandler(w http.ResponseWriter, r *http.Request) { + /* vars := mux.Vars(r) + paste := vars["pasteId"] + delkey := vars["delKey"] */ } func saveHandler(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r)