1
0
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...

Former-commit-id: 829790cd667b22fdebf335ed5eabfc2b8231d275 [formerly 56a83fa27db5527f6aecddd55d0e5a176fc90b01] [formerly e5d2c26518289f0dffedd16f4f9547e3da15a48f [formerly 9c57046a6f481c6addadc5ad3f8ccaad2ffa5ebf [formerly 0228d53929]]]
Former-commit-id: 2c2961d3fd98262b58792638e964cd4ae5a1baa3 [formerly 45e0ca872d8731bc8ecad719bd725d7bfc2af4b6]
Former-commit-id: add863c06877ae869be205ca4409c4ec5be8f467
Former-commit-id: 76fcf04f45
This commit is contained in:
Zack Scholl 2016-02-14 09:31:30 -05:00
parent 341a8c17de
commit c04b4f2a68
3 changed files with 59 additions and 28 deletions

24
db.go
View File

@ -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
}

View File

@ -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.",
})

View File

@ -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
}