go fmt
This commit is contained in:
parent
b96215b7ff
commit
11d24f2f20
4 changed files with 15 additions and 16 deletions
18
admin.go
18
admin.go
|
@ -18,7 +18,7 @@ func deleteHandler(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
var titles []string
|
||||
var isNew bool
|
||||
ids:= strings.Split(r.URL.Path[len("/delete/"):], "/")
|
||||
ids := strings.Split(r.URL.Path[len("/delete/"):], "/")
|
||||
for _, idStr := range ids {
|
||||
if idStr == "" {
|
||||
continue
|
||||
|
@ -40,12 +40,12 @@ func deleteHandler(w http.ResponseWriter, r *http.Request) {
|
|||
os.RemoveAll(book.Path)
|
||||
db.RemoveBook(id)
|
||||
|
||||
if ! book.Active {
|
||||
if !book.Active {
|
||||
isNew = true
|
||||
}
|
||||
titles = append(titles, book.Title)
|
||||
}
|
||||
sess.Notify("Removed books!", "The books "+ strings.Join(titles, ", ") +" are completly removed", "success")
|
||||
sess.Notify("Removed books!", "The books "+strings.Join(titles, ", ")+" are completly removed", "success")
|
||||
sess.Save(w, r)
|
||||
if isNew {
|
||||
http.Redirect(w, r, "/new/", 307)
|
||||
|
@ -127,9 +127,9 @@ func saveHandler(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
type newBook struct {
|
||||
TitleFound int
|
||||
TitleFound int
|
||||
AuthorFound int
|
||||
B Book
|
||||
B Book
|
||||
}
|
||||
type newData struct {
|
||||
S Status
|
||||
|
@ -156,8 +156,8 @@ func newHandler(w http.ResponseWriter, r *http.Request) {
|
|||
data.Books = make([]newBook, num)
|
||||
for i, b := range res {
|
||||
data.Books[i].B = b
|
||||
_, data.Books[i].TitleFound, _ = db.GetBooks(buildQuery("title:" + b.Title), 1)
|
||||
_, data.Books[i].AuthorFound, _ = db.GetBooks(buildQuery("author:" + strings.Join(b.Author, " author:")), 1)
|
||||
_, data.Books[i].TitleFound, _ = db.GetBooks(buildQuery("title:"+b.Title), 1)
|
||||
_, data.Books[i].AuthorFound, _ = db.GetBooks(buildQuery("author:"+strings.Join(b.Author, " author:")), 1)
|
||||
}
|
||||
loadTemplate(w, "new", data)
|
||||
}
|
||||
|
@ -197,7 +197,7 @@ func storeHandler(w http.ResponseWriter, r *http.Request) {
|
|||
book := books[0]
|
||||
|
||||
title := book.Title
|
||||
path := ValidFileName(BOOKS_PATH + title[:1], title, ".epub")
|
||||
path := ValidFileName(BOOKS_PATH+title[:1], title, ".epub")
|
||||
|
||||
oldPath := book.Path
|
||||
os.Mkdir(BOOKS_PATH+title[:1], os.ModePerm)
|
||||
|
@ -206,7 +206,7 @@ func storeHandler(w http.ResponseWriter, r *http.Request) {
|
|||
db.UpdateBook(id, bson.M{"active": true, "path": path})
|
||||
titles = append(titles, book.Title)
|
||||
}
|
||||
sess.Notify("Store books!", "The books '"+ strings.Join(titles, ", ") +"' are stored for public download", "success")
|
||||
sess.Notify("Store books!", "The books '"+strings.Join(titles, ", ")+"' are stored for public download", "success")
|
||||
sess.Save(w, r)
|
||||
http.Redirect(w, r, "/new/", 307)
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@ import (
|
|||
|
||||
var db *DB
|
||||
|
||||
|
||||
type Book struct {
|
||||
Id string `bson:"_id"`
|
||||
Title string
|
||||
|
@ -36,8 +35,8 @@ type Book struct {
|
|||
|
||||
type DB struct {
|
||||
session *mgo.Session
|
||||
books *mgo.Collection
|
||||
user *mgo.Collection
|
||||
books *mgo.Collection
|
||||
user *mgo.Collection
|
||||
}
|
||||
|
||||
func initDB() *DB {
|
||||
|
@ -120,7 +119,7 @@ func (d *DB) GetBooks(query bson.M, r ...int) (books []Book, num int, err error)
|
|||
|
||||
/* Returns: list of books, number found and err
|
||||
*/
|
||||
func (d *DB) GetNewBooks()(books []Book, num int, err error) {
|
||||
func (d *DB) GetNewBooks() (books []Book, num int, err error) {
|
||||
var q *mgo.Query
|
||||
q = d.books.Find(bson.M{"$nor": []bson.M{{"active": true}}}).Sort("-_id")
|
||||
num, err = q.Count()
|
||||
|
|
|
@ -125,7 +125,7 @@ func readHandler(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
var data readData
|
||||
data.Book = books[0]
|
||||
if ! data.Book.Active {
|
||||
if !data.Book.Active {
|
||||
sess := GetSession(r)
|
||||
if sess.User == "" {
|
||||
http.NotFound(w, r)
|
||||
|
@ -158,7 +158,7 @@ func contentHandler(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
book := books[0]
|
||||
if ! book.Active {
|
||||
if !book.Active {
|
||||
sess := GetSession(r)
|
||||
if sess.User == "" {
|
||||
http.NotFound(w, r)
|
||||
|
|
|
@ -76,7 +76,7 @@ func storeImg(img []byte, title, extension string) (string, string) {
|
|||
resize := append(strings.Split(RESIZE_CMD, " "), imgPath, imgPath)
|
||||
cmd := exec.Command(resize[0], resize[1:]...)
|
||||
cmd.Run()
|
||||
imgPathSmall := ValidFileName(folder, title, "_small" + extension)
|
||||
imgPathSmall := ValidFileName(folder, title, "_small"+extension)
|
||||
resize = append(strings.Split(RESIZE_THUMB_CMD, " "), imgPath, imgPathSmall)
|
||||
cmd = exec.Command(resize[0], resize[1:]...)
|
||||
cmd.Run()
|
||||
|
|
Reference in a new issue