Skip to content

Commit

Permalink
Add HTTP request for ATFL upload
Browse files Browse the repository at this point in the history
  • Loading branch information
srimanachanta committed Aug 9, 2023
1 parent e0681b1 commit 1aa7e57
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,48 @@ public static void onNetworkConfigRequest(Context ctx) {
}
}

public static void onAprilTagFieldLayoutRequest(Context ctx) {
var file = ctx.uploadedFile("data");

if (file == null) {
ctx.status(400);
ctx.result(
"No File was sent with the request. Make sure that the field layout json is sent at the key 'data'");
logger.error(
"No File was sent with the request. Make sure that the field layout json is sent at the key 'data'");
return;
}

if (!file.getExtension().contains("json")) {
ctx.status(400);
ctx.result(
"The uploaded file was not of type 'json'. The uploaded file should be a .json file.");
logger.error(
"The uploaded file was not of type 'json'. The uploaded file should be a .json file.");
return;
}

// Create a temp file
var tempFilePath = handleTempFileCreation(file);

if (tempFilePath.isEmpty()) {
ctx.status(500);
ctx.result("There was an error while creating a temporary copy of the file");
logger.error("There was an error while creating a temporary copy of the file");
return;
}

if (ConfigManager.getInstance().saveUploadedAprilTagFieldLayout(tempFilePath.get().toPath())) {
ctx.status(200);
ctx.result("Successfully saved the uploaded AprilTagFieldLayout");
logger.info("Successfully saved the uploaded AprilTagFieldLayout");
} else {
ctx.status(500);
ctx.result("There was an error while saving the uploaded AprilTagFieldLayout");
logger.error("There was an error while saving the uploaded AprilTagFieldLayout");
}
}

public static void onOfflineUpdateRequest(Context ctx) {
var file = ctx.uploadedFile("jarData");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public static void start(int port) {
app.post("/api/settings/hardwareConfig", RequestHandler::onHardwareConfigRequest);
app.post("/api/settings/hardwareSettings", RequestHandler::onHardwareSettingsRequest);
app.post("/api/settings/networkConfig", RequestHandler::onNetworkConfigRequest);
app.post("/api/settings/aprilTagFieldLayout", RequestHandler::onAprilTagFieldLayoutRequest);
app.post("/api/settings/general", RequestHandler::onGeneralSettingsRequest);
app.post("/api/settings/camera", RequestHandler::onCameraSettingsRequest);
app.post("/api/settings/camera/setNickname", RequestHandler::onCameraNicknameChangeRequest);
Expand Down

0 comments on commit 1aa7e57

Please sign in to comment.