[ENG-850] Wrongly labelled .ts files (as video) (#1052)

* Fixing conflits of mts code files showing as video

* Introducing a reidentify_objects param on fullRescan

* Fix job output metadata in case of completed with errors
This commit is contained in:
Ericson "Fogo" Soares 2023-06-28 23:58:33 -03:00 committed by GitHub
parent 2363fbac61
commit 9a6d88a096
12 changed files with 70 additions and 19 deletions

View File

@ -185,7 +185,7 @@ const EditLocationSettingsScreen = ({
<SettingsItem
title="Full Reindex"
rightArea={
<AnimatedButton size="sm" onPress={() => fullRescan.mutate(id)}>
<AnimatedButton size="sm" onPress={() => fullRescan.mutate({ location_id: id, reidentify_objects: true })}>
<ArrowsClockwise color="white" size={20} />
</AnimatedButton>
}

View File

@ -73,7 +73,7 @@ function LocationItem({ location, index, navigation }: LocationItemProps) {
{/* Full Re-scan IS too much here */}
<Pressable
style={tw`items-center justify-center rounded-md border border-app-line bg-app-button px-3 py-1.5 shadow-sm`}
onPress={() => fullRescan.mutate(location.id)}
onPress={() => fullRescan.mutate({ location_id: location.id, reidentify_objects: true })}
>
<Repeat size={18} color="white" />
</Pressable>

View File

@ -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<Ctx> {
})
})
.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::<Vec<_>>();
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,

View File

@ -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);

View File

@ -262,6 +262,7 @@ extension_category_enum! {
Swift,
Mdx,
Astro,
Mts,
}
}

View File

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

View File

@ -140,7 +140,7 @@ export const ParentFolderActions = ({
<ContextMenu.Item
onClick={async () => {
try {
await fullRescan.mutateAsync(locationId);
await fullRescan.mutateAsync({ location_id: locationId, reidentify_objects: false });
} catch (error) {
showAlertDialog({
title: 'Error',

View File

@ -52,7 +52,7 @@ export default (props: PropsWithChildren) => {
<CM.Item
onClick={async () => {
try {
await rescanLocation.mutateAsync(parent.location.id);
await rescanLocation.mutateAsync({ location_id: parent.location.id, reidentify_objects: false });
} catch (error) {
showAlertDialog({
title: 'Error',

View File

@ -73,7 +73,7 @@ export default function LocationOptions({ location, path }: { location: Location
</PopoverSection>
<PopoverDivider />
<PopoverSection>
<OptionButton onClick={() => scanLocation.mutate(location.id)}>
<OptionButton onClick={() => scanLocation.mutate({ location_id: location.id, reidentify_objects: false })}>
<FolderDotted />
Re-index
</OptionButton>

View File

@ -228,7 +228,7 @@ const EditLocationForm = () => {
<FlexCol>
<div>
<Button
onClick={() => fullRescan.mutate(locationId)}
onClick={() => fullRescan.mutate({ location_id: locationId, reidentify_objects: true })}
size="sm"
variant="outline"
>

View File

@ -89,7 +89,7 @@ export default ({ location }: Props) => {
onClick={(e: { stopPropagation: () => void }) => {
e.stopPropagation();
// this should cause a lite directory rescan, but this will do for now, so the button does something useful
fullRescan.mutate(location.id);
fullRescan.mutate({ location_id: location.id, reidentify_objects: false });
}}
>
<Tooltip label="Rescan Location">

View File

@ -52,7 +52,7 @@ export type Procedures = {
{ key: "locations.addLibrary", input: LibraryArgs<LocationCreateArgs>, result: null } |
{ key: "locations.create", input: LibraryArgs<LocationCreateArgs>, result: null } |
{ key: "locations.delete", input: LibraryArgs<number>, result: null } |
{ key: "locations.fullRescan", input: LibraryArgs<number>, result: null } |
{ key: "locations.fullRescan", input: LibraryArgs<FullRescanArgs>, result: null } |
{ key: "locations.indexer_rules.create", input: LibraryArgs<IndexerRuleCreateArgs>, result: null } |
{ key: "locations.indexer_rules.delete", input: LibraryArgs<number>, result: null } |
{ key: "locations.relink", input: LibraryArgs<string>, result: null } |
@ -117,6 +117,8 @@ export type FilePathWithObject = { id: number; pub_id: number[]; is_dir: boolean
export type FromPattern = { pattern: string; replace_all: boolean }
export type FullRescanArgs = { location_id: number; reidentify_objects: boolean }
export type GenerateThumbsForLocationArgs = { id: number; path: string }
export type GetArgs = { id: number }