mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-05-18 02:31:27 +00:00
use string templates for URI construction
This commit is contained in:
@@ -32,6 +32,7 @@ import javafx.stage.Stage;
|
||||
import javafx.stage.WindowEvent;
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
@@ -62,6 +63,7 @@ public class RegisterDeviceController implements FxController {
|
||||
private final P384KeyPair deviceKeyPair;
|
||||
private final CompletableFuture<ReceivedKey> result;
|
||||
private final HttpClient httpClient;
|
||||
private final StringTemplate.Processor<URI, RuntimeException> API_BASE = this::resolveRelativeToApiBase;
|
||||
|
||||
private final BooleanProperty invalidSetupCode = new SimpleBooleanProperty(false);
|
||||
private final BooleanProperty workInProgress = new SimpleBooleanProperty(false);
|
||||
@@ -108,9 +110,8 @@ public class RegisterDeviceController implements FxController {
|
||||
public void register() {
|
||||
workInProgress.set(true);
|
||||
|
||||
var apiRootUrl = hubConfig.getApiBaseUrl();
|
||||
|
||||
var userReq = HttpRequest.newBuilder(apiRootUrl.resolve("users/me")) //
|
||||
var userReq = HttpRequest.newBuilder(API_BASE."users/me") //
|
||||
.GET() //
|
||||
.timeout(REQ_TIMEOUT) //
|
||||
.header("Authorization", "Bearer " + bearerToken) //
|
||||
@@ -136,7 +137,7 @@ public class RegisterDeviceController implements FxController {
|
||||
var now = Instant.now().toString();
|
||||
var dto = new CreateDeviceDto(deviceId, deviceNameField.getText(), BaseEncoding.base64().encode(deviceKeyPair.getPublic().getEncoded()), "DESKTOP", jwe.serialize(), now);
|
||||
var json = toJson(dto);
|
||||
var deviceUri = apiRootUrl.resolve("devices/" + deviceId);
|
||||
var deviceUri = API_BASE."devices/\{deviceId}";
|
||||
var putDeviceReq = HttpRequest.newBuilder(deviceUri) //
|
||||
.PUT(HttpRequest.BodyPublishers.ofString(json, StandardCharsets.UTF_8)) //
|
||||
.timeout(REQ_TIMEOUT) //
|
||||
@@ -204,6 +205,12 @@ public class RegisterDeviceController implements FxController {
|
||||
result.cancel(true);
|
||||
}
|
||||
|
||||
private URI resolveRelativeToApiBase(StringTemplate template) {
|
||||
var path = template.interpolate();
|
||||
var relPath = path.startsWith("/") ? path.substring(1) : path;
|
||||
return hubConfig.getApiBaseUrl().resolve(relPath);
|
||||
}
|
||||
|
||||
//--- Getters & Setters
|
||||
public BooleanProperty invalidSetupCodeProperty() {
|
||||
return invalidSetupCode;
|
||||
|
||||
Reference in New Issue
Block a user