Fix sanitized api causing issues (#16433)

This commit is contained in:
Nicolas Mowen 2025-02-09 14:50:12 -07:00 committed by GitHub
parent c8cec63cb9
commit 81bd956ae8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 15 deletions

View File

@ -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,

View File

@ -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",
});
}