# 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)
try {
ServerObject server = new RemoteLibraryServer(key, port);
server.setTraceHandler(Instance.getTraceHandler());
- server.start();
+ server.run();
} catch (IOException e) {
Instance.getTraceHandler().error(e);
}
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;
@Override
public BufferedImage getCover(final String luid) {
+ // TODO: cache doesn't seem to work
if (isCached(luid)) {
return cacheLib.getCover(luid);
}
}
}
+ @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:
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;
pg.add(1);
}
- send(null); // done sending the story
- luidSaved[0] = (String) send(null); // get LUID
+ luidSaved[0] = (String) send(null);
pg.done();
}
// 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();
}
}
+ @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(
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;
* if not)</li>
* <li>[md5] SAVE_STORY [luid]: save the story (that must be sent just after the
* command) with the given LUID, then return the LUID</li>
+ * <li>[md5] IMPORT [url]: save the story found at the given URL, then return
+ * the LUID</li>
* <li>[md5] DELETE_STORY [luid]: delete the story of LUID luid</li>
* <li>[md5] GET_COVER [luid]: return the cover of the story</li>
* <li>[md5] GET_SOURCE_COVER [source]: return the cover for this source</li>
* <li>[md5] SET_SOURCE_COVER [source], [luid]: set the default cover for the
* given source to the cover of the story denoted by luid</li>
+ * <li>[md5] CHANGE_SOURCE [luid] [new source]: change the source of the story
+ * of LUID luid</li>
* <li>[md5] EXIT: stop the server</li>
* </ul>
*
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];
}
}
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)) {
} 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);
}