import java.io.IOException;
import java.net.URL;
+import java.nio.file.AccessDeniedException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
}
if ((subkey + "|").contains("|wl|")) {
wl = false; // |wl| = bypass whitelist
+ whitelist = new ArrayList<String>();
}
}
}
if ("PING".equals(command)) {
return rw ? "r/w" : "r/o";
} else if ("GET_METADATA".equals(command)) {
+ List<MetaData> metas = new ArrayList<MetaData>();
+
if ("*".equals(args[0])) {
Progress pg = createPgForwarder(action);
- List<MetaData> metas = new ArrayList<MetaData>();
-
for (MetaData meta : Instance.getLibrary().getMetas(pg)) {
MetaData light;
if (meta.getCover() == null) {
}
forcePgDoneSent(pg);
- return metas.toArray(new MetaData[] {});
+ } else {
+ metas.add(Instance.getLibrary().getInfo((String) args[0]));
+ }
+
+ if (!whitelist.isEmpty()) {
+ for (int i = 0; i < metas.size(); i++) {
+ if (!whitelist.contains(metas.get(i).getSource())) {
+ metas.remove(i);
+ i--;
+ }
+ }
}
- return new MetaData[] { Instance.getLibrary().getInfo(
- (String) args[0]) };
+ return metas.toArray(new MetaData[0]);
} else if ("GET_STORY".equals(command)) {
MetaData meta = Instance.getLibrary().getInfo((String) args[0]);
+ if (meta == null) {
+ return null;
+ }
+
+ if (!whitelist.isEmpty()) {
+ if (!whitelist.contains(meta.getSource())) {
+ return null;
+ }
+ }
+
meta = meta.clone();
meta.setCover(null);
action.rec();
}
} else if ("SAVE_STORY".equals(command)) {
+ if (!rw) {
+ throw new AccessDeniedException("" + args[0], null,
+ "Read-Only remote library");
+ }
+
List<Object> list = new ArrayList<Object>();
action.send(null);
Instance.getLibrary().save(story, (String) args[0], null);
return story.getMeta().getLuid();
} else if ("IMPORT".equals(command)) {
+ if (!rw) {
+ throw new AccessDeniedException("" + args[0], null,
+ "Read-Only remote library");
+ }
+
Progress pg = createPgForwarder(action);
Story story = Instance.getLibrary().imprt(
new URL((String) args[0]), pg);
forcePgDoneSent(pg);
return story.getMeta().getLuid();
} else if ("DELETE_STORY".equals(command)) {
+ if (!rw) {
+ throw new AccessDeniedException("" + args[0], null,
+ "Read-Only remote library");
+ }
+
Instance.getLibrary().delete((String) args[0]);
} else if ("GET_COVER".equals(command)) {
return Instance.getLibrary().getCover((String) args[0]);
return null;
}
} else if ("SET_COVER".equals(command)) {
+ if (!rw) {
+ throw new AccessDeniedException("" + args[0], "" + args[1],
+ "Read-Only remote library");
+ }
+
if ("SOURCE".equals(args[0])) {
Instance.getLibrary().setSourceCover((String) args[1],
(String) args[2]);
(String) args[2]);
}
} else if ("CHANGE_STA".equals(command)) {
+ if (!rw) {
+ throw new AccessDeniedException("" + args[0], "" + args[1],
+ "Read-Only remote library");
+ }
+
Progress pg = createPgForwarder(action);
Instance.getLibrary().changeSTA((String) args[0], (String) args[1],
(String) args[2], (String) args[3], pg);
forcePgDoneSent(pg);
} else if ("EXIT".equals(command)) {
+ if (!rw) {
+ throw new AccessDeniedException("EXIT", "",
+ "Read-Only remote library, cannot close it");
+ }
+
stop(0, false);
}