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();
|
||||
|
||||
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';
|
||||
} else if (PHOTO_EXTENSIONS.some(p => ext.includes(p))) {
|
||||
} else if (PHOTO_EXTENSIONS.some(p => p.toLowerCase() === cleanExt)) {
|
||||
type = 'photo';
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -34,15 +34,19 @@ const generatePhotoThumbnail = (photoPath: string, thumbnailPath: string) => {
|
|||
};
|
||||
|
||||
const scanLibrary = async (library: { id: number; path: string }) => {
|
||||
// Scan videos
|
||||
const videoFiles = await glob(`${library.path}/**/*.{${VIDEO_EXTENSIONS.join(",")}}`, {
|
||||
nodir: true,
|
||||
});
|
||||
// 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 photos
|
||||
const photoFiles = await glob(`${library.path}/**/*.{${PHOTO_EXTENSIONS.join(",")}}`, {
|
||||
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 });
|
||||
|
||||
const allFiles = [...videoFiles, ...photoFiles];
|
||||
|
||||
|
|
@ -50,8 +54,9 @@ const scanLibrary = async (library: { id: number; path: string }) => {
|
|||
const stats = fs.statSync(file);
|
||||
const title = path.basename(file);
|
||||
const ext = path.extname(file).toLowerCase();
|
||||
const isVideo = VIDEO_EXTENSIONS.some(v => ext.includes(v));
|
||||
const isPhoto = PHOTO_EXTENSIONS.some(p => ext.includes(p));
|
||||
const cleanExt = ext.replace('.', '').toLowerCase();
|
||||
const isVideo = VIDEO_EXTENSIONS.some(v => v.toLowerCase() === cleanExt);
|
||||
const isPhoto = PHOTO_EXTENSIONS.some(p => p.toLowerCase() === cleanExt);
|
||||
|
||||
const mediaType = isVideo ? "video" : "photo";
|
||||
const thumbnailFileName = `${path.parse(title).name}_${Date.now()}.png`;
|
||||
|
|
|
|||
Loading…
Reference in New Issue