From: Niki Roo Date: Sat, 2 Dec 2017 19:25:21 +0000 (+0100) Subject: Update nikiroo-utils, Remote: X-Git-Tag: fanfix-1.6.3~4 X-Git-Url: https://git.nikiroo.be/?a=commitdiff_plain;h=edf79e5e06e8dc177cc13b9bad5bf848e6f9741d;p=fanfix.git Update nikiroo-utils, Remote: - nikiroo-utils fix for serialisation of objects within custom objects - remote change source now works on server (not client + delete + re-upload) - remote import now works on server (not client + delete + re-upload) --- diff --git a/changelog.md b/changelog.md index d820412..5b725d1 100644 --- a/changelog.md +++ b/changelog.md @@ -3,7 +3,10 @@ # Version WIP - Bug fixes -- Remote server/client improvements (progress report, can send large files, detect server state) +- Remote server/client improvement: progress report +- Remote server/client improvement: can send large files +- Remote server/client improvement: detect server state +- Remote server/client improvement: import and change source on server - Better support for some CBZ files (if SUMMARY or URL files are present in it) - Fix cover images not deleted on story delete - Fix some images not supported because not jpeg-able (now try again in png) diff --git a/libs/nikiroo-utils-3.1.5-sources.jar b/libs/nikiroo-utils-3.1.6-sources.jar similarity index 87% rename from libs/nikiroo-utils-3.1.5-sources.jar rename to libs/nikiroo-utils-3.1.6-sources.jar index 38d88a6..5f2dbae 100644 Binary files a/libs/nikiroo-utils-3.1.5-sources.jar and b/libs/nikiroo-utils-3.1.6-sources.jar differ diff --git a/src/be/nikiroo/fanfix/Main.java b/src/be/nikiroo/fanfix/Main.java index f18e03c..0da6bba 100644 --- a/src/be/nikiroo/fanfix/Main.java +++ b/src/be/nikiroo/fanfix/Main.java @@ -333,7 +333,7 @@ public class Main { try { ServerObject server = new RemoteLibraryServer(key, port); server.setTraceHandler(Instance.getTraceHandler()); - server.start(); + server.run(); } catch (IOException e) { Instance.getTraceHandler().error(e); } diff --git a/src/be/nikiroo/fanfix/library/CacheLibrary.java b/src/be/nikiroo/fanfix/library/CacheLibrary.java index 28f5682..14113e4 100644 --- a/src/be/nikiroo/fanfix/library/CacheLibrary.java +++ b/src/be/nikiroo/fanfix/library/CacheLibrary.java @@ -3,6 +3,7 @@ package be.nikiroo.fanfix.library; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; +import java.net.URL; import java.util.List; import be.nikiroo.fanfix.Instance; @@ -101,6 +102,7 @@ public class CacheLibrary extends BasicLibrary { @Override public BufferedImage getCover(final String luid) { + // TODO: cache doesn't seem to work if (isCached(luid)) { return cacheLib.getCover(luid); } @@ -211,6 +213,25 @@ public class CacheLibrary extends BasicLibrary { } } + @Override + public Story imprt(URL url, Progress pg) throws IOException { + if (pg == null) { + pg = new Progress(); + } + + Progress pgImprt = new Progress(); + Progress pgCache = new Progress(); + pg.setMinMax(0, 10); + pg.addProgress(pgImprt, 7); + pg.addProgress(pgCache, 3); + + Story story = lib.imprt(url, pgImprt); + cacheLib.save(story, story.getMeta().getLuid(), pgCache); + + pg.done(); + return story; + } + // All the following methods are only used by Save and Delete in // BasicLibrary: diff --git a/src/be/nikiroo/fanfix/library/RemoteLibrary.java b/src/be/nikiroo/fanfix/library/RemoteLibrary.java index f310413..7b52fe3 100644 --- a/src/be/nikiroo/fanfix/library/RemoteLibrary.java +++ b/src/be/nikiroo/fanfix/library/RemoteLibrary.java @@ -3,6 +3,7 @@ package be.nikiroo.fanfix.library; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; +import java.net.URL; import java.net.UnknownHostException; import java.util.ArrayList; import java.util.List; @@ -220,8 +221,7 @@ public class RemoteLibrary extends BasicLibrary { pg.add(1); } - send(null); // done sending the story - luidSaved[0] = (String) send(null); // get LUID + luidSaved[0] = (String) send(null); pg.done(); } @@ -235,7 +235,10 @@ public class RemoteLibrary extends BasicLibrary { // because the meta changed: clearCache(); refresh(pgRefresh); - story.setMeta(getInfo(luidSaved[0])); + + MetaData meta = getInfo(luidSaved[0]); + meta.setCover(story.getMeta().getCover()); + story.setMeta(meta); pg.done(); @@ -276,6 +279,96 @@ public class RemoteLibrary extends BasicLibrary { } } + @Override + // Could work (more slowly) without it + public Story imprt(final URL url, Progress pg) throws IOException { + if (pg == null) { + pg = new Progress(); + } + + pg.setMinMax(0, 2); + Progress pgImprt = new Progress(); + Progress pgGet = new Progress(); + pg.addProgress(pgImprt, 1); + pg.addProgress(pgGet, 1); + + final Progress pgF = pgImprt; + final String[] luid = new String[1]; + + try { + new ConnectActionClientObject(host, port, true) { + @Override + public void action(Version serverVersion) throws Exception { + Progress pg = pgF; + + Object rep = send(new Object[] { md5, "IMPORT", + url.toString() }); + + while (true) { + if (!RemoteLibraryServer.updateProgress(pg, rep)) { + break; + } + + rep = send(null); + } + + pg.done(); + luid[0] = (String) rep; + } + + @Override + protected void onError(Exception e) { + Instance.getTraceHandler().error(e); + } + }.connect(); + } catch (IOException e) { + Instance.getTraceHandler().error(e); + } + + if (luid[0] == null) { + throw new IOException("Remote failure"); + } + + Story story = getStory(luid[0], pgGet); + pgGet.done(); + + pg.done(); + return story; + } + + @Override + // Could work (more slowly) without it + public synchronized void changeSource(final String luid, + final String newSource, Progress pg) throws IOException { + final Progress pgF = pg == null ? new Progress() : pg; + + try { + new ConnectActionClientObject(host, port, true) { + @Override + public void action(Version serverVersion) throws Exception { + Progress pg = pgF; + + Object rep = send(new Object[] { md5, "CHANGE_SOURCE", + luid, newSource }); + while (true) { + if (!RemoteLibraryServer.updateProgress(pg, rep)) { + break; + } + + rep = send(null); + } + } + + @Override + protected void onError(Exception e) { + Instance.getTraceHandler().error(e); + } + }.connect(); + } catch (IOException e) { + Instance.getTraceHandler().error(e); + } + } + @Override public synchronized File getFile(final String luid, Progress pg) { throw new java.lang.InternalError( diff --git a/src/be/nikiroo/fanfix/library/RemoteLibraryServer.java b/src/be/nikiroo/fanfix/library/RemoteLibraryServer.java index c93f0f3..adef7ed 100644 --- a/src/be/nikiroo/fanfix/library/RemoteLibraryServer.java +++ b/src/be/nikiroo/fanfix/library/RemoteLibraryServer.java @@ -1,6 +1,7 @@ package be.nikiroo.fanfix.library; import java.io.IOException; +import java.net.URL; import java.security.InvalidParameterException; import java.util.ArrayList; import java.util.List; @@ -33,11 +34,15 @@ import be.nikiroo.utils.serial.server.ServerObject; * if not) *
  • [md5] SAVE_STORY [luid]: save the story (that must be sent just after the * command) with the given LUID, then return the LUID
  • + *
  • [md5] IMPORT [url]: save the story found at the given URL, then return + * the LUID
  • *
  • [md5] DELETE_STORY [luid]: delete the story of LUID luid
  • *
  • [md5] GET_COVER [luid]: return the cover of the story
  • *
  • [md5] GET_SOURCE_COVER [source]: return the cover for this source
  • *
  • [md5] SET_SOURCE_COVER [source], [luid]: set the default cover for the * given source to the cover of the story denoted by luid
  • + *
  • [md5] CHANGE_SOURCE [luid] [new source]: change the source of the story + * of LUID luid
  • *
  • [md5] EXIT: stop the server
  • * * @@ -74,13 +79,13 @@ public class RemoteLibraryServer extends ServerObject { if (data instanceof Object[]) { Object[] dataArray = (Object[]) data; if (dataArray.length >= 2) { + md5 = "" + dataArray[0]; + command = "" + dataArray[1]; + args = new Object[dataArray.length - 2]; for (int i = 2; i < dataArray.length; i++) { args[i - 2] = dataArray[i]; } - - md5 = "" + dataArray[0]; - command = "" + dataArray[1]; } } @@ -133,6 +138,10 @@ public class RemoteLibraryServer extends ServerObject { Story story = rebuildStory(list); Instance.getLibrary().save(story, (String) args[0], null); return story.getMeta().getLuid(); + } else if ("IMPORT".equals(command)) { + Story story = Instance.getLibrary().imprt( + new URL((String) args[0]), createPgForwarder(action)); + return story.getMeta().getLuid(); } else if ("DELETE_STORY".equals(command)) { Instance.getLibrary().delete((String) args[0]); } else if ("GET_COVER".equals(command)) { @@ -142,6 +151,9 @@ public class RemoteLibraryServer extends ServerObject { } else if ("SET_SOURCE_COVER".equals(command)) { Instance.getLibrary().setSourceCover((String) args[0], (String) args[1]); + } else if ("CHANGE_SOURCE".equals(command)) { + Instance.getLibrary().changeSource((String) args[0], + (String) args[1], createPgForwarder(action)); } else if ("EXIT".equals(command)) { stop(0, false); }