Compare commits

..

3 Commits

Author SHA1 Message Date
tigeren caa0d1eab9 refactor: improve path handling in folder viewer
- Updated path splitting logic to retain leading slashes for absolute paths while filtering out empty segments.
- Enhanced parent path reconstruction to ensure correct navigation within the folder structure.
- Improved readability and maintainability of the path management code.
2025-08-27 17:16:45 +00:00
tigeren fcf2b19c80 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.
2025-08-27 17:12:32 +00:00
tigeren 22e94264ee 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.
2025-08-27 17:03:55 +00:00
4 changed files with 31 additions and 16 deletions

BIN
media.db

Binary file not shown.

View File

@ -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';
}

View File

@ -174,12 +174,18 @@ const FolderViewerPage = () => {
// Don't allow navigation above library root
if (currentPath === libraryRoot) return '';
const pathParts = currentPath.split('/').filter(part => part.length > 0);
// Split path but keep leading slash for absolute paths
const pathParts = currentPath.split('/');
const libraryParts = libraryRoot.split('/').filter(part => part.length > 0);
if (pathParts.length <= libraryParts.length) return '';
// Filter out empty parts but keep structure
const filteredPathParts = pathParts.filter(part => part.length > 0);
return pathParts.slice(0, -1).join('/');
if (filteredPathParts.length <= libraryParts.length) return '';
// Reconstruct absolute path
const parentParts = filteredPathParts.slice(0, -1);
return '/' + parentParts.join('/');
};
const handleBackClick = () => {

View File

@ -34,24 +34,32 @@ 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 all case variations
const videoFiles = await glob(`${library.path}/**/*.*`, { nodir: true });
// Scan photos - handle all case variations
const photoFiles = await glob(`${library.path}/**/*.*`, { 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
const photoFiles = await glob(`${library.path}/**/*.{${PHOTO_EXTENSIONS.join(",")}}`, {
nodir: true,
});
const allFiles = [...videoFiles, ...photoFiles];
const allFiles = [...filteredVideoFiles, ...filteredPhotoFiles];
for (const file of allFiles) {
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`;