feat: improve media type detection and scanning functionality
- Enhanced media type detection by normalizing file extensions to handle case variations for videos and photos. - Updated the scanning process to accommodate different case formats for video and photo file extensions, improving accuracy in file recognition. - Refactored related code for better readability and maintainability.
This commit is contained in:
parent
90fe3c8fb9
commit
22e94264ee
|
|
@ -31,9 +31,10 @@ export async function GET(request: Request) {
|
||||||
const ext = path.extname(file).toLowerCase();
|
const ext = path.extname(file).toLowerCase();
|
||||||
|
|
||||||
let type = 'file';
|
let type = 'file';
|
||||||
if (VIDEO_EXTENSIONS.some(v => ext.includes(v))) {
|
const cleanExt = ext.replace('.', '').toLowerCase();
|
||||||
|
if (VIDEO_EXTENSIONS.some(v => v.toLowerCase() === cleanExt)) {
|
||||||
type = 'video';
|
type = 'video';
|
||||||
} else if (PHOTO_EXTENSIONS.some(p => ext.includes(p))) {
|
} else if (PHOTO_EXTENSIONS.some(p => p.toLowerCase() === cleanExt)) {
|
||||||
type = 'photo';
|
type = 'photo';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,15 +34,19 @@ const generatePhotoThumbnail = (photoPath: string, thumbnailPath: string) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const scanLibrary = async (library: { id: number; path: string }) => {
|
const scanLibrary = async (library: { id: number; path: string }) => {
|
||||||
// Scan videos
|
// Scan videos - handle case variations
|
||||||
const videoFiles = await glob(`${library.path}/**/*.{${VIDEO_EXTENSIONS.join(",")}}`, {
|
const videoPatterns = VIDEO_EXTENSIONS.flatMap(ext => [
|
||||||
nodir: true,
|
`${library.path}/**/*.${ext}`,
|
||||||
});
|
`${library.path}/**/*.${ext.toUpperCase()}`,
|
||||||
|
]);
|
||||||
|
const videoFiles = await glob(videoPatterns, { nodir: true });
|
||||||
|
|
||||||
// Scan photos
|
// Scan photos - handle case variations
|
||||||
const photoFiles = await glob(`${library.path}/**/*.{${PHOTO_EXTENSIONS.join(",")}}`, {
|
const photoPatterns = PHOTO_EXTENSIONS.flatMap(ext => [
|
||||||
nodir: true,
|
`${library.path}/**/*.${ext}`,
|
||||||
});
|
`${library.path}/**/*.${ext.toUpperCase()}`,
|
||||||
|
]);
|
||||||
|
const photoFiles = await glob(photoPatterns, { nodir: true });
|
||||||
|
|
||||||
const allFiles = [...videoFiles, ...photoFiles];
|
const allFiles = [...videoFiles, ...photoFiles];
|
||||||
|
|
||||||
|
|
@ -50,8 +54,9 @@ const scanLibrary = async (library: { id: number; path: string }) => {
|
||||||
const stats = fs.statSync(file);
|
const stats = fs.statSync(file);
|
||||||
const title = path.basename(file);
|
const title = path.basename(file);
|
||||||
const ext = path.extname(file).toLowerCase();
|
const ext = path.extname(file).toLowerCase();
|
||||||
const isVideo = VIDEO_EXTENSIONS.some(v => ext.includes(v));
|
const cleanExt = ext.replace('.', '').toLowerCase();
|
||||||
const isPhoto = PHOTO_EXTENSIONS.some(p => ext.includes(p));
|
const isVideo = VIDEO_EXTENSIONS.some(v => v.toLowerCase() === cleanExt);
|
||||||
|
const isPhoto = PHOTO_EXTENSIONS.some(p => p.toLowerCase() === cleanExt);
|
||||||
|
|
||||||
const mediaType = isVideo ? "video" : "photo";
|
const mediaType = isVideo ? "video" : "photo";
|
||||||
const thumbnailFileName = `${path.parse(title).name}_${Date.now()}.png`;
|
const thumbnailFileName = `${path.parse(title).name}_${Date.now()}.png`;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue