Add dupe paste checking

This commit is contained in:
Eliot Whalan 2016-06-19 16:44:46 +10:00
parent b20229ca98
commit 8bcc435c50
No known key found for this signature in database
GPG Key ID: C0A42175139840D6
1 changed files with 12 additions and 0 deletions

12
main.go
View File

@ -79,6 +79,15 @@ func save(raw []byte) []string {
check(err) check(err)
sha := hash(p) 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() id := generateName()
url := ADDRESS + "/p/" + id url := ADDRESS + "/p/" + id
delKey := uniuri.NewLen(40) delKey := uniuri.NewLen(40)
@ -94,6 +103,9 @@ func save(raw []byte) []string {
} }
func delHandler(w http.ResponseWriter, r *http.Request) { 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) { func saveHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r) vars := mux.Vars(r)