• Adds a track to the user's Spotify library

    Parameters

    • trackId: string

      Spotify track ID to add

    • silent: boolean = false

      Whether to suppress error logs

    Returns Promise<boolean>

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