X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Flibrary%2FWebLibrary.java;h=040acd07f1505acb49845d4ad153a3661dbae8b6;hb=089e354e5efc0de39caa4df2f3987d573b71dcbc;hp=8c71ff590b41b85bba46e715b0ea8328af383592;hpb=a4efa44c8575c641a32878b177c035b5555d57ea;p=nikiroo-utils.git diff --git a/src/be/nikiroo/fanfix/library/WebLibrary.java b/src/be/nikiroo/fanfix/library/WebLibrary.java index 8c71ff5..040acd0 100644 --- a/src/be/nikiroo/fanfix/library/WebLibrary.java +++ b/src/be/nikiroo/fanfix/library/WebLibrary.java @@ -110,7 +110,7 @@ public class WebLibrary extends BasicLibrary { public Version getVersion() { try { - InputStream in = download(WebLibraryUrls.VERSION_URL); + InputStream in = post(WebLibraryUrls.VERSION_URL); try { return new Version(IOUtils.readSmallStream(in)); } finally { @@ -125,10 +125,10 @@ public class WebLibrary extends BasicLibrary { @Override public Status getStatus() { try { - download(WebLibraryUrls.INDEX_URL).close(); + post(WebLibraryUrls.INDEX_URL).close(); } catch (IOException e) { try { - download(WebLibraryUrls.VERSION_URL).close(); + post("/style.css").close(); return Status.UNAUTHORIZED; } catch (IOException ioe) { return Status.UNAVAILABLE; @@ -146,7 +146,7 @@ public class WebLibrary extends BasicLibrary { @Override public Image getCover(String luid) throws IOException { - InputStream in = download(WebLibraryUrls.getStoryUrlCover(luid)); + InputStream in = post(WebLibraryUrls.getStoryUrlCover(luid)); try { return new Image(in); } finally { @@ -155,27 +155,37 @@ public class WebLibrary extends BasicLibrary { } @Override - public Image getCustomSourceCover(final String source) throws IOException { - // TODO maybe global system in BasicLib ? - return null; + public Image getCustomSourceCover(String source) throws IOException { + InputStream in = post(WebLibraryUrls.getCoverUrlSource(source)); + try { + return new Image(in); + } finally { + in.close(); + } } @Override - public Image getCustomAuthorCover(final String author) throws IOException { - // TODO maybe global system in BasicLib ? - return null; + public Image getCustomAuthorCover(String author) throws IOException { + InputStream in = post(WebLibraryUrls.getCoverUrlAuthor(author)); + try { + return new Image(in); + } finally { + in.close(); + } } @Override public void setSourceCover(String source, String luid) throws IOException { - // TODO Auto-generated method stub - throw new IOException("Not implemented yet"); + Map post = new HashMap(); + post.put("luid", luid); + post(WebLibraryUrls.getCoverUrlSource(source), post).close(); } @Override public void setAuthorCover(String author, String luid) throws IOException { - // TODO Auto-generated method stub - throw new IOException("Not implemented yet"); + Map post = new HashMap(); + post.put("luid", luid); + post(WebLibraryUrls.getCoverUrlAuthor(author), post).close(); } @Override @@ -185,7 +195,7 @@ public class WebLibrary extends BasicLibrary { // TODO: pg Story story; - InputStream in = download(WebLibraryUrls.getStoryUrlJson(luid)); + InputStream in = post(WebLibraryUrls.getStoryUrlJson(luid)); try { JSONObject json = new JSONObject(IOUtils.readSmallStream(in)); story = JsonIO.toStory(json); @@ -199,7 +209,7 @@ public class WebLibrary extends BasicLibrary { int number = 1; for (Paragraph para : chap) { if (para.getType() == ParagraphType.IMAGE) { - InputStream subin = download( + InputStream subin = post( WebLibraryUrls.getStoryUrl(luid, chapNum, number)); try { para.setContentImage(new Image(subin)); @@ -220,7 +230,7 @@ public class WebLibrary extends BasicLibrary { @Override protected List getMetas(Progress pg) throws IOException { List metas = new ArrayList(); - InputStream in = download(WebLibraryUrls.LIST_URL_METADATA); + InputStream in = post(WebLibraryUrls.LIST_URL_METADATA); JSONArray jsonArr = new JSONArray(IOUtils.readSmallStream(in)); for (int i = 0; i < jsonArr.length(); i++) { JSONObject json = jsonArr.getJSONObject(i); @@ -253,8 +263,24 @@ public class WebLibrary extends BasicLibrary { protected synchronized void changeSTA(final String luid, final String newSource, final String newTitle, final String newAuthor, Progress pg) throws IOException { - // TODO - super.changeSTA(luid, newSource, newTitle, newAuthor, pg); + MetaData meta = getInfo(luid); + if (meta != null) { + if (!meta.getSource().equals(newSource)) { + Map post = new HashMap(); + post.put("value", newSource); + post(WebLibraryUrls.getStoryUrlSource(luid), post).close(); + } + if (!meta.getTitle().equals(newTitle)) { + Map post = new HashMap(); + post.put("value", newTitle); + post(WebLibraryUrls.getStoryUrlTitle(luid), post).close(); + } + if (!meta.getAuthor().equals(newAuthor)) { + Map post = new HashMap(); + post.put("value", newAuthor); + post(WebLibraryUrls.getStoryUrlAuthor(luid), post).close(); + } + } } @Override @@ -293,10 +319,18 @@ public class WebLibrary extends BasicLibrary { } // starts with "/", never NULL - private InputStream download(String path) throws IOException { + private InputStream post(String path) throws IOException { + return post(path, null); + } + + // starts with "/", never NULL + private InputStream post(String path, Map post) + throws IOException { URL url = new URL(host + ":" + port + path); - Map post = new HashMap(); + if (post == null) { + post = new HashMap(); + } post.put("login", subkey); post.put("password", key);