From 7652d43df572570420d3ed5eecb92bf383471b67 Mon Sep 17 00:00:00 2001 From: Cameron Dunn Date: Wed, 8 Jan 2025 15:49:35 -0500 Subject: [PATCH] fixed video sync --- front-end/package.json | 4 ++-- .../components/modal/download/DownloadModal.jsx | 2 +- .../components/views/VideoPlayer/VideoPlayer.jsx | 2 +- front-end/src/lib/apiUtils.ts | 14 +++++++++++++- front-end/src/lib/modelUtils.ts | 8 ++++---- 5 files changed, 21 insertions(+), 9 deletions(-) diff --git a/front-end/package.json b/front-end/package.json index c9d3f383..80d3e7cc 100644 --- a/front-end/package.json +++ b/front-end/package.json @@ -1,6 +1,6 @@ { "name": "dataviewer", - "version": "1.0.0", + "version": "1.2.0", "private": true, "type": "module", "main": "build/main.js", @@ -84,7 +84,7 @@ } ], "artifactName": "${productName}-v${version}-installer.exe", - "requestedExecutionLevel": "asInvoker" + "requestedExecutionLevel": "requireAdministrator" }, "nsis": { "oneClick": false, diff --git a/front-end/src/components/modal/download/DownloadModal.jsx b/front-end/src/components/modal/download/DownloadModal.jsx index e3cc5f9d..66d15a35 100644 --- a/front-end/src/components/modal/download/DownloadModal.jsx +++ b/front-end/src/components/modal/download/DownloadModal.jsx @@ -37,7 +37,7 @@ export const DownloadModal = ({ setModal }) => { // Add each selected file to the zip archive for (const file of selectedFiles) { - const blob = await ApiUtil.getFile(file.key); + const blob = await ApiUtil.getFileAsText(file.key); // Add the file to the zip archive with the file name as the key zip.file(file.key, blob); diff --git a/front-end/src/components/views/VideoPlayer/VideoPlayer.jsx b/front-end/src/components/views/VideoPlayer/VideoPlayer.jsx index 8b4c7e23..a83541e3 100644 --- a/front-end/src/components/views/VideoPlayer/VideoPlayer.jsx +++ b/front-end/src/components/views/VideoPlayer/VideoPlayer.jsx @@ -9,7 +9,7 @@ const VideoPlayer = ({ video, setVideoTimestamp }) => { useEffect(() => { // Fetch data when the component mounts - ApiUtil.getFile(video.key) + ApiUtil.getFileAsBlob(video.key) .then((blob) => { const url = URL.createObjectURL(blob); setVideoURL(url); diff --git a/front-end/src/lib/apiUtils.ts b/front-end/src/lib/apiUtils.ts index 0ebd891f..fdedc543 100644 --- a/front-end/src/lib/apiUtils.ts +++ b/front-end/src/lib/apiUtils.ts @@ -10,13 +10,25 @@ export const ApiUtil = { * @param {string} fileKey - The unique identifier of the file. * @returns {Promise} A promise that resolves to the fetched file in the form of a Blob. */ - getFile: async (fileKey: string) => { + getFileAsText: async (fileKey: string) => { fileKey = encodeURIComponent(fileKey); const response = await fetch(`${baseApiUrl}/files/${fileKey}`); if (!response.ok) throw Error(response.statusText); return response.text(); }, + /** + * Sends a GET request to the server to fetch a specific file. + * @param {string} fileKey - The unique identifier of the file. + * @returns {Promise} A promise that resolves to the fetched file in the form of a Blob. + */ + getFileAsBlob: async (fileKey: string) => { + fileKey = encodeURIComponent(fileKey); + const response = await fetch(`${baseApiUrl}/files/${fileKey}`); + if (!response.ok) throw Error(response.statusText); + return response.blob(); + }, + /** * @description Fetches a list of files from the server. * @returns {Promise} A promise that resolves to an array of file names. diff --git a/front-end/src/lib/modelUtils.ts b/front-end/src/lib/modelUtils.ts index 96386015..a2cc2923 100644 --- a/front-end/src/lib/modelUtils.ts +++ b/front-end/src/lib/modelUtils.ts @@ -28,10 +28,10 @@ const combineData = (timestamps: string[], x: string[], y: string[], z: string[] export const fetchData = async (bin: string) => { let data: quatReplayData = []; await Promise.all([ - ApiUtil.getFile(`${bin}/IMU QUAT W.csv`), - ApiUtil.getFile(`${bin}/IMU QUAT X.csv`), - ApiUtil.getFile(`${bin}/IMU QUAT Y.csv`), - ApiUtil.getFile(`${bin}/IMU QUAT Z.csv`) + ApiUtil.getFileAsText(`${bin}/IMU QUAT W.csv`), + ApiUtil.getFileAsText(`${bin}/IMU QUAT X.csv`), + ApiUtil.getFileAsText(`${bin}/IMU QUAT Y.csv`), + ApiUtil.getFileAsText(`${bin}/IMU QUAT Z.csv`) ]).then(([wDataRaw, xDataRaw, yDataRaw, zDataRaw]) => { const wData = parseCSV(wDataRaw); const xData = parseCSV(xDataRaw);