From 81bd956ae8308bbf5ae6fe84de824f97e934b248 Mon Sep 17 00:00:00 2001 From: Nicolas Mowen Date: Sun, 9 Feb 2025 14:50:12 -0700 Subject: [PATCH] Fix sanitized api causing issues (#16433) --- frigate/api/classification.py | 9 +++++---- web/src/pages/FaceLibrary.tsx | 20 +++++++++----------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/frigate/api/classification.py b/frigate/api/classification.py index df0d3b45e..7cd127d07 100644 --- a/frigate/api/classification.py +++ b/frigate/api/classification.py @@ -98,9 +98,10 @@ def train_face(request: Request, name: str, body: dict = None): status_code=404, ) + sanitized_name = sanitize_filename(name) rand_id = "".join(random.choices(string.ascii_lowercase + string.digits, k=6)) - new_name = f"{name}-{rand_id}.webp" - new_file = sanitize_filename(os.path.join(FACE_DIR, f"{name}/{new_name}")) + new_name = f"{sanitized_name}-{rand_id}.webp" + new_file = os.path.join(FACE_DIR, f"{sanitized_name}/{new_name}") shutil.move(training_file, new_file) context: EmbeddingsContext = request.app.embeddings @@ -118,7 +119,7 @@ def train_face(request: Request, name: str, body: dict = None): @router.post("/faces/{name}/create") -async def create_face(request: Request, name: str, file: UploadFile): +async def create_face(request: Request, name: str): if not request.app.frigate_config.face_recognition.enabled: return JSONResponse( status_code=400, @@ -126,7 +127,7 @@ async def create_face(request: Request, name: str, file: UploadFile): ) os.makedirs( - sanitize_filename(os.path.join(FACE_DIR, name.replace(" ", "_"))), exist_ok=True + os.path.join(FACE_DIR, sanitize_filename(name.replace(" ", "_"))), exist_ok=True ) return JSONResponse( status_code=200, diff --git a/web/src/pages/FaceLibrary.tsx b/web/src/pages/FaceLibrary.tsx index a096bb28c..4bb6b39ff 100644 --- a/web/src/pages/FaceLibrary.tsx +++ b/web/src/pages/FaceLibrary.tsx @@ -93,10 +93,9 @@ export default function FaceLibrary() { if (resp.status == 200) { setUpload(false); refreshFaces(); - toast.success( - "Successfully uploaded image. View the file in the /exports folder.", - { position: "top-center" }, - ); + toast.success("Successfully uploaded image.", { + position: "top-center", + }); } }) .catch((error) => { @@ -125,22 +124,21 @@ export default function FaceLibrary() { }) .then((resp) => { if (resp.status == 200) { - setUpload(false); + setAddFace(false); refreshFaces(); - toast.success( - "Successfully uploaded image. View the file in the /exports folder.", - { position: "top-center" }, - ); + toast.success("Successfully add face library.", { + position: "top-center", + }); } }) .catch((error) => { if (error.response?.data?.message) { toast.error( - `Failed to upload image: ${error.response.data.message}`, + `Failed to set face name: ${error.response.data.message}`, { position: "top-center" }, ); } else { - toast.error(`Failed to upload image: ${error.message}`, { + toast.error(`Failed to set face name: ${error.message}`, { position: "top-center", }); }