Spotify track ID to add
Whether to suppress error logs
Promise resolving to true if successful
export async function likeTrack(
trackId: string,
silent: boolean = false,
): Promise<boolean> {
await ensureValidToken();
try {
await retryApiCall(async () => {
await spotifyAxios.put(
`${API_BASE_URL}/me/tracks?ids=${trackId}`,
{},
{
headers: {
Authorization: `Bearer ${getAccessToken()}`,
},
},
);
});
if (!silent) {
saveLog(`Track ${trackId} saved to library`, "INFO");
}
return true;
} catch (error: unknown) {
const err = error as Error;
if (!silent) {
saveLog(`Failed to save track to library: ${err.message}`, "ERROR");
}
return false;
}
}
Adds a track to the user's Spotify library