From 0228d539292ae4b817b7a661b6a142f416916fd2 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... --- 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 }