public Image getCover(String luid) throws IOException {
InputStream in = post(WebLibraryUrls.getStoryUrlCover(luid));
try {
- return new Image(in);
+ Image img = new Image(in);
+ if (img.getSize() > 0) {
+ return img;
+ }
+
+ return null;
} finally {
in.close();
}
public Image getCustomSourceCover(String source) throws IOException {
InputStream in = post(WebLibraryUrls.getCoverUrlSource(source));
try {
- return new Image(in);
+ Image img = new Image(in);
+ if (img.getSize() > 0) {
+ return img;
+ }
+
+ return null;
} finally {
in.close();
}
public Image getCustomAuthorCover(String author) throws IOException {
InputStream in = post(WebLibraryUrls.getCoverUrlAuthor(author));
try {
- return new Image(in);
+ Image img = new Image(in);
+ if (img.getSize() > 0) {
+ return img;
+ }
+
+ return null;
} finally {
in.close();
}
InputStream subin = post(
WebLibraryUrls.getStoryUrl(luid, chapNum, number));
try {
- para.setContentImage(new Image(subin));
+ Image img = new Image(subin);
+ if (img.getSize() > 0) {
+ para.setContentImage(img);
+ }
} finally {
subin.close();
}
try {
subPg = JsonIO.toProgress(
new JSONObject(IOUtils.readSmallStream(in)));
+ } catch (Exception e) {
+ subPg = null;
} finally {
in.close();
}
public class WebLibraryServer extends WebLibraryServerHtml {
class WLoginResult extends LoginResult {
- private boolean rw;
- private boolean wl;
- private boolean bl;
-
public WLoginResult(boolean badLogin, boolean badCookie) {
super(badLogin, badCookie);
}
boolean wl, boolean bl) {
super(who, key, subkey, (rw ? "|rw" : "") + (wl ? "|wl" : "")
+ (bl ? "|bl" : "") + "|");
- this.rw = rw;
- this.wl = wl;
- this.bl = bl;
}
public WLoginResult(String cookie, String who, String key,
NanoHTTPD.MIME_PLAINTEXT, "Invalid story part request");
}
+ if (!login.isRw()) {
+ return NanoHTTPD.newFixedLengthResponse(Status.FORBIDDEN,
+ NanoHTTPD.MIME_PLAINTEXT, "SET story part not allowed");
+ }
+
String luid = uriParts[off + 0];
String type = uriParts[off + 1];
NanoHTTPD.MIME_PLAINTEXT, "Invalid cover request");
}
+ if (!login.isRw()) {
+ return NanoHTTPD.newFixedLengthResponse(Status.FORBIDDEN,
+ NanoHTTPD.MIME_PLAINTEXT, "Cover request not allowed");
+ }
+
String type = uriParts[off + 0];
String id = uriParts[off + 1];
throws IOException {
final BasicLibrary lib = Instance.getInstance().getLibrary();
+ if (!login.isRw()) {
+ return NanoHTTPD.newFixedLengthResponse(Status.FORBIDDEN,
+ NanoHTTPD.MIME_PLAINTEXT, "Import not allowed");
+ }
+
final URL url = new URL(urlStr);
final Progress pg = new Progress();
final String luid = lib.getNextId();
}
}, "Import story: " + urlStr).start();
- lib.imprt(url, pg);
-
return NanoHTTPD.newFixedLengthResponse(Status.OK,
NanoHTTPD.MIME_PLAINTEXT, luid);
}
return newInputStreamResponse(NanoHTTPD.MIME_PLAINTEXT, null);
}
+ @Override
+ protected Response delete(String uri, WLoginResult login)
+ throws IOException {
+ String[] uriParts = uri.split("/");
+ int off = 2; // "" and "delete"
+
+ if (uriParts.length < off + 1) {
+ return NanoHTTPD.newFixedLengthResponse(Status.BAD_REQUEST,
+ NanoHTTPD.MIME_PLAINTEXT, "Invalid delete request");
+ }
+
+ if (!login.isRw()) {
+ return NanoHTTPD.newFixedLengthResponse(Status.FORBIDDEN,
+ NanoHTTPD.MIME_PLAINTEXT, "Delete not allowed");
+ }
+
+ String luid = uriParts[off + 0];
+
+ BasicLibrary lib = Instance.getInstance().getLibrary();
+ lib.delete(luid);
+
+ return newInputStreamResponse(NanoHTTPD.MIME_PLAINTEXT, null);
+ }
+
@Override
protected List<MetaData> metas(WLoginResult login) throws IOException {
BasicLibrary lib = Instance.getInstance().getLibrary();
protected abstract Response imprtProgress(String uri, WLoginResult login);
+ protected abstract Response delete(String uri, WLoginResult login)
+ throws IOException;
+
public WebLibraryServerHtml(boolean secure) throws IOException {
Integer port = Instance.getInstance().getConfig()
.getInteger(Config.SERVER_PORT);
} else {
rep = imprtProgress(uri, login);
}
+ } else if (WebLibraryUrls.isDeleteUrl(uri)) {
+ rep = delete(uri, login);
} else {
getTraceHandler().error(
"Supported URL was not processed: "
static private final String IMPRT_URL_PROGRESS = IMPRT_URL_BASE + "{luid}";
static public final String IMPRT_URL_IMPORT = IMPRT_URL_BASE + "import";
+ static private final String DELETE_URL_BASE = "/delete/";
+ static private final String DELETE_URL_STORY = DELETE_URL_BASE + "{luid}";
+
// GET/SET ("luid" param -> set cover to the cover of this story -- not ok
// for /cover/story/)
static private final String COVER_URL_BASE = "/cover/";
.replace("{author}", author);
}
+ static public String getDeleteUrlStory(String luid) {
+ return DELETE_URL_STORY //
+ .replace("{luid}", luid);
+ }
+
static public boolean isViewUrl(String url) {
return url != null && url.startsWith(VIEWER_URL_BASE);
}
static public boolean isImprtUrl(String url) {
return url != null && url.startsWith(IMPRT_URL_BASE);
}
+
+ static public boolean isDeleteUrl(String url) {
+ return url != null && url.startsWith(DELETE_URL_BASE);
+ }
}