From c04b4f2a68773f0361903e5ad25a46101c46296a Mon Sep 17 00:00:00 2001 From: Zack Scholl Date: Sun, 14 Feb 2016 09:31:30 -0500 Subject: [PATCH] Keeping random for now...not gauranteeing *no* collisions yet... Former-commit-id: 829790cd667b22fdebf335ed5eabfc2b8231d275 [formerly 56a83fa27db5527f6aecddd55d0e5a176fc90b01] [formerly e5d2c26518289f0dffedd16f4f9547e3da15a48f [formerly 9c57046a6f481c6addadc5ad3f8ccaad2ffa5ebf [formerly 0228d539292ae4b817b7a661b6a142f416916fd2]]] Former-commit-id: 2c2961d3fd98262b58792638e964cd4ae5a1baa3 [formerly 45e0ca872d8731bc8ecad719bd725d7bfc2af4b6] Former-commit-id: add863c06877ae869be205ca4409c4ec5be8f467 Former-commit-id: 76fcf04f45198cf1b04082d50afd4e447cb7b236 --- db.go | 24 ++++++++++++------------ routes.go | 31 +++++++++++++++++++++++++++++++ utils.go | 32 ++++++++++++++++---------------- 3 files changed, 59 insertions(+), 28 deletions(-) diff --git a/db.go b/db.go index 1053e26..bb2b76d 100644 --- a/db.go +++ b/db.go @@ -179,18 +179,18 @@ func (p *WikiData) save(newText string) error { } return err }) - // Add the new name to the programdata so its not randomly generated - if err == nil { - err2 := db.Update(func(tx *bolt.Tx) error { - b := tx.Bucket([]byte("programdata")) - id, _ := b.NextSequence() - idInt := int(id) - return b.Put(itob(idInt), []byte(p.Title)) - }) - if err2 != nil { - return fmt.Errorf("could not add to programdata: %s", err) - } - } + // // Add the new name to the programdata so its not randomly generated + // if err == nil && len(p.Timestamps) > 0 && len(p.CurrentText) > 0 { + // err2 := db.Update(func(tx *bolt.Tx) error { + // b := tx.Bucket([]byte("programdata")) + // id, _ := b.NextSequence() + // idInt := int(id) + // return b.Put(itob(idInt), []byte(p.Title)) + // }) + // if err2 != nil { + // return fmt.Errorf("could not add to programdata: %s", err) + // } + // } return err } diff --git a/routes.go b/routes.go index 657513c..2e1535c 100644 --- a/routes.go +++ b/routes.go @@ -262,6 +262,37 @@ func deletePage(c *gin.Context) { // if adminKey == RuntimeArgs.AdminKey || true == true { p := WikiData{strings.ToLower(deleteName), "", []string{}, []string{}} p.save("") + + // // remove from program data + // var deleteKey []byte + // foundKey := false + // err := db.View(func(tx *bolt.Tx) error { + // b := tx.Bucket([]byte("programdata")) + // c := b.Cursor() + // for k, v := c.First(); k != nil; k, v = c.Next() { + // if strings.ToLower(string(v)) == strings.ToLower(deleteName) { + // fmt.Println("FOUND " + string(v)) + // deleteKey = k + // foundKey = true + // break + // } + // } + // return nil + // }) + // if err != nil { + // panic(err) + // } + // if foundKey == true { + // fmt.Println(len([]string{})) + // fmt.Println(deleteKey) + // db.View(func(tx *bolt.Tx) error { + // b := tx.Bucket([]byte("programdata")) + // err := b.Delete(deleteKey) + // return err + // }) + // } + + // return OKAY c.JSON(200, gin.H{ "message": "Done.", }) diff --git a/utils.go b/utils.go index bbcbfab..7ec001d 100644 --- a/utils.go +++ b/utils.go @@ -10,7 +10,6 @@ import ( "strings" "time" - "github.com/boltdb/bolt" "github.com/sergi/go-diff/diffmatchpatch" ) @@ -44,25 +43,26 @@ func randomAdjective() string { func randomAlliterateCombo() (combo string) { combo = "" - // first determine which names are taken from program data - takenNames := []string{} - err := db.View(func(tx *bolt.Tx) error { - // Assume bucket exists and has keys - b := tx.Bucket([]byte("programdata")) - c := b.Cursor() - for k, v := c.First(); k != nil; k, v = c.Next() { - takenNames = append(takenNames, strings.ToLower(string(v))) - } - return nil - }) - if err != nil { - panic(err) - } + // // first determine which names are taken from program data + // takenNames := []string{} + // err := db.View(func(tx *bolt.Tx) error { + // // Assume bucket exists and has keys + // b := tx.Bucket([]byte("programdata")) + // c := b.Cursor() + // for k, v := c.First(); k != nil; k, v = c.Next() { + // takenNames = append(takenNames, strings.ToLower(string(v))) + // } + // return nil + // }) + // if err != nil { + // panic(err) + // } + // fmt.Println(takenNames) // generate random alliteration thats not been used for { animal := randomAnimal() adjective := randomAdjective() - if animal[0] == adjective[0] && stringInSlice(strings.ToLower(adjective+animal), takenNames) == false { + if animal[0] == adjective[0] { //&& stringInSlice(strings.ToLower(adjective+animal), takenNames) == false { combo = adjective + animal break }