mirror of
https://github.com/schollz/cowyo.git
synced 2023-08-10 21:13:00 +03:00
Keeping random for now...not gauranteeing *no* collisions yet...
This commit is contained in:
parent
b1c4ac2869
commit
0228d53929
24
db.go
24
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
|
||||
}
|
||||
|
||||
|
31
routes.go
31
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.",
|
||||
})
|
||||
|
32
utils.go
32
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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user