Skip to content

Commit

Permalink
Fix box id feilds
Browse files Browse the repository at this point in the history
ChromaticPanic committed Jun 21, 2024
1 parent a279e01 commit e538367
Showing 6 changed files with 49 additions and 42 deletions.
41 changes: 22 additions & 19 deletions src/App.tsx
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { HashRouter as Router, Route, Routes } from "react-router-dom";
import { useCallback, Fragment, useState, useEffect } from "react";
// import { v4 as uuidv4 } from "uuid";
import { v4 as uuidv4 } from "uuid";
import Cookies from "js-cookie";
import Navbar from "./components/header/navbar";
import Body from "./root/body";
@@ -19,6 +19,7 @@ function App({
height: window.innerHeight,
});
const [uuid, setUuid] = useState<string>("");
const [container_uuid, setContainerUuid] = useState<string>("");
const [creativeCommonsPopupOpen, setCreativeCommonsPopupOpen] =
useState<boolean>(false);
const [switchLanguage, setSwitchLanguage] = useState<boolean>(false);
@@ -47,24 +48,24 @@ function App({
}
}, []);

// const createUuid = useCallback((): void => {
// // create a new uuid for user and set a cookie to remember it for 10 years (it is used to identify user container in azure storage)
// const newUuid = uuidv4();
// setUuid(newUuid);
// Cookies.set("user-uuid", newUuid, { expires: 365 * 10 });
// }, []);
const createContainerUuid = useCallback((): void => {
// create a new uuid for user and set a cookie to remember it for 10 years (it is used to identify user container in azure storage)
const newUuid = uuidv4();
setContainerUuid(newUuid);
Cookies.set("container-uuid", newUuid, { expires: 365 * 10 });

Check warning

Code scanning / CodeQL

Clear text transmission of sensitive cookie Medium

Sensitive cookie sent without enforcing SSL encryption.
}, []);

// const getUuid = useCallback((): void => {
// // check if the user has already a uuid (cookie)
// const existingUuid = Cookies.get("user-uuid") as string;
// if (existingUuid !== undefined) {
// setUuid(existingUuid);
// console.log("Existing UUID: " + existingUuid);
// } else {
// console.log("Creating new UUID");
// createUuid();
// }
// }, [createUuid]);
const getContainerUuid = useCallback((): void => {
// check if the user has already a uuid (cookie)
const existingUuid = Cookies.get("container-uuid") as string;
if (existingUuid !== undefined) {
setContainerUuid(existingUuid);
console.log("Existing Container UUID: " + existingUuid);
} else {
console.log("Creating new Container UUID");
createContainerUuid();
}
}, [createContainerUuid]);

// const handleSignIn = (): void => {
// setSignedIn(true);
@@ -88,8 +89,9 @@ function App({
// }, [signedIn]);

useEffect(() => {
getContainerUuid();
getCreativeCommonsAgreement();
}, [getCreativeCommonsAgreement]);
}, [getContainerUuid, getCreativeCommonsAgreement]);

useEffect(() => {
// update window size on resize
@@ -127,6 +129,7 @@ function App({
<Body
windowSize={windowSize}
uuid={uuid}
container_uuid={container_uuid}
creativeCommonsPopupOpen={creativeCommonsPopupOpen}
setCreativeCommonsPopupOpen={setCreativeCommonsPopupOpen}
handleCreativeCommonsAgreement={handleCreativeCommonsAgreement}
25 changes: 14 additions & 11 deletions src/common/api.ts
100644 → 100755
Original file line number Diff line number Diff line change
@@ -129,7 +129,8 @@ export const inferenceRequest = async (
imageObject: Images,
curDir: string,
uuid: string,
): Promise<ApiInferenceData[]> => {
container_uuid: string,
): Promise<ApiInferenceData> => {
if (backendUrl === "" || backendUrl == null) {
throw new ValueError("Backend URL is null or empty");
}
@@ -158,9 +159,10 @@ export const inferenceRequest = async (
imageDims: imageObject.imageDims,
folder_name: curDir,
user_id: uuid,
container_name: container_uuid,
},
};
return handleAxios<ApiInferenceData[]>(request);
return handleAxios<ApiInferenceData>(request);
};

export const fetchModelMetadata = async (
@@ -265,24 +267,25 @@ export const requestUUID = async (

export const requestClassList = async (
backendUrl: string,
uuid: string,
// uuid: string,
): Promise<ApiSpeciesData> => {
if (backendUrl === "" || backendUrl == null) {
throw new ValueError("Backend URL is null or empty");
}
if (uuid === "" || uuid == null) {
throw new ValueError("UUID is null or empty");
}
// if (uuid === "" || uuid == null) {
// throw new ValueError("UUID is null or empty");
// }
const request = {
method: "post",
url: `${backendUrl}/get-class-list`,
method: "get",
url: `${backendUrl}/seeds`,
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
},
data: {
uuid: uuid,
},
data: {},
// data: {
// uuid: uuid,
// },
};
return handleAxios<ApiSpeciesData>(request);
};
6 changes: 3 additions & 3 deletions src/common/cacheutils.ts
100644 → 100755
Original file line number Diff line number Diff line change
@@ -369,9 +369,9 @@ export const loadResultsToCache = (
boxes: inferenceData.boxes.map((box) => {
return {
...box.box,
inferenceId: inferenceData.inferenceId,
boxId: box.boxId,
classId: box.classId,
inferenceId: inferenceData.inference_id,
boxId: box.box_id,
classId: box.object_type_id,
label: box.label,
};
}),
7 changes: 4 additions & 3 deletions src/common/types.d.ts
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
export interface ApiInferenceData {
filename: string;
imageId: string;
inferenceId: string;
inference_id: string;
boxes: Array<{
topN: Array<{ score: number; label: string }>;
score: number;
label: string;
classId: string;
boxId: string;
object_type_id: string;
box_id: string;
box: BoxCoordinates;
overlapping: boolean;
overlappingIndices: number;
@@ -86,7 +87,7 @@ interface ClassData {
}

interface ApiSpeciesData {
data: Array<{
seeds: Array<{
seed_id: string;
seed_name: string;
}>;
6 changes: 3 additions & 3 deletions src/components/body/microscope_feed/MicroscopeFeed.tsx
100644 → 100755
Original file line number Diff line number Diff line change
@@ -145,8 +145,8 @@ const MicroscopeFeed = (props: MicroscopeFeedProps): JSX.Element => {
const classList: ClassData[] = useMemo(() => {
const classes: ClassData[] = [];
const getClasses = () => {
return requestClassList(backendUrl, uuid).then((response) => {
return response.data;
return requestClassList(backendUrl).then((response) => {
return response.seeds;
});
};
getClasses().then((data) => {
@@ -160,7 +160,7 @@ const MicroscopeFeed = (props: MicroscopeFeedProps): JSX.Element => {
});

return classes;
}, [backendUrl, uuid]);
}, [backendUrl]);

const iconStyle = {
fontSize: "1.7vh",
6 changes: 3 additions & 3 deletions src/root/body/body.tsx
100644 → 100755
Original file line number Diff line number Diff line change
@@ -32,6 +32,7 @@ interface params {
height: number;
};
uuid: string;
container_uuid: string;
creativeCommonsPopupOpen: boolean;
setCreativeCommonsPopupOpen: React.Dispatch<React.SetStateAction<boolean>>;
handleCreativeCommonsAgreement: (agree: boolean) => void;
@@ -165,12 +166,11 @@ const Body: React.FC<params> = (props) => {
imageObject,
curDir,
props.uuid,
props.uuid,
)
.then((response) => {
setReadAzureStorage(!readAzureStorage);
setImageCache(
loadResultsToCache(response[0], imageCache, imageIndex),
);
setImageCache(loadResultsToCache(response, imageCache, imageIndex));
setModelDisplayName(selectedModel);
})
.catch((error) => {

0 comments on commit e538367

Please sign in to comment.