refactor: streamline media scanning process for videos and photos

- Simplified the scanning logic to handle all file types in a single glob pattern, improving efficiency.
- Implemented case-insensitive filtering for video and photo files based on their extensions, enhancing media detection accuracy.
- Refactored code for better readability and maintainability.
This commit is contained in:
tigeren 2025-08-27 17:12:32 +00:00
parent 22e94264ee
commit fcf2b19c80
2 changed files with 17 additions and 14 deletions

BIN
media.db

Binary file not shown.

View File

@ -34,21 +34,24 @@ const generatePhotoThumbnail = (photoPath: string, thumbnailPath: string) => {
}; };
const scanLibrary = async (library: { id: number; path: string }) => { const scanLibrary = async (library: { id: number; path: string }) => {
// Scan videos - handle case variations // Scan videos - handle all case variations
const videoPatterns = VIDEO_EXTENSIONS.flatMap(ext => [ const videoFiles = await glob(`${library.path}/**/*.*`, { nodir: true });
`${library.path}/**/*.${ext}`,
`${library.path}/**/*.${ext.toUpperCase()}`, // Scan photos - handle all case variations
]); const photoFiles = await glob(`${library.path}/**/*.*`, { nodir: true });
const videoFiles = await glob(videoPatterns, { nodir: true });
// Filter files by extension (case-insensitive)
const filteredVideoFiles = videoFiles.filter(file => {
const ext = path.extname(file).toLowerCase().replace('.', '');
return VIDEO_EXTENSIONS.includes(ext);
});
const filteredPhotoFiles = photoFiles.filter(file => {
const ext = path.extname(file).toLowerCase().replace('.', '');
return PHOTO_EXTENSIONS.includes(ext);
});
// Scan photos - handle case variations const allFiles = [...filteredVideoFiles, ...filteredPhotoFiles];
const photoPatterns = PHOTO_EXTENSIONS.flatMap(ext => [
`${library.path}/**/*.${ext}`,
`${library.path}/**/*.${ext.toUpperCase()}`,
]);
const photoFiles = await glob(photoPatterns, { nodir: true });
const allFiles = [...videoFiles, ...photoFiles];
for (const file of allFiles) { for (const file of allFiles) {
const stats = fs.statSync(file); const stats = fs.statSync(file);