diff --git a/apps/mobile/src/screens/settings/library/EditLocationSettings.tsx b/apps/mobile/src/screens/settings/library/EditLocationSettings.tsx index b60084a79..5a50e7f21 100644 --- a/apps/mobile/src/screens/settings/library/EditLocationSettings.tsx +++ b/apps/mobile/src/screens/settings/library/EditLocationSettings.tsx @@ -185,7 +185,7 @@ const EditLocationSettingsScreen = ({ fullRescan.mutate(id)}> + fullRescan.mutate({ location_id: id, reidentify_objects: true })}> } diff --git a/apps/mobile/src/screens/settings/library/LocationSettings.tsx b/apps/mobile/src/screens/settings/library/LocationSettings.tsx index 101912e8f..68a00cb5a 100644 --- a/apps/mobile/src/screens/settings/library/LocationSettings.tsx +++ b/apps/mobile/src/screens/settings/library/LocationSettings.tsx @@ -73,7 +73,7 @@ function LocationItem({ location, index, navigation }: LocationItemProps) { {/* Full Re-scan IS too much here */} fullRescan.mutate(location.id)} + onPress={() => fullRescan.mutate({ location_id: location.id, reidentify_objects: true })} > diff --git a/core/src/api/locations.rs b/core/src/api/locations.rs index 9a9309b31..47da8048c 100644 --- a/core/src/api/locations.rs +++ b/core/src/api/locations.rs @@ -14,6 +14,7 @@ use std::path::PathBuf; use rspc::{self, alpha::AlphaRouter, ErrorCode}; use serde::{Deserialize, Serialize}; use specta::Type; +use tracing::info; use super::{utils::library, Ctx, R}; @@ -127,8 +128,43 @@ pub(crate) fn mount() -> AlphaRouter { }) }) .procedure("fullRescan", { + #[derive(Type, Deserialize)] + pub struct FullRescanArgs { + pub location_id: location::id::Type, + pub reidentify_objects: bool, + } + R.with2(library()).mutation( - |(_, library), location_id: location::id::Type| async move { + |(_, library), + FullRescanArgs { + location_id, + reidentify_objects, + }| async move { + if reidentify_objects { + let object_ids = library + .db + .file_path() + .find_many(vec![ + file_path::location_id::equals(Some(location_id)), + file_path::object_id::not(None), + ]) + .select(file_path::select!({ object_id })) + .exec() + .await? + .into_iter() + .filter_map(|file_path| file_path.object_id) + .collect::>(); + + let count = library + .db + .object() + .delete_many(vec![object::id::in_vec(object_ids)]) + .exec() + .await?; + + info!("Deleted {count} objects, to be reidentified"); + } + // rescan location scan_location( &library, diff --git a/core/src/job/worker.rs b/core/src/job/worker.rs index 54d3e06f8..ab1cf4b07 100644 --- a/core/src/job/worker.rs +++ b/core/src/job/worker.rs @@ -418,7 +418,15 @@ impl Worker { report.status = JobStatus::CompletedWithErrors; report.errors_text = errors; report.data = None; - report.metadata = metadata; + report.metadata = match (report.metadata.take(), metadata) { + (Some(mut current_metadata), Some(new_metadata)) => { + current_metadata["output"] = new_metadata; + Some(current_metadata) + } + (None, Some(new_metadata)) => Some(json!({ "output": new_metadata })), + (Some(current_metadata), None) => Some(current_metadata), + _ => None, + }; report.completed_at = Some(Utc::now()); if let Err(e) = report.update(library).await { error!("failed to update job report: {:#?}", e); diff --git a/crates/file-ext/src/extensions.rs b/crates/file-ext/src/extensions.rs index e461c6acc..3ab1e0f2e 100644 --- a/crates/file-ext/src/extensions.rs +++ b/crates/file-ext/src/extensions.rs @@ -262,6 +262,7 @@ extension_category_enum! { Swift, Mdx, Astro, + Mts, } } diff --git a/crates/file-ext/src/magic.rs b/crates/file-ext/src/magic.rs index ba8ba8810..7f6d4a092 100644 --- a/crates/file-ext/src/magic.rs +++ b/crates/file-ext/src/magic.rs @@ -215,15 +215,19 @@ impl Extension { } } ExtensionPossibility::Conflicts(ext) => match ext_str { - "ts" => { - let maybe_video_ext = if ext.iter().any(|e| matches!(e, Extension::Video(_))) { - verify_magic_bytes(VideoExtension::Ts, file) - .await - .map(Extension::Video) - } else { - None - }; - Some(maybe_video_ext.unwrap_or(Extension::Code(CodeExtension::Ts))) + "ts" if ext.iter().any(|e| matches!(e, Extension::Video(_))) => { + verify_magic_bytes(VideoExtension::Ts, file) + .await + .map_or(Some(Extension::Code(CodeExtension::Ts)), |video_ext| { + Some(Extension::Video(video_ext)) + }) + } + "mts" if ext.iter().any(|e| matches!(e, Extension::Video(_))) => { + verify_magic_bytes(VideoExtension::Mts, file) + .await + .map_or(Some(Extension::Code(CodeExtension::Mts)), |video_ext| { + Some(Extension::Video(video_ext)) + }) } _ => None, }, diff --git a/interface/app/$libraryId/Explorer/ContextMenu/FilePath/Items.tsx b/interface/app/$libraryId/Explorer/ContextMenu/FilePath/Items.tsx index c007c9efe..ccab5d446 100644 --- a/interface/app/$libraryId/Explorer/ContextMenu/FilePath/Items.tsx +++ b/interface/app/$libraryId/Explorer/ContextMenu/FilePath/Items.tsx @@ -140,7 +140,7 @@ export const ParentFolderActions = ({ { try { - await fullRescan.mutateAsync(locationId); + await fullRescan.mutateAsync({ location_id: locationId, reidentify_objects: false }); } catch (error) { showAlertDialog({ title: 'Error', diff --git a/interface/app/$libraryId/Explorer/ParentContextMenu.tsx b/interface/app/$libraryId/Explorer/ParentContextMenu.tsx index dfba955ff..9ffadfa4c 100644 --- a/interface/app/$libraryId/Explorer/ParentContextMenu.tsx +++ b/interface/app/$libraryId/Explorer/ParentContextMenu.tsx @@ -52,7 +52,7 @@ export default (props: PropsWithChildren) => { { try { - await rescanLocation.mutateAsync(parent.location.id); + await rescanLocation.mutateAsync({ location_id: parent.location.id, reidentify_objects: false }); } catch (error) { showAlertDialog({ title: 'Error', diff --git a/interface/app/$libraryId/location/LocationOptions.tsx b/interface/app/$libraryId/location/LocationOptions.tsx index 96a73eb44..7474df65e 100644 --- a/interface/app/$libraryId/location/LocationOptions.tsx +++ b/interface/app/$libraryId/location/LocationOptions.tsx @@ -73,7 +73,7 @@ export default function LocationOptions({ location, path }: { location: Location - scanLocation.mutate(location.id)}> + scanLocation.mutate({ location_id: location.id, reidentify_objects: false })}> Re-index diff --git a/interface/app/$libraryId/settings/library/locations/$id.tsx b/interface/app/$libraryId/settings/library/locations/$id.tsx index 8188b27cb..b20bb1650 100644 --- a/interface/app/$libraryId/settings/library/locations/$id.tsx +++ b/interface/app/$libraryId/settings/library/locations/$id.tsx @@ -228,7 +228,7 @@ const EditLocationForm = () => {