lib: Add WebDav server type, make this the default server type (since it's relatively simple, standardized, and requires the least configuration).
This commit is contained in:
parent
c0cb1b4f2e
commit
6ed87b738f
@ -11,11 +11,17 @@ import net.monarchpass.piecannon.Server;
|
||||
import net.monarchpass.piecannon.impl.FtpServer;
|
||||
import net.monarchpass.piecannon.impl.GoFileServer;
|
||||
import net.monarchpass.piecannon.impl.SftpServer;
|
||||
import net.monarchpass.piecannon.impl.WebDavServer;
|
||||
|
||||
public class ServerFactory implements Function<JsonObject, Server> {
|
||||
public Server apply (final JsonObject object) {
|
||||
final String type = object.getAsJsonPrimitive("type").getAsString();
|
||||
if (type.equalsIgnoreCase("gofile")) {
|
||||
final String type = Optional.ofNullable(object.getAsJsonPrimitive("type"))
|
||||
.map(JsonPrimitive::getAsString)
|
||||
.orElse("webdav");
|
||||
|
||||
if (type.equals("webdav")) {
|
||||
return makeWebDavServer(object);
|
||||
} else if (type.equalsIgnoreCase("gofile")) {
|
||||
return new GoFileServer(Optional.ofNullable(object.getAsJsonPrimitive("label")).map(JsonPrimitive::getAsString).orElse("GoFile"));
|
||||
} else if (type.equalsIgnoreCase("ftp")) {
|
||||
return makeFtpServer(object);
|
||||
@ -23,9 +29,26 @@ public class ServerFactory implements Function<JsonObject, Server> {
|
||||
return makeSftpServer(object);
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException("Invalid server type: " + type);
|
||||
throw new IllegalArgumentException("Invalid server type: " + type);
|
||||
}
|
||||
|
||||
private Server makeWebDavServer (final JsonObject object) {
|
||||
final String label = Optional.ofNullable(object.getAsJsonPrimitive("label"))
|
||||
.map(JsonPrimitive::getAsString)
|
||||
.orElse("WebDav");
|
||||
final String username = Optional.ofNullable(object.getAsJsonPrimitive("username"))
|
||||
.map(JsonPrimitive::getAsString)
|
||||
.orElse(null);
|
||||
final String password = Optional.ofNullable(object.getAsJsonPrimitive("password"))
|
||||
.map(JsonPrimitive::getAsString)
|
||||
.orElse(null);
|
||||
final String url = object.getAsJsonPrimitive("url").getAsString();
|
||||
|
||||
return new WebDavServer(
|
||||
label, URI.create(url), username, password
|
||||
);
|
||||
}
|
||||
|
||||
private Server makeSftpServer (final JsonObject object) {
|
||||
final String host = object.getAsJsonPrimitive("host").getAsString();
|
||||
final String label = object.has("label") ? object.getAsJsonPrimitive("label").getAsString() : host;
|
||||
|
Loading…
x
Reference in New Issue
Block a user