Helper functions for the migration scripts
This commit is contained in:
parent
fd0b9cf53d
commit
b62b303995
2 changed files with 7 additions and 3 deletions
|
@ -36,11 +36,15 @@ func (db *pgDB) AddUser(name string, pass string) error {
|
||||||
log.Error("Error hashing password: ", err)
|
log.Error("Error hashing password: ", err)
|
||||||
return errors.New("An error happen storing the password")
|
return errors.New("An error happen storing the password")
|
||||||
}
|
}
|
||||||
|
return db.AddRawUser(name, hpass, salt, "")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (db *DB) AddRawUser(name string, hpass []byte, salt []byte, role string) error {
|
||||||
u := user{
|
u := user{
|
||||||
Username: name,
|
Username: name,
|
||||||
Password: hpass,
|
Password: hpass,
|
||||||
Salt: salt,
|
Salt: salt,
|
||||||
Role: "",
|
Role: role,
|
||||||
}
|
}
|
||||||
return db.sql.Create(&u)
|
return db.sql.Create(&u)
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ func EpubMetadata(epub *epubgo.Epub) database.Book {
|
||||||
case "description":
|
case "description":
|
||||||
book.Description = parseDescription(data)
|
book.Description = parseDescription(data)
|
||||||
case "subject":
|
case "subject":
|
||||||
book.Tags = parseSubject(data)
|
book.Tags = ParseSubject(data)
|
||||||
case "date":
|
case "date":
|
||||||
book.Date = parseDate(data)
|
book.Date = parseDate(data)
|
||||||
case "language":
|
case "language":
|
||||||
|
@ -88,7 +88,7 @@ func parseDescription(description []string) string {
|
||||||
return str
|
return str
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseSubject(subject []string) []string {
|
func ParseSubject(subject []string) []string {
|
||||||
parsed := subject
|
parsed := subject
|
||||||
for _, sep := range []string{"/", ","} {
|
for _, sep := range []string{"/", ","} {
|
||||||
p2 := []string{}
|
p2 := []string{}
|
||||||
|
|
Reference in a new issue