Clean up the code

This commit is contained in:
Las Zenow 2012-10-24 22:36:20 +02:00
parent 68e999777a
commit d87351d946

View file

@ -8,6 +8,7 @@ import (
"regexp" "regexp"
"strconv" "strconv"
"strings" "strings"
"log"
) )
func storePath(name string) string { func storePath(name string) string {
@ -25,6 +26,7 @@ func storeFiles(r *http.Request) ([]string, error) {
filesForm := r.MultipartForm.File["epub"] filesForm := r.MultipartForm.File["epub"]
paths := make([]string, 0, len(filesForm)) paths := make([]string, 0, len(filesForm))
for _, f := range filesForm { for _, f := range filesForm {
log.Println("File uploaded:", f.Filename)
file, err := f.Open() file, err := f.Open()
if err != nil { if err != nil {
return paths, err return paths, err
@ -85,21 +87,11 @@ func storeImg(img []byte, title, extension string) (string, string) {
func getCover(e *epub.Epub, title string) (string, string) { func getCover(e *epub.Epub, title string) (string, string) {
/* Try first common names */ /* Try first common names */
img := e.Data("cover.jpg") for _, p := range []string{"cover.jpg", "Images/cover.jpg", "cover.jpeg", "cover1.jpg", "cover1.jpeg"} {
if len(img) != 0 { img := e.Data(p)
return storeImg(img, title, ".jpg") if len(img) != 0 {
} return storeImg(img, title, ".jpg")
img = e.Data("cover.jpeg") }
if len(img) != 0 {
return storeImg(img, title, ".jpg")
}
img = e.Data("cover1.jpg")
if len(img) != 0 {
return storeImg(img, title, ".jpg")
}
img = e.Data("cover1.jpeg")
if len(img) != 0 {
return storeImg(img, title, ".jpg")
} }
/* search for img on the text */ /* search for img on the text */