From 7d5ca83a36abb95a6b185320c1e2b2fd4b296b4a Mon Sep 17 00:00:00 2001 From: Las Zenow Date: Wed, 15 Aug 2012 17:12:15 +0200 Subject: [PATCH] Improve the url parsing --- upload/upload.go | 61 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 47 insertions(+), 14 deletions(-) diff --git a/upload/upload.go b/upload/upload.go index c2dcb39..d1a4584 100644 --- a/upload/upload.go +++ b/upload/upload.go @@ -21,7 +21,36 @@ const ( RESIZE_THUMB = "/usr/bin/convert -resize 60 -quality 60 " ) +func resize(folder, name, extension string) (string, string) { + imgPath := folder + name + extension + resize := append(strings.Split(RESIZE, " "), imgPath, imgPath) + cmd := exec.Command(resize[0], resize[1:]...) + cmd.Run() + imgPathSmall := folder + name + "_small" + extension + resize = append(strings.Split(RESIZE_THUMB, " "), imgPath, imgPathSmall) + cmd = exec.Command(resize[0], resize[1:]...) + cmd.Run() + return "/" + imgPath, "/" + imgPathSmall +} + func getCover(e *epub.Epub, path string) (string, string) { + folder := COVER_PATH + path[:1] + "/" + os.Mkdir(folder, os.ModePerm) + + /* Try first common names */ + imgPath := folder + path + ".jpg" + file, _ := os.Create(imgPath) + defer file.Close() + n, _ := file.Write(e.Data("cover.jpg")) + if n != 0 { + return resize(folder, path, ".jpg") + } + n, _ = file.Write(e.Data("cover.jpeg")) + if n != 0 { + return resize(folder, path, ".jpg") + } + defer os.Remove(imgPath) + exp, _ := regexp.Compile("