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:
parent
22e94264ee
commit
fcf2b19c80
|
|
@ -34,21 +34,24 @@ const generatePhotoThumbnail = (photoPath: string, thumbnailPath: string) => {
|
|||
};
|
||||
|
||||
const scanLibrary = async (library: { id: number; path: string }) => {
|
||||
// Scan videos - handle case variations
|
||||
const videoPatterns = VIDEO_EXTENSIONS.flatMap(ext => [
|
||||
`${library.path}/**/*.${ext}`,
|
||||
`${library.path}/**/*.${ext.toUpperCase()}`,
|
||||
]);
|
||||
const videoFiles = await glob(videoPatterns, { nodir: true });
|
||||
// Scan videos - handle all case variations
|
||||
const videoFiles = await glob(`${library.path}/**/*.*`, { nodir: true });
|
||||
|
||||
// Scan photos - handle case variations
|
||||
const photoPatterns = PHOTO_EXTENSIONS.flatMap(ext => [
|
||||
`${library.path}/**/*.${ext}`,
|
||||
`${library.path}/**/*.${ext.toUpperCase()}`,
|
||||
]);
|
||||
const photoFiles = await glob(photoPatterns, { nodir: true });
|
||||
// Scan photos - handle all case variations
|
||||
const photoFiles = await glob(`${library.path}/**/*.*`, { nodir: true });
|
||||
|
||||
const allFiles = [...videoFiles, ...photoFiles];
|
||||
// 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);
|
||||
});
|
||||
|
||||
const allFiles = [...filteredVideoFiles, ...filteredPhotoFiles];
|
||||
|
||||
for (const file of allFiles) {
|
||||
const stats = fs.statSync(file);
|
||||
|
|
|
|||
Loading…
Reference in New Issue