mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-18 17:14:26 +03:00
Fix rename operation and add delete button
This commit is contained in:
parent
0ccf512b35
commit
57eb548cbb
@ -167,33 +167,30 @@ export default function FaceLibrary() {
|
|||||||
await axios.post(`/faces/${renameData.newName}/create`);
|
await axios.post(`/faces/${renameData.newName}/create`);
|
||||||
|
|
||||||
const oldFaceImages = faceData[renameData.oldName] || [];
|
const oldFaceImages = faceData[renameData.oldName] || [];
|
||||||
for (const image of oldFaceImages) {
|
const copyPromises = oldFaceImages.map(async (image) => {
|
||||||
const response = await fetch(`${baseUrl}clips/faces/${renameData.oldName}/${image}`);
|
const response = await fetch(`${baseUrl}clips/faces/${renameData.oldName}/${image}`);
|
||||||
const blob = await response.blob();
|
const blob = await response.blob();
|
||||||
|
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append('file', new File([blob], image));
|
formData.append('file', new File([blob], image));
|
||||||
|
formData.append('cropped', 'true');
|
||||||
|
|
||||||
await axios.post(`/faces/${renameData.newName}`, formData, {
|
return axios.post(`/faces/${renameData.newName}`, formData, {
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'multipart/form-data',
|
'Content-Type': 'multipart/form-data',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
|
|
||||||
if (oldFaceImages.length > 0) {
|
await Promise.all(copyPromises);
|
||||||
await axios.post(`/faces/${renameData.oldName}/delete`, {
|
|
||||||
ids: oldFaceImages
|
await axios.post(`/faces/${renameData.oldName}/delete`, {
|
||||||
});
|
ids: oldFaceImages.length ? oldFaceImages : ['dummy']
|
||||||
} else {
|
});
|
||||||
await axios.post(`/faces/${renameData.oldName}/delete`, {
|
|
||||||
ids: ['dummy']
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
setRenameDialog(false);
|
setRenameDialog(false);
|
||||||
setRenameData({ oldName: '', newName: '' });
|
setRenameData({ oldName: '', newName: '' });
|
||||||
refreshFaces();
|
await refreshFaces(); // Wait for refresh to complete
|
||||||
toast.success("Successfully renamed face", { position: "top-center" });
|
toast.success("Successfully renamed face", { position: "top-center" });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const axiosError = error as AxiosError<{ message: string }>;
|
const axiosError = error as AxiosError<{ message: string }>;
|
||||||
@ -206,6 +203,24 @@ export default function FaceLibrary() {
|
|||||||
}
|
}
|
||||||
}, [renameData, faceData, refreshFaces]);
|
}, [renameData, faceData, refreshFaces]);
|
||||||
|
|
||||||
|
const deleteFace = useCallback(async () => {
|
||||||
|
try {
|
||||||
|
const images = faceData[renameData.oldName] || [];
|
||||||
|
await axios.post(`/faces/${renameData.oldName}/delete`, {
|
||||||
|
ids: images.length ? images : ['dummy']
|
||||||
|
});
|
||||||
|
setRenameDialog(false);
|
||||||
|
await refreshFaces(); // Wait for refresh
|
||||||
|
toast.success("Successfully deleted face", { position: "top-center" });
|
||||||
|
} catch (error) {
|
||||||
|
const axiosError = error as AxiosError<{ message: string }>;
|
||||||
|
toast.error(
|
||||||
|
`Failed to delete face: ${axiosError.response?.data?.message || axiosError.message}`,
|
||||||
|
{ position: "top-center" }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}, [renameData.oldName, faceData, refreshFaces]);
|
||||||
|
|
||||||
if (!config) {
|
if (!config) {
|
||||||
return <ActivityIndicator />;
|
return <ActivityIndicator />;
|
||||||
}
|
}
|
||||||
@ -247,9 +262,22 @@ export default function FaceLibrary() {
|
|||||||
onKeyPress={(e) => e.key === 'Enter' && renameFace()}
|
onKeyPress={(e) => e.key === 'Enter' && renameFace()}
|
||||||
disabled={isRenaming}
|
disabled={isRenaming}
|
||||||
/>
|
/>
|
||||||
<Button onClick={renameFace} disabled={isRenaming}>
|
<div className="flex gap-2 justify-between">
|
||||||
{isRenaming ? "Renaming..." : "Rename"}
|
<Button onClick={renameFace} disabled={isRenaming} className="flex-1">
|
||||||
</Button>
|
{isRenaming ? "Renaming..." : "Rename"}
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant="destructive"
|
||||||
|
onClick={() => {
|
||||||
|
if (window.confirm(`Are you sure you want to delete ${renameData.oldName}?`)) {
|
||||||
|
deleteFace();
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
className="flex-1"
|
||||||
|
>
|
||||||
|
Delete Face
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user