Fix deleting and renaming

This commit is contained in:
Nicolas Mowen 2024-04-19 09:02:43 -06:00
parent 28a8b7c8d4
commit e6f00c4b4f
4 changed files with 14 additions and 15 deletions

View File

@ -76,7 +76,7 @@ def export_recording(camera_name: str, start_time, end_time):
exporter = RecordingExporter( exporter = RecordingExporter(
current_app.frigate_config, current_app.frigate_config,
camera_name, camera_name,
secure_filename(name.replace(" ", "_")) if name else None, secure_filename(name) if name else None,
int(start_time), int(start_time),
int(end_time), int(end_time),
( (
@ -97,7 +97,7 @@ def export_recording(camera_name: str, start_time, end_time):
) )
@ExportBp.route("/export/<id>/<new_name>", methods=["POST"]) @ExportBp.route("/export/<id>/<new_name>", methods=["PATCH"])
def export_rename(id, new_name: str): def export_rename(id, new_name: str):
try: try:
export: Export = Export.get(Export.id == id) export: Export = Export.get(Export.id == id)
@ -142,7 +142,7 @@ def export_delete(id: str):
Path(export.video_path).unlink(missing_ok=True) Path(export.video_path).unlink(missing_ok=True)
Path(export.thumb_path).unlink(missing_ok=True) Path(export.thumb_path).unlink(missing_ok=True)
export.delete() export.delete_instance()
return make_response( return make_response(
jsonify( jsonify(
{ {

View File

@ -159,7 +159,7 @@ class RecordingExporter(threading.Thread):
export_id = f"{self.camera}_{''.join(random.choices(string.ascii_lowercase + string.digits, k=6))}" export_id = f"{self.camera}_{''.join(random.choices(string.ascii_lowercase + string.digits, k=6))}"
export_name = ( export_name = (
self.user_provided_name self.user_provided_name
or f"{self.camera.replace("_", " ")} {self.get_datetime_from_timestamp(self.start_time)} {self.get_datetime_from_timestamp(self.end_time)}" or f"{self.camera.replace('_', ' ')} {self.get_datetime_from_timestamp(self.start_time)} {self.get_datetime_from_timestamp(self.end_time)}"
) )
video_path = f"{EXPORT_DIR}/{export_id}.mp4" video_path = f"{EXPORT_DIR}/{export_id}.mp4"

View File

@ -40,7 +40,7 @@ export default function ExportCard({
editName != undefined ? ["Enter"] : [], editName != undefined ? ["Enter"] : [],
(_, down, repeat) => { (_, down, repeat) => {
if (down && !repeat && editName && editName.update.length > 0) { if (down && !repeat && editName && editName.update.length > 0) {
onRename(editName.original, editName.update); onRename(exportedRecording.id, editName.update);
setEditName(undefined); setEditName(undefined);
} }
}, },
@ -78,10 +78,7 @@ export default function ExportCard({
variant="select" variant="select"
disabled={(editName?.update?.length ?? 0) == 0} disabled={(editName?.update?.length ?? 0) == 0}
onClick={() => { onClick={() => {
onRename( onRename(exportedRecording.id, editName.update);
editName.original,
editName.update.replaceAll(" ", "_"),
);
setEditName(undefined); setEditName(undefined);
}} }}
> >
@ -118,7 +115,7 @@ export default function ExportCard({
<Chip <Chip
className="bg-gradient-to-br from-gray-400 to-gray-500 bg-gray-500 rounded-md cursor-pointer" className="bg-gradient-to-br from-gray-400 to-gray-500 bg-gray-500 rounded-md cursor-pointer"
onClick={() => onClick={() =>
setEditName({ original: exportedRecording.id, update: "" }) setEditName({ original: exportedRecording.name, update: "" })
} }
> >
<LuPencil className="size-4 text-white" /> <LuPencil className="size-4 text-white" />

View File

@ -34,9 +34,7 @@ function Exports() {
} }
return exports.filter((exp) => return exports.filter((exp) =>
exp.name exp.name.toLowerCase().includes(search.toLowerCase()),
.toLowerCase()
.includes(search.toLowerCase().replaceAll(" ", "_")),
); );
}, [exports, search]); }, [exports, search]);
@ -90,7 +88,11 @@ function Exports() {
</AlertDialogHeader> </AlertDialogHeader>
<AlertDialogFooter> <AlertDialogFooter>
<AlertDialogCancel>Cancel</AlertDialogCancel> <AlertDialogCancel>Cancel</AlertDialogCancel>
<Button variant="destructive" onClick={() => onHandleDelete()}> <Button
className="text-white"
variant="destructive"
onClick={() => onHandleDelete()}
>
Delete Delete
</Button> </Button>
</AlertDialogFooter> </AlertDialogFooter>
@ -144,7 +146,7 @@ function Exports() {
exportedRecording={item} exportedRecording={item}
onSelect={setSelected} onSelect={setSelected}
onRename={onHandleRename} onRename={onHandleRename}
onDelete={(file) => setDeleteClip(file)} onDelete={(id) => setDeleteClip(id)}
/> />
))} ))}
</div> </div>