- Fix WebDAV service to find all 4,101 MP3 files instead of 1,023 - Add support for AIFF files (.aif, .aiff) in audio detection - Update audioMetadataService to recognize AIFF formats - Simplify BackgroundJobProgress component polling logic - Add maxDepth parameter to WebDAV directory listing - Add comprehensive test scripts for debugging WebDAV integration The WebDAV integration now correctly processes all 4,257 audio files from the music collection, including 4,101 MP3 files and 156 other audio formats (FLAC, WAV, AIFF, M4A, OGG).
114 lines
4.4 KiB
JavaScript
114 lines
4.4 KiB
JavaScript
import { StorageProviderFactory } from './dist/services/storageProvider.js';
|
||
import { AudioMetadataService } from './dist/services/audioMetadataService.js';
|
||
|
||
async function testBackgroundJobFlow() {
|
||
try {
|
||
console.log('🔍 Testing Background Job Flow:');
|
||
console.log('');
|
||
|
||
// Step 1: Load config and create provider (same as background job)
|
||
console.log('1️⃣ Loading storage configuration...');
|
||
const config = await StorageProviderFactory.loadConfig();
|
||
console.log('Config provider:', config.provider);
|
||
console.log('Config basePath:', config.basePath);
|
||
console.log('');
|
||
|
||
// Step 2: Create storage service (same as background job)
|
||
console.log('2️⃣ Creating storage service...');
|
||
const storageService = await StorageProviderFactory.createProvider(config);
|
||
console.log('Storage service created:', storageService.constructor.name);
|
||
console.log('');
|
||
|
||
// Step 3: List all files (same as background job)
|
||
console.log('3️⃣ Listing all files from storage...');
|
||
const startTime = Date.now();
|
||
const storageFiles = await storageService.listAllFiles();
|
||
const endTime = Date.now();
|
||
console.log(`✅ listAllFiles completed in ${endTime - startTime}ms`);
|
||
console.log('Total storage files found:', storageFiles.length);
|
||
console.log('');
|
||
|
||
// Step 4: Filter for audio files (same as background job)
|
||
console.log('4️⃣ Filtering for audio files...');
|
||
const audioMetadataService = new AudioMetadataService();
|
||
|
||
const audioFiles = storageFiles.filter(storageFile => {
|
||
const filename = storageFile.key.split('/').pop() || storageFile.key;
|
||
const isAudio = audioMetadataService.isAudioFile(filename);
|
||
if (!isAudio) {
|
||
console.log(` ❌ Not audio: ${filename}`);
|
||
}
|
||
return isAudio;
|
||
});
|
||
|
||
console.log('Audio files found:', audioFiles.length);
|
||
console.log('');
|
||
|
||
// Step 5: Show breakdown by file type
|
||
console.log('5️⃣ File type breakdown:');
|
||
const fileTypes = new Map();
|
||
storageFiles.forEach(file => {
|
||
const filename = file.key.split('/').pop() || file.key;
|
||
const ext = filename.split('.').pop()?.toLowerCase() || 'no-extension';
|
||
fileTypes.set(ext, (fileTypes.get(ext) || 0) + 1);
|
||
});
|
||
|
||
const sortedTypes = Array.from(fileTypes.entries()).sort((a, b) => b[1] - a[1]);
|
||
sortedTypes.forEach(([ext, count]) => {
|
||
const isAudio = audioMetadataService.isAudioFile(`test.${ext}`);
|
||
const status = isAudio ? '🎵' : '📄';
|
||
console.log(` ${status} .${ext}: ${count} files`);
|
||
});
|
||
console.log('');
|
||
|
||
// Step 6: Show MP3 breakdown
|
||
console.log('6️⃣ MP3 files breakdown:');
|
||
const mp3Files = storageFiles.filter(file => {
|
||
const filename = file.key.split('/').pop() || file.key;
|
||
return filename.toLowerCase().endsWith('.mp3');
|
||
});
|
||
|
||
console.log('MP3 files found:', mp3Files.length);
|
||
|
||
// Show directory distribution of MP3 files
|
||
const mp3DirCounts = new Map();
|
||
mp3Files.forEach(file => {
|
||
const dir = file.key.split('/')[0];
|
||
mp3DirCounts.set(dir, (mp3DirCounts.get(dir) || 0) + 1);
|
||
});
|
||
|
||
const sortedMp3Dirs = Array.from(mp3DirCounts.entries()).sort((a, b) => b[1] - a[1]);
|
||
console.log('MP3 files by directory:');
|
||
sortedMp3Dirs.forEach(([dir, count]) => {
|
||
console.log(` 📁 ${dir}: ${count} MP3 files`);
|
||
});
|
||
console.log('');
|
||
|
||
// Step 7: Test with different prefixes (if WebDAV)
|
||
if (config.provider === 'webdav') {
|
||
console.log('7️⃣ Testing with different prefixes...');
|
||
const testPrefixes = ['', 'Gekocht', 'Merijn Music', 'Musica'];
|
||
for (const prefix of testPrefixes) {
|
||
try {
|
||
const prefixFiles = await storageService.listAllFiles(prefix);
|
||
const prefixMp3Files = prefixFiles.filter(file => {
|
||
const filename = file.key.split('/').pop() || file.key;
|
||
return filename.toLowerCase().endsWith('.mp3');
|
||
});
|
||
console.log(` 📁 Prefix "${prefix}": ${prefixFiles.length} total, ${prefixMp3Files.length} MP3`);
|
||
} catch (error) {
|
||
console.log(` ❌ Prefix "${prefix}": Error - ${error.message}`);
|
||
}
|
||
}
|
||
}
|
||
|
||
} catch (error) {
|
||
console.error('❌ Failed to test background job flow:', error);
|
||
console.error('Error details:', error.message);
|
||
console.error('Stack trace:', error.stack);
|
||
}
|
||
}
|
||
|
||
// Run the test
|
||
testBackgroundJobFlow().catch(console.error);
|