mirror of
https://github.com/xtrll/MusicMetaFinder.git
synced 2026-04-17 21:54:09 +02:00
refactor: enhance jsdoc for clarity and improve error handling
This commit is contained in:
@@ -1,36 +1,27 @@
|
||||
import getSpotifyAccessToken from '../../api/spotifyAuthApi.js';
|
||||
import requestMetadata from '../../api/metadata/spotifyApi.js';
|
||||
import getLyrics from '../../api/metadata/lyricOvhApi.js';
|
||||
|
||||
/**
|
||||
* Adapter to handle retrieval of metadata for an array of Spotify track IDs.
|
||||
* @function
|
||||
* @param {string[]} trackIds - An array of spotify track IDs.
|
||||
* @returns {Promise<Object[]>} A promise that resolves with an object of metadata.
|
||||
* @async
|
||||
* @param {string[]} trackIds - An array of Spotify track IDs.
|
||||
* @returns {Promise<Object[]>} A promise that, when resolved, returns an array of metadata objects for the Spotify tracks.
|
||||
*/
|
||||
export default async function getMetadata(trackIds) {
|
||||
try {
|
||||
if (!Array.isArray(trackIds)) {
|
||||
throw new Error('spotifyAdapter expects an array of trackIds');
|
||||
throw new Error('getMetadata expects an array of trackIds');
|
||||
}
|
||||
|
||||
const accessToken = await getSpotifyAccessToken();
|
||||
|
||||
const metadataPromises = trackIds.map(async (trackId) => {
|
||||
const trackMetadata = await requestMetadata(trackId, accessToken);
|
||||
|
||||
// const lyrics = await getLyrics(artist, title);
|
||||
|
||||
// Combine the track metadata with the lyrics
|
||||
return {
|
||||
...trackMetadata,
|
||||
// lyrics
|
||||
};
|
||||
});
|
||||
const metadataPromises = trackIds.map(trackId => requestMetadata(trackId, accessToken));
|
||||
|
||||
// Resolves to an array of metadata objects corresponding to the track IDs.
|
||||
return await Promise.all(metadataPromises);
|
||||
} catch (e) {
|
||||
console.error('Error retrieving metadata using Spotify:', e);
|
||||
throw e;
|
||||
console.error('Error retrieving metadata from Spotify:', e);
|
||||
throw e; // Rethrowing the error to handle it at a higher level
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user