Fix rename operation 2

This commit is contained in:
Weitheng Haw 2025-01-28 13:35:15 +00:00
parent ff55faf5bd
commit 0ccf512b35
2 changed files with 17 additions and 3 deletions

View File

@ -117,10 +117,19 @@ def deregister_faces(request: Request, name: str, body: dict = None):
status_code=404, status_code=404,
) )
face_dir = os.path.join(FACE_DIR, name)
context: EmbeddingsContext = request.app.embeddings context: EmbeddingsContext = request.app.embeddings
context.delete_face_ids( context.delete_face_ids(
name, map(lambda file: sanitize_filename(file), list_of_ids) name, map(lambda file: sanitize_filename(file), list_of_ids)
) )
try:
if os.path.exists(face_dir) and not os.listdir(face_dir):
os.rmdir(face_dir)
except Exception as e:
logger.error(f"Failed to remove directory {face_dir}: {str(e)}")
return JSONResponse( return JSONResponse(
content=({"success": True, "message": "Successfully deleted faces."}), content=({"success": True, "message": "Successfully deleted faces."}),
status_code=200, status_code=200,

View File

@ -172,8 +172,13 @@ export default function FaceLibrary() {
const blob = await response.blob(); const blob = await response.blob();
const formData = new FormData(); const formData = new FormData();
formData.append('file', blob, image); formData.append('file', new File([blob], image));
await axios.post(`/faces/${renameData.newName}`, formData);
await axios.post(`/faces/${renameData.newName}`, formData, {
headers: {
'Content-Type': 'multipart/form-data',
},
});
} }
if (oldFaceImages.length > 0) { if (oldFaceImages.length > 0) {
@ -182,7 +187,7 @@ export default function FaceLibrary() {
}); });
} else { } else {
await axios.post(`/faces/${renameData.oldName}/delete`, { await axios.post(`/faces/${renameData.oldName}/delete`, {
ids: ['dummy'] // Send a dummy ID to pass validation ids: ['dummy']
}); });
} }