feat(indexing): allow to ignore dot and at starting files while indexing when wanted

pull/1015/head
Saninn Salas Diaz 2024-01-23 09:16:53 +01:00
parent f042e1820c
commit 1a0aa8917e
3 changed files with 33 additions and 4 deletions

View File

@ -108,6 +108,31 @@ class Index
}
}
public function resolveValidFiles(array $nodes, array $mimes): array
{
return array_filter($nodes, static function ($node) use ($mimes) {
if (!$node instanceof File) {
return false;
}
if (!\in_array($node->getMimeType(), $mimes, true)) {
return false;
}
$fistChar = mb_substr($node->getName(), 0, 1);
if (SystemConfig::get('memories.index.ignore_file_with_starting_dot') && '.' === $fistChar) {
return false;
}
if (SystemConfig::get('memories.index.ignore_file_with_starting_at') && '@' === $fistChar) {
return false;
}
return true;
});
}
/**
* Index all files in a folder.
*
@ -129,7 +154,8 @@ class Index
// Filter files that are supported
$mimes = self::getMimeList();
$files = array_filter($nodes, static fn ($n) => $n instanceof File && \in_array($n->getMimeType(), $mimes, true));
$files = self::resolveValidFiles($nodes, $mimes);
// Create an associative array with file ID as key
$files = array_combine(array_map(static fn ($n) => $n->getId(), $files), $files);

View File

@ -33,8 +33,11 @@ class SystemConfig
// Path to index (only used if indexing mode is 3)
'memories.index.path' => '/',
'memories.index.ignore_file_with_starting_dot' => false,
// To not index hidden files
'memories.index.ignore_file_with_starting_dot' => true,
// Some NAS use `@Recyle` to store deleted folders and files.
'memories.index.ignore_file_with_starting_at' => false,
// Places database type identifier

View File

@ -125,7 +125,7 @@
@update:checked="update('memories.index.ignore_file_with_starting_dot')"
type="switch"
>
{{ t('memories', `Ignore files and folders starting with "."`) }}
{{ t('memories', `Ignore Hidden files and folders (starting with ".")`) }}
</NcCheckboxRadioSwitch>