X-Git-Url: http://git.nikiroo.be/?p=fanfix.git;a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Flibrary%2FWebLibraryServer.java;fp=src%2Fbe%2Fnikiroo%2Ffanfix%2Flibrary%2FWebLibraryServer.java;h=dfbceeeb7a19ce09cdbd398fa45a36789a758811;hp=a45fdec5b793036067534a1d63b5713934b6cb4e;hb=e4b1b70c5388573bda8ae28f9391ee3831e53feb;hpb=6673ec5924d57a37c4f995f9c81c50a187b51c63 diff --git a/src/be/nikiroo/fanfix/library/WebLibraryServer.java b/src/be/nikiroo/fanfix/library/WebLibraryServer.java index a45fdec..dfbceee 100644 --- a/src/be/nikiroo/fanfix/library/WebLibraryServer.java +++ b/src/be/nikiroo/fanfix/library/WebLibraryServer.java @@ -304,30 +304,58 @@ public class WebLibraryServer extends WebLibraryServerHtml { InputStream in = null; - if ("cover".equals(type)) { + if ("story".equals(type)) { Image img = storyCover(id, login); if (img != null) { in = img.newInputStream(); } - } else if ("author".equals(type)) { - Image img = authorCover(id, login); + } else if ("source".equals(type)) { + Image img = sourceCover(id, login); if (img != null) { in = img.newInputStream(); } - } else if ("source".equals(type)) { - Image img = sourceCover(id, login); + } else if ("author".equals(type)) { + Image img = authorCover(id, login); if (img != null) { in = img.newInputStream(); } } else { return NanoHTTPD.newFixedLengthResponse(Status.BAD_REQUEST, - NanoHTTPD.MIME_PLAINTEXT, "Invalid cover type: " + type); + NanoHTTPD.MIME_PLAINTEXT, + "Invalid GET cover type: " + type); } // TODO: get correct image type return newInputStreamResponse("image/png", in); } + @Override + protected Response setCover(String uri, String luid, WLoginResult login) + throws IOException { + String[] uriParts = uri.split("/"); + int off = 2; // "" and "cover" + + if (uriParts.length < off + 2) { + return NanoHTTPD.newFixedLengthResponse(Status.BAD_REQUEST, + NanoHTTPD.MIME_PLAINTEXT, "Invalid cover request"); + } + + String type = uriParts[off + 0]; + String id = uriParts[off + 1]; + + if ("source".equals(type)) { + sourceCover(id, login, luid); + } else if ("author".equals(type)) { + authorCover(id, login, luid); + } else { + return NanoHTTPD.newFixedLengthResponse(Status.BAD_REQUEST, + NanoHTTPD.MIME_PLAINTEXT, + "Invalid SET cover type: " + type); + } + + return newInputStreamResponse(NanoHTTPD.MIME_PLAINTEXT, null); + } + @Override protected List metas(WLoginResult login) throws IOException { BasicLibrary lib = Instance.getInstance().getLibrary(); @@ -417,6 +445,18 @@ public class WebLibraryServer extends WebLibraryServerHtml { } + private void authorCover(String author, WLoginResult login, String luid) + throws IOException { + if (meta(luid, login) != null) { + List metas = new MetaResultList(metas(login)).filter(null, + author, null); + if (metas.size() > 0) { + BasicLibrary lib = Instance.getInstance().getLibrary(); + lib.setAuthorCover(author, luid); + } + } + } + private Image sourceCover(String source, WLoginResult login) throws IOException { Image img = null; @@ -433,6 +473,18 @@ public class WebLibraryServer extends WebLibraryServerHtml { return img; } + private void sourceCover(String source, WLoginResult login, String luid) + throws IOException { + if (meta(luid, login) != null) { + List metas = new MetaResultList(metas(login)) + .filter(source, null, null); + if (metas.size() > 0) { + BasicLibrary lib = Instance.getInstance().getLibrary(); + lib.setSourceCover(source, luid); + } + } + } + private boolean isAllowed(MetaData meta, WLoginResult login) { MetaResultList one = new MetaResultList(Arrays.asList(meta)); if (login.isWl() && !whitelist.isEmpty()) {