From 6e18c45204bf2bcf18cf08cea126078a3a76ea54 Mon Sep 17 00:00:00 2001 From: Matt Date: Thu, 21 Mar 2024 20:49:58 -0400 Subject: [PATCH 1/2] Remove cal images if needed and bump http request size --- .../cameras/CameraCalibrationInfoCard.vue | 36 +++++++++++++++++-- photon-client/src/types/SettingTypes.ts | 2 +- .../photonvision/server/RequestHandler.java | 4 ++- .../java/org/photonvision/server/Server.java | 2 +- 4 files changed, 38 insertions(+), 6 deletions(-) diff --git a/photon-client/src/components/cameras/CameraCalibrationInfoCard.vue b/photon-client/src/components/cameras/CameraCalibrationInfoCard.vue index 52f5eb93c2..f1f02e8bde 100644 --- a/photon-client/src/components/cameras/CameraCalibrationInfoCard.vue +++ b/photon-client/src/components/cameras/CameraCalibrationInfoCard.vue @@ -4,6 +4,8 @@ import { useCameraSettingsStore } from "@/stores/settings/CameraSettingsStore"; import { useStateStore } from "@/stores/StateStore"; import { computed, inject, ref } from "vue"; import { getResolutionString, parseJsonFile } from "@/lib/PhotonUtils"; +import axios from "axios"; +import loadingImage from "@/assets/images/loading.svg"; const props = defineProps<{ videoFormat: VideoFormat; @@ -36,13 +38,36 @@ const importCalibration = async () => { return; } + let message: any = undefined; + + // check size and trim if we have to + let approxSizeMb = uploadedJson.size / 1e6; + if (approxSizeMb > 50) { + data.observations.map((it) => (it.snapshotData = undefined)); + + // so at this point the calibration is likely pretty small -- it's cheap enough to check though + approxSizeMb = JSON.stringify(data).length / 1e6; + + if (approxSizeMb > 50) { + // Absolutely monster dataset, try trimming again + data.observations = []; + } + + message = { + color: "warning", + message: `The calibration file was very large (~${approxSizeMb.toFixed(0)}MB) -- images were removed to save space!`, + timeout: 10000 + }; + } + useCameraSettingsStore() .importCalibrationFromData({ calibration: data }) .then((response) => { - useStateStore().showSnackbarMessage({ + message = message || { color: "success", message: response.data.text || response.data - }); + }; + useStateStore().showSnackbarMessage(message); }) .catch((error) => { if (error.response) { @@ -256,7 +281,12 @@ const calibrationImageURL = (index: number) => diff --git a/photon-client/src/types/SettingTypes.ts b/photon-client/src/types/SettingTypes.ts index 0531bb8b44..f81de4fe52 100644 --- a/photon-client/src/types/SettingTypes.ts +++ b/photon-client/src/types/SettingTypes.ts @@ -131,7 +131,7 @@ export interface BoardObservation { optimisedCameraToObject: Pose3d; includeObservationInCalibration: boolean; snapshotName: string; - snapshotData: JsonImageMat; + snapshotData?: JsonImageMat; } export interface CameraCalibrationResult { diff --git a/photon-server/src/main/java/org/photonvision/server/RequestHandler.java b/photon-server/src/main/java/org/photonvision/server/RequestHandler.java index 0ea9f05d79..09c703f101 100644 --- a/photon-server/src/main/java/org/photonvision/server/RequestHandler.java +++ b/photon-server/src/main/java/org/photonvision/server/RequestHandler.java @@ -604,7 +604,9 @@ public static void onCalibrationSnapshotRequest(Context ctx) { .findFirst() .orElse(null); - if (calList == null || calList.observations.size() < observationIdx) { + if (calList == null + || calList.observations.size() < observationIdx + || calList.observations.get(observationIdx).snapshotData == null) { ctx.status(404); return; } diff --git a/photon-server/src/main/java/org/photonvision/server/Server.java b/photon-server/src/main/java/org/photonvision/server/Server.java index 0fc0d97f01..f024fe3096 100644 --- a/photon-server/src/main/java/org/photonvision/server/Server.java +++ b/photon-server/src/main/java/org/photonvision/server/Server.java @@ -67,7 +67,7 @@ private static void start(int port) { // Increase the upload size limit (arbitrary, but need to be able to deal with large // calibration JSONs) - javalinConfig.http.maxRequestSize = (long) (50 * 1e6); + javalinConfig.http.maxRequestSize = (long) (100 * 1e6); javalinConfig.requestLogger.http( (ctx, ms) -> { From f8fe23adbbb9dd9f5b5d90dc1df02ab6f83259ab Mon Sep 17 00:00:00 2001 From: Matt Date: Thu, 21 Mar 2024 22:27:57 -0400 Subject: [PATCH 2/2] Run lint --- photon-client/src/components/app/photon-camera-stream.vue | 2 +- .../src/components/cameras/CameraCalibrationInfoCard.vue | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/photon-client/src/components/app/photon-camera-stream.vue b/photon-client/src/components/app/photon-camera-stream.vue index 34465e9389..710fd81b2a 100644 --- a/photon-client/src/components/app/photon-camera-stream.vue +++ b/photon-client/src/components/app/photon-camera-stream.vue @@ -63,7 +63,7 @@ onBeforeUnmount(() => {