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:
@@ -11,11 +11,17 @@ import net.monarchpass.piecannon.Server;
|
|||||||
import net.monarchpass.piecannon.impl.FtpServer;
|
import net.monarchpass.piecannon.impl.FtpServer;
|
||||||
import net.monarchpass.piecannon.impl.GoFileServer;
|
import net.monarchpass.piecannon.impl.GoFileServer;
|
||||||
import net.monarchpass.piecannon.impl.SftpServer;
|
import net.monarchpass.piecannon.impl.SftpServer;
|
||||||
|
import net.monarchpass.piecannon.impl.WebDavServer;
|
||||||
|
|
||||||
public class ServerFactory implements Function<JsonObject, Server> {
|
public class ServerFactory implements Function<JsonObject, Server> {
|
||||||
public Server apply (final JsonObject object) {
|
public Server apply (final JsonObject object) {
|
||||||
final String type = object.getAsJsonPrimitive("type").getAsString();
|
final String type = Optional.ofNullable(object.getAsJsonPrimitive("type"))
|
||||||
if (type.equalsIgnoreCase("gofile")) {
|
.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"));
|
return new GoFileServer(Optional.ofNullable(object.getAsJsonPrimitive("label")).map(JsonPrimitive::getAsString).orElse("GoFile"));
|
||||||
} else if (type.equalsIgnoreCase("ftp")) {
|
} else if (type.equalsIgnoreCase("ftp")) {
|
||||||
return makeFtpServer(object);
|
return makeFtpServer(object);
|
||||||
@@ -26,6 +32,23 @@ public class ServerFactory implements Function<JsonObject, Server> {
|
|||||||
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) {
|
private Server makeSftpServer (final JsonObject object) {
|
||||||
final String host = object.getAsJsonPrimitive("host").getAsString();
|
final String host = object.getAsJsonPrimitive("host").getAsString();
|
||||||
final String label = object.has("label") ? object.getAsJsonPrimitive("label").getAsString() : host;
|
final String label = object.has("label") ? object.getAsJsonPrimitive("label").getAsString() : host;
|
||||||
|
Reference in New Issue
Block a user