X-Git-Url: http://git.nikiroo.be/?p=nikiroo-utils.git;a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Flibrary%2FWebLibrary.java;h=1178e40c578b3bb2f2df46b3994de2b0770cc1ed;hp=7f775830edf8c7641eeb3303abdddf3fcdb48fbd;hb=5ee0fc14dbffa8d11b914537d957ef892ba20ef9;hpb=b6aad7afb573f35c2ca2c0157e39838db87ad698 diff --git a/src/be/nikiroo/fanfix/library/WebLibrary.java b/src/be/nikiroo/fanfix/library/WebLibrary.java index 7f77583..1178e40 100644 --- a/src/be/nikiroo/fanfix/library/WebLibrary.java +++ b/src/be/nikiroo/fanfix/library/WebLibrary.java @@ -22,6 +22,7 @@ import be.nikiroo.fanfix.data.Story; import be.nikiroo.utils.IOUtils; import be.nikiroo.utils.Image; import be.nikiroo.utils.Progress; +import be.nikiroo.utils.Version; /** * This {@link BasicLibrary} will access a remote server to list the available @@ -107,16 +108,30 @@ public class WebLibrary extends BasicLibrary { this.rw = false; } + public Version getVersion() { + try { + InputStream in = download(WebLibraryUrls.VERSION_URL); + try { + return new Version(IOUtils.readSmallStream(in)); + } finally { + in.close(); + } + } catch (IOException e) { + } + + return null; + } + @Override public Status getStatus() { try { - download("/"); + download(WebLibraryUrls.INDEX_URL).close(); } catch (IOException e) { try { - download("/style.css"); + download(WebLibraryUrls.VERSION_URL).close(); return Status.UNAUTHORIZED; } catch (IOException ioe) { - return Status.INVALID; + return Status.UNAVAILABLE; } } @@ -130,12 +145,12 @@ public class WebLibrary extends BasicLibrary { @Override public Image getCover(String luid) throws IOException { - InputStream in = download("/story/" + luid + "/cover"); - if (in != null) { + InputStream in = download(WebLibraryUrls.getStoryUrlCover(luid)); + try { return new Image(in); + } finally { + in.close(); } - - return null; } @Override @@ -169,7 +184,7 @@ public class WebLibrary extends BasicLibrary { // TODO: pg Story story; - InputStream in = download("/story/" + luid + "/json"); + InputStream in = download(WebLibraryUrls.getStoryUrlJson(luid)); try { JSONObject json = new JSONObject(IOUtils.readSmallStream(in)); story = JsonIO.toStory(json); @@ -184,7 +199,7 @@ public class WebLibrary extends BasicLibrary { for (Paragraph para : chap) { if (para.getType() == ParagraphType.IMAGE) { InputStream subin = download( - "/story/" + luid + "/" + chapNum + "/" + number); + WebLibraryUrls.getStoryUrl(luid, chapNum, number)); try { para.setContentImage(new Image(subin)); } finally { @@ -204,7 +219,7 @@ public class WebLibrary extends BasicLibrary { @Override protected List getMetas(Progress pg) throws IOException { List metas = new ArrayList(); - InputStream in = download("/list/luids"); + InputStream in = download(WebLibraryUrls.LIST_URL_METADATA); JSONArray jsonArr = new JSONArray(IOUtils.readSmallStream(in)); for (int i = 0; i < jsonArr.length(); i++) { JSONObject json = jsonArr.getJSONObject(i); @@ -276,7 +291,7 @@ public class WebLibrary extends BasicLibrary { "Operation not supportorted on remote Libraries"); } - // starts with "/" + // starts with "/", never NULL private InputStream download(String path) throws IOException { URL url = new URL(host + ":" + port + path);