do not allow empty cover images
[fanfix.git] / src / be / nikiroo / fanfix / library / WebLibrary.java
index 9d1c773aae698457d920b5094668eebb74605202..9af38e2b6bd1c7ccb565ca6f244e31ef42f40746 100644 (file)
@@ -126,6 +126,26 @@ public class WebLibrary extends BasicLibrary {
                return new Version();
        }
 
+       /**
+        * Stop the server.
+        * 
+        * @throws IOException
+        *             in case of I/O errors
+        */
+       public void stop() throws IOException {
+               try {
+                       post(WebLibraryUrls.EXIT_URL, null).close();
+               } catch (Exception e) {
+                       try {
+                               Thread.sleep(200);
+                       } catch (InterruptedException e1) {
+                       }
+                       if (getStatus() != Status.UNAVAILABLE) {
+                               throw new IOException("Cannot exit the library", e);
+                       }
+               }
+       }
+
        @Override
        public Status getStatus() {
                try {
@@ -152,7 +172,13 @@ public class WebLibrary extends BasicLibrary {
        public Image getCover(String luid) throws IOException {
                InputStream in = post(WebLibraryUrls.getStoryUrlCover(luid));
                try {
-                       return new Image(in);
+                       Image img = new Image(in);
+                       if (img.getSize() > 0) {
+                               img.close();
+                               return img;
+                       }
+
+                       return null;
                } finally {
                        in.close();
                }
@@ -162,7 +188,13 @@ public class WebLibrary extends BasicLibrary {
        public Image getCustomSourceCover(String source) throws IOException {
                InputStream in = post(WebLibraryUrls.getCoverUrlSource(source));
                try {
-                       return new Image(in);
+                       Image img = new Image(in);
+                       if (img.getSize() > 0) {
+                               img.close();
+                               return img;
+                       }
+
+                       return null;
                } finally {
                        in.close();
                }
@@ -172,7 +204,13 @@ public class WebLibrary extends BasicLibrary {
        public Image getCustomAuthorCover(String author) throws IOException {
                InputStream in = post(WebLibraryUrls.getCoverUrlAuthor(author));
                try {
-                       return new Image(in);
+                       Image img = new Image(in);
+                       if (img.getSize() > 0) {
+                               img.close();
+                               return img;
+                       }
+
+                       return null;
                } finally {
                        in.close();
                }
@@ -223,7 +261,10 @@ public class WebLibrary extends BasicLibrary {
                                        InputStream subin = post(
                                                        WebLibraryUrls.getStoryUrl(luid, chapNum, number));
                                        try {
-                                               para.setContentImage(new Image(subin));
+                                               Image img = new Image(subin);
+                                               if (img.getSize() > 0) {
+                                                       para.setContentImage(img);
+                                               }
                                        } finally {
                                                subin.close();
                                        }
@@ -291,6 +332,11 @@ public class WebLibrary extends BasicLibrary {
                                try {
                                        subPg = JsonIO.toProgress(
                                                        new JSONObject(IOUtils.readSmallStream(in)));
+                                       pg.setName(subPg.getName());
+                                       pg.setMinMax(subPg.getMin(), subPg.getMax());
+                                       pg.setProgress(subPg.getProgress());
+                               } catch (Exception e) {
+                                       subPg = null;
                                } finally {
                                        in.close();
                                }
@@ -333,6 +379,11 @@ public class WebLibrary extends BasicLibrary {
                }
        }
 
+       @Override
+       public synchronized void delete(String luid) throws IOException {
+               post(WebLibraryUrls.getDeleteUrlStory(luid), null).close();
+       }
+
        @Override
        protected void updateInfo(MetaData meta) {
                // Will be taken care of directly server side