diff --git a/admin.go b/admin.go index c7be41f..65b4a82 100644 --- a/admin.go +++ b/admin.go @@ -166,7 +166,7 @@ func newHandler(w http.ResponseWriter, r *http.Request) { } if len(r.URL.Path) > len("/new/") { - http.ServeFile(w, r, r.URL.Path[1:]) + http.ServeFile(w, r, NEW_PATH + r.URL.Path[len("/new/"):]) return } diff --git a/reader.go b/reader.go index ebf8acf..f6ca746 100644 --- a/reader.go +++ b/reader.go @@ -125,6 +125,7 @@ func readHandler(w http.ResponseWriter, r *http.Request) { var data readData data.Book = books[0] + var bookPath string if !data.Book.Active { sess := GetSession(r) if sess.User == "" { @@ -132,10 +133,12 @@ func readHandler(w http.ResponseWriter, r *http.Request) { return } data.Back = "/new/" + bookPath = NEW_PATH + data.Book.Path } else { data.Back = "/book/" + id + bookPath = BOOKS_PATH + data.Book.Path } - e, _ := epub.Open(data.Book.Path, 0) + e, _ := epub.Open(bookPath, 0) defer e.Close() if file == "" { it := e.Iterator(epub.EITERATOR_LINEAR) @@ -158,14 +161,18 @@ func contentHandler(w http.ResponseWriter, r *http.Request) { return } book := books[0] + var bookPath string if !book.Active { sess := GetSession(r) if sess.User == "" { http.NotFound(w, r) return } + bookPath = NEW_PATH + book.Path + } else { + bookPath = BOOKS_PATH + book.Path } - e, _ := epub.Open(book.Path, 0) + e, _ := epub.Open(bookPath, 0) defer e.Close() if file == "" { http.NotFound(w, r) diff --git a/store.go b/store.go index d2aa250..8f0ec44 100644 --- a/store.go +++ b/store.go @@ -13,7 +13,7 @@ import ( func ParseFile(path string) (string, error) { book := map[string]interface{}{} - e, err := epub.Open(path, 0) + e, err := epub.Open(NEW_PATH + path, 0) if err != nil { return "", err } @@ -47,7 +47,7 @@ func ParseFile(path string) (string, error) { func StoreNewFile(name string, file io.Reader) (string, error) { path := storePath(name) - fw, err := os.Create(path) + fw, err := os.Create(NEW_PATH + path) if err != nil { return "", err } @@ -65,14 +65,14 @@ func StoreNewFile(name string, file io.Reader) (string, error) { func StoreBook(book Book) (path string, err error) { title := book.Title - path = validFileName(BOOKS_PATH+title[:1], title, ".epub") + path = validFileName(BOOKS_PATH, title, ".epub") - oldPath := book.Path + oldPath := NEW_PATH+book.Path err = os.Mkdir(BOOKS_PATH+title[:1], os.ModePerm) if err != nil { return } - cmd := exec.Command("mv", oldPath, path) + cmd := exec.Command("mv", oldPath, BOOKS_PATH+path) err = cmd.Run() return } @@ -91,21 +91,21 @@ func validFileName(path string, title string, extension string) string { title = strings.Replace(title, "/", "_", -1) title = strings.Replace(title, "?", "_", -1) title = strings.Replace(title, "#", "_", -1) - file := path + "/" + title + extension - _, err := os.Stat(file) + file := title[:1] + "/" + title + extension + _, err := os.Stat(path + file) for i := 0; err == nil; i++ { - file = path + "/" + title + "_" + strconv.Itoa(i) + extension - _, err = os.Stat(file) + file = title[:1] + "/" + title + "_" + strconv.Itoa(i) + extension + _, err = os.Stat(path + file) } return file } func storePath(name string) string { - path := NEW_PATH + name - _, err := os.Stat(path) + path := name + _, err := os.Stat(NEW_PATH + path) for i := 0; err == nil; i++ { - path = NEW_PATH + strconv.Itoa(i) + "_" + name - _, err = os.Stat(path) + path = strconv.Itoa(i) + "_" + name + _, err = os.Stat(NEW_PATH + path) } return path } @@ -120,12 +120,11 @@ func cleanStr(str string) string { } func storeImg(img []byte, title, extension string) (string, string) { - folder := COVER_PATH + title[:1] - os.Mkdir(folder, os.ModePerm) - imgPath := validFileName(folder, title, extension) + os.Mkdir(COVER_PATH + title[:1], os.ModePerm) + imgPath := validFileName(COVER_PATH, title, extension) /* store img on disk */ - file, err := os.Create(imgPath) + file, err := os.Create(COVER_PATH + imgPath) if err != nil { return "", "" } @@ -133,14 +132,14 @@ func storeImg(img []byte, title, extension string) (string, string) { file.Write(img) /* resize img */ - resize := append(strings.Split(RESIZE_CMD, " "), imgPath, imgPath) + resize := append(strings.Split(RESIZE_CMD, " "), COVER_PATH + imgPath, COVER_PATH + imgPath) cmd := exec.Command(resize[0], resize[1:]...) cmd.Run() - imgPathSmall := validFileName(folder, title, "_small"+extension) - resize = append(strings.Split(RESIZE_THUMB_CMD, " "), imgPath, imgPathSmall) + imgPathSmall := validFileName(COVER_PATH, title, "_small"+extension) + resize = append(strings.Split(RESIZE_THUMB_CMD, " "), COVER_PATH + imgPath, COVER_PATH + imgPathSmall) cmd = exec.Command(resize[0], resize[1:]...) cmd.Run() - return "/" + imgPath, "/" + imgPathSmall + return imgPath, imgPathSmall } func getCover(e *epub.Epub, title string) (string, string) { diff --git a/templates/book.html b/templates/book.html index 6c557ab..c1eadcc 100644 --- a/templates/book.html +++ b/templates/book.html @@ -25,7 +25,7 @@ function delBook(){
{{if .Cover}}
- {{.Title}} + {{.Title}}
{{end}} @@ -53,7 +53,7 @@ function delBook(){ {{end}}
diff --git a/templates/edit.html b/templates/edit.html index c866425..fbad606 100644 --- a/templates/edit.html +++ b/templates/edit.html @@ -4,7 +4,7 @@
{{if .Cover}}
- {{.Title}} + {{.Title}}
{{end}} diff --git a/templates/index.html b/templates/index.html index 5ebf96c..cea350c 100644 --- a/templates/index.html +++ b/templates/index.html @@ -15,7 +15,7 @@
  • @@ -35,7 +35,7 @@
  • @@ -55,7 +55,7 @@
  • diff --git a/templates/new.html b/templates/new.html index e2714d8..f9def41 100644 --- a/templates/new.html +++ b/templates/new.html @@ -14,7 +14,7 @@ {{with .B}}
    -

    {{if .CoverSmall}}{{.Title}}{{end}}

    +

    {{if .CoverSmall}}{{.Title}}{{end}}

    {{.Title}} ({{$titleFound}})
    @@ -34,7 +34,7 @@

    diff --git a/templates/search.html b/templates/search.html index 29fceaa..cf905fe 100644 --- a/templates/search.html +++ b/templates/search.html @@ -19,7 +19,7 @@ {{range .}}
    @@ -33,7 +33,7 @@
    diff --git a/upload.go b/upload.go index ca789eb..1adcf90 100644 --- a/upload.go +++ b/upload.go @@ -43,7 +43,7 @@ func uploadHandler(w http.ResponseWriter, r *http.Request) { for _, path := range paths { title, err := ParseFile(path) if err != nil { - os.Remove(path) + os.Remove(NEW_PATH + path) sess.Notify("Problem uploading!", "The file '"+path[len("new/"):]+"' is not a well formed epub", "error") } else { uploaded = uploaded + " '" + title + "'"