// /story/luid/json <-- json, whole chapter (no images)
@Override
protected Response getStoryPart(String uri, WLoginResult login) {
- String[] cover = uri.split("/");
+ String[] uriParts = uri.split("/");
int off = 2;
- if (cover.length < off + 2) {
+ if (uriParts.length < off + 2) {
return NanoHTTPD.newFixedLengthResponse(Status.BAD_REQUEST,
NanoHTTPD.MIME_PLAINTEXT, null);
}
- String luid = cover[off + 0];
- String chapterStr = cover[off + 1];
- String imageStr = cover.length < off + 3 ? null : cover[off + 2];
+ String luid = uriParts[off + 0];
+ String chapterStr = uriParts[off + 1];
+ String imageStr = uriParts.length < off + 3 ? null : uriParts[off + 2];
// 1-based (0 = desc)
int chapter = 0;
InputStream in = null;
try {
if ("cover".equals(chapterStr)) {
- Image img = cover(luid, login);
+ Image img = storyCover(luid, login);
if (img != null) {
in = img.newInputStream();
}
return newInputStreamResponse(mimeType, in);
}
+ @Override
+ protected Response getCover(String uri, 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];
+
+ InputStream in = null;
+
+ if ("cover".equals(type)) {
+ Image img = storyCover(id, login);
+ if (img != null) {
+ in = img.newInputStream();
+ }
+ } else if ("author".equals(type)) {
+ Image img = authorCover(id, login);
+ if (img != null) {
+ in = img.newInputStream();
+ }
+ } else if ("source".equals(type)) {
+ Image img = sourceCover(id, login);
+ if (img != null) {
+ in = img.newInputStream();
+ }
+ } else {
+ return NanoHTTPD.newFixedLengthResponse(Status.BAD_REQUEST,
+ NanoHTTPD.MIME_PLAINTEXT, "Invalid cover type: " + type);
+ }
+
+ // TODO: get correct image type
+ return newInputStreamResponse("image/png", in);
+ }
+
@Override
protected List<MetaData> metas(WLoginResult login) throws IOException {
BasicLibrary lib = Instance.getInstance().getLibrary();
return meta;
}
- private Image cover(String luid, WLoginResult login) throws IOException {
+ private Image storyCover(String luid, WLoginResult login)
+ throws IOException {
MetaData meta = meta(luid, login);
if (meta != null) {
BasicLibrary lib = Instance.getInstance().getLibrary();
return null;
}
+ private Image authorCover(String author, WLoginResult login)
+ throws IOException {
+ Image img = null;
+
+ List<MetaData> metas = new MetaResultList(metas(login)).filter(null,
+ author, null);
+ if (metas.size() > 0) {
+ BasicLibrary lib = Instance.getInstance().getLibrary();
+ img = lib.getCustomAuthorCover(author);
+ if (img == null)
+ img = lib.getCover(metas.get(0).getLuid());
+ }
+
+ return img;
+
+ }
+
+ private Image sourceCover(String source, WLoginResult login)
+ throws IOException {
+ Image img = null;
+
+ List<MetaData> metas = new MetaResultList(metas(login)).filter(source,
+ null, null);
+ if (metas.size() > 0) {
+ BasicLibrary lib = Instance.getInstance().getLibrary();
+ img = lib.getCustomSourceCover(source);
+ if (img == null)
+ img = lib.getCover(metas.get(0).getLuid());
+ }
+
+ return img;
+ }
+
private boolean isAllowed(MetaData meta, WLoginResult login) {
MetaResultList one = new MetaResultList(Arrays.asList(meta));
if (login.isWl() && !whitelist.isEmpty()) {
abstract protected Response getStoryPart(String uri, WLoginResult login);
+ abstract protected Response getCover(String uri, WLoginResult login)
+ throws IOException;
+
abstract protected List<MetaData> metas(WLoginResult login)
throws IOException;
rep = newFixedLengthResponse(Status.OK,
MIME_PLAINTEXT,
Version.getCurrentVersion().toString());
+ } else if (WebLibraryUrls.isCoverUrl(uri)) {
+ rep = getCover(uri, login);
} else if (WebLibraryUrls.isListUrl(uri)) {
rep = getList(uri, login);
} else if (WebLibraryUrls.isStoryUrl(uri)) {
}
};
- if (ssf != null) {
+ if (ssf != null)
+
+ {
getTraceHandler().trace("Install SSL on the web server...");
server.makeSecure(ssf, null);
getTraceHandler().trace("Done.");
static public final String LIST_URL_METADATA = LIST_URL_BASE + "metadata";
+ // GET/POST
+ static private final String COVER_URL_BASE = "/cover/";
+ static private final String COVER_URL_STORY = COVER_URL_BASE
+ + "story/{luid}";
+ static private final String COVER_URL_AUTHOR = COVER_URL_BASE
+ + "author/{author}";
+ static private final String COVER_URL_SOURCE = COVER_URL_BASE
+ + "source/{source}";
+
static public String getViewUrl(String luid, Integer chap, Integer para) {
return VIEWER_URL //
.replace("{luid}", luid) //
static public boolean isSupportedUrl(String url) {
return INDEX_URL.equals(url) || VERSION_URL.equals(url)
|| LOGOUT_URL.equals(url) || isViewUrl(url) || isStoryUrl(url)
- || isListUrl(url);
+ || isListUrl(url) || isCoverUrl(url);
+ }
+
+ static public String getCoverUrlStory(String luid) {
+ return COVER_URL_STORY //
+ .replace("{luid}", luid);
+ }
+
+ static public String getCoverUrlSource(String source) {
+ return COVER_URL_SOURCE //
+ .replace("{source}", source);
+ }
+
+ static public String getCoverUrlAuthor(String author) {
+ return COVER_URL_AUTHOR //
+ .replace("{author}", author);
}
static public boolean isViewUrl(String url) {
static public boolean isListUrl(String url) {
return url != null && url.startsWith(LIST_URL_BASE);
}
+
+ static public boolean isCoverUrl(String url) {
+ return url != null && url.startsWith(COVER_URL_BASE);
+ }
}