+ @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 ("story".equals(type)) {
+ Image img = storyCover(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 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 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);
+ }
+