diff --git a/lib/Service/Index.php b/lib/Service/Index.php index 6c337c6b..68667bef 100644 --- a/lib/Service/Index.php +++ b/lib/Service/Index.php @@ -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); diff --git a/lib/Settings/SystemConfig.php b/lib/Settings/SystemConfig.php index 2fffa1af..246da833 100644 --- a/lib/Settings/SystemConfig.php +++ b/lib/Settings/SystemConfig.php @@ -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 diff --git a/src/components/admin/sections/Indexing.vue b/src/components/admin/sections/Indexing.vue index 518af881..7690fa19 100644 --- a/src/components/admin/sections/Indexing.vue +++ b/src/components/admin/sections/Indexing.vue @@ -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 ".")`) }}