mirror of
https://github.com/xtrll/MusicMetaFinder.git
synced 2026-04-17 15:53:29 +02:00
refactor: update jsdoc comments and optimize promise handling
This commit is contained in:
@@ -4,19 +4,19 @@ import recognizeAudio from '../../api/recognition/auddApi.js';
|
||||
* Recognizes a list of audio files.
|
||||
*
|
||||
* @param {string[]} audioFiles An array of file paths of the audio files.
|
||||
* @return {Promise<Object[]>} A promise that resolves to an array of recognition results.
|
||||
* @return {Promise<(Object|null)[]>} A promise that resolves to an array of recognition result objects or null values for each file.
|
||||
*/
|
||||
export default async function recognizeAudioFiles(audioFiles) {
|
||||
const recognitionPromises = audioFiles.map((filePath) => recognizeAudio(filePath)
|
||||
.catch((error) => {
|
||||
// Log the error and return null
|
||||
// This prevents one failed recognition from stopping the whole process
|
||||
console.error(`Recognition failed for file ${filePath}:`, error);
|
||||
return null;
|
||||
}));
|
||||
const recognitionPromises = audioFiles.map(filePath =>
|
||||
recognizeAudio(filePath)
|
||||
.catch(error => {
|
||||
// Log the error and return null for this file.
|
||||
// This prevents one failed recognition from stopping the whole process
|
||||
console.error(`Recognition failed for file ${filePath}:`, error);
|
||||
return null;
|
||||
})
|
||||
);
|
||||
|
||||
// Wait for all recognitions to resolve. This will be an array of results or null values
|
||||
const recognizedAudioFiles = await Promise.all(recognitionPromises);
|
||||
// Filter out unsuccessful recognitions
|
||||
return recognizedAudioFiles.filter((result) => result !== null);
|
||||
// Wait for all recognitions to resolve. This will be an array of results or null values for each audio file.
|
||||
return Promise.all(recognitionPromises);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user