This commit is contained in:
Las Zenow 2012-09-14 00:34:13 +02:00
parent b96215b7ff
commit 11d24f2f20
4 changed files with 15 additions and 16 deletions

View file

@ -18,7 +18,7 @@ func deleteHandler(w http.ResponseWriter, r *http.Request) {
var titles []string var titles []string
var isNew bool var isNew bool
ids:= strings.Split(r.URL.Path[len("/delete/"):], "/") ids := strings.Split(r.URL.Path[len("/delete/"):], "/")
for _, idStr := range ids { for _, idStr := range ids {
if idStr == "" { if idStr == "" {
continue continue
@ -40,12 +40,12 @@ func deleteHandler(w http.ResponseWriter, r *http.Request) {
os.RemoveAll(book.Path) os.RemoveAll(book.Path)
db.RemoveBook(id) db.RemoveBook(id)
if ! book.Active { if !book.Active {
isNew = true isNew = true
} }
titles = append(titles, book.Title) 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) sess.Save(w, r)
if isNew { if isNew {
http.Redirect(w, r, "/new/", 307) http.Redirect(w, r, "/new/", 307)
@ -127,9 +127,9 @@ func saveHandler(w http.ResponseWriter, r *http.Request) {
} }
type newBook struct { type newBook struct {
TitleFound int TitleFound int
AuthorFound int AuthorFound int
B Book B Book
} }
type newData struct { type newData struct {
S Status S Status
@ -156,8 +156,8 @@ func newHandler(w http.ResponseWriter, r *http.Request) {
data.Books = make([]newBook, num) data.Books = make([]newBook, num)
for i, b := range res { for i, b := range res {
data.Books[i].B = b data.Books[i].B = b
_, data.Books[i].TitleFound, _ = db.GetBooks(buildQuery("title:" + b.Title), 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) _, data.Books[i].AuthorFound, _ = db.GetBooks(buildQuery("author:"+strings.Join(b.Author, " author:")), 1)
} }
loadTemplate(w, "new", data) loadTemplate(w, "new", data)
} }
@ -197,7 +197,7 @@ func storeHandler(w http.ResponseWriter, r *http.Request) {
book := books[0] book := books[0]
title := book.Title title := book.Title
path := ValidFileName(BOOKS_PATH + title[:1], title, ".epub") path := ValidFileName(BOOKS_PATH+title[:1], title, ".epub")
oldPath := book.Path oldPath := book.Path
os.Mkdir(BOOKS_PATH+title[:1], os.ModePerm) 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}) db.UpdateBook(id, bson.M{"active": true, "path": path})
titles = append(titles, book.Title) 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) sess.Save(w, r)
http.Redirect(w, r, "/new/", 307) http.Redirect(w, r, "/new/", 307)
} }

View file

@ -9,7 +9,6 @@ import (
var db *DB var db *DB
type Book struct { type Book struct {
Id string `bson:"_id"` Id string `bson:"_id"`
Title string Title string
@ -36,8 +35,8 @@ type Book struct {
type DB struct { type DB struct {
session *mgo.Session session *mgo.Session
books *mgo.Collection books *mgo.Collection
user *mgo.Collection user *mgo.Collection
} }
func initDB() *DB { 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 /* 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 var q *mgo.Query
q = d.books.Find(bson.M{"$nor": []bson.M{{"active": true}}}).Sort("-_id") q = d.books.Find(bson.M{"$nor": []bson.M{{"active": true}}}).Sort("-_id")
num, err = q.Count() num, err = q.Count()

View file

@ -125,7 +125,7 @@ func readHandler(w http.ResponseWriter, r *http.Request) {
var data readData var data readData
data.Book = books[0] data.Book = books[0]
if ! data.Book.Active { if !data.Book.Active {
sess := GetSession(r) sess := GetSession(r)
if sess.User == "" { if sess.User == "" {
http.NotFound(w, r) http.NotFound(w, r)
@ -158,7 +158,7 @@ func contentHandler(w http.ResponseWriter, r *http.Request) {
return return
} }
book := books[0] book := books[0]
if ! book.Active { if !book.Active {
sess := GetSession(r) sess := GetSession(r)
if sess.User == "" { if sess.User == "" {
http.NotFound(w, r) http.NotFound(w, r)

View file

@ -76,7 +76,7 @@ func storeImg(img []byte, title, extension string) (string, string) {
resize := append(strings.Split(RESIZE_CMD, " "), imgPath, imgPath) resize := append(strings.Split(RESIZE_CMD, " "), imgPath, imgPath)
cmd := exec.Command(resize[0], resize[1:]...) cmd := exec.Command(resize[0], resize[1:]...)
cmd.Run() cmd.Run()
imgPathSmall := ValidFileName(folder, title, "_small" + extension) imgPathSmall := ValidFileName(folder, title, "_small"+extension)
resize = append(strings.Split(RESIZE_THUMB_CMD, " "), imgPath, imgPathSmall) resize = append(strings.Split(RESIZE_THUMB_CMD, " "), imgPath, imgPathSmall)
cmd = exec.Command(resize[0], resize[1:]...) cmd = exec.Command(resize[0], resize[1:]...)
cmd.Run() cmd.Run()