Skip to content

Commit

Permalink
chore: make linter parse
Browse files Browse the repository at this point in the history
  • Loading branch information
sofushn committed Sep 7, 2024
1 parent af63915 commit b977b2f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
8 changes: 4 additions & 4 deletions src/services/get-songs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default class {
}

async getSongs(query: string, playlistLimit: number, shouldSplitChapters: boolean): Promise<[SongMetadata[], string]> {
let newSongs: SongMetadata[] = [];
const newSongs: SongMetadata[] = [];
let extraMsg = '';

// Test if it's a complete URL
Expand Down Expand Up @@ -49,7 +49,7 @@ export default class {
}
} else if (url.protocol === 'spotify:' || url.host === 'open.spotify.com') {
if (this.spotifyAPI === undefined) {
throw new Error('Spotify is not enabled!')
throw new Error('Spotify is not enabled!');
}

const [convertedSongs, nSongsNotFound, totalSongs] = await this.spotifySource(query, playlistLimit, shouldSplitChapters);
Expand Down Expand Up @@ -81,7 +81,7 @@ export default class {
}
}
} catch (err: any) {
if (err = 'spotify not enabled') {
if (err.message === 'Spotify is not enabled!') {

Check failure on line 84 in src/services/get-songs.ts

View workflow job for this annotation

GitHub Actions / Lint

Unsafe member access .message on an `any` value
throw err;
}

Expand Down Expand Up @@ -112,7 +112,7 @@ export default class {

private async spotifySource(url: string, playlistLimit: number, shouldSplitChapters: boolean): Promise<[SongMetadata[], number, number]> {
if (this.spotifyAPI === undefined) {
return [[], 0, 0];
return [[], 0, 0];
}

const parsed = spotifyURI.parse(url);
Expand Down
17 changes: 6 additions & 11 deletions src/utils/get-youtube-and-spotify-suggestions-for.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@ const filterDuplicates = <T extends {name: string}>(items: T[]) => {
};

const getYouTubeAndSpotifySuggestionsFor = async (query: string, spotify?: SpotifyWebApi, limit = 10): Promise<APIApplicationCommandOptionChoice[]> => {

// Only search Spotify if enabled
let spotifySuggestionPromise = spotify !== undefined
const spotifySuggestionPromise = spotify !== undefined

Check failure on line 19 in src/utils/get-youtube-and-spotify-suggestions-for.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected negated condition
? spotify.search(query, ['album', 'track'], {limit})
: undefined;

const youtubeSuggestions = await getYouTubeSuggestionsFor(query);

const totalYouTubeResults = youtubeSuggestions.length;
Expand All @@ -36,11 +35,9 @@ const getYouTubeAndSpotifySuggestionsFor = async (query: string, spotify?: Spoti
value: suggestion,
}),
));



if (spotify !== undefined && spotifySuggestionPromise !== undefined) {

const spotifyResponse = (await spotifySuggestionPromise).body
const spotifyResponse = (await spotifySuggestionPromise).body;
const spotifyAlbums = filterDuplicates(spotifyResponse.albums?.items ?? []);
const spotifyTracks = filterDuplicates(spotifyResponse.tracks?.items ?? []);

Expand All @@ -51,22 +48,21 @@ const getYouTubeAndSpotifySuggestionsFor = async (query: string, spotify?: Spoti
const maxSpotifySuggestions = Math.floor(limit / 2);
const numOfSpotifySuggestions = Math.min(maxSpotifySuggestions, totalSpotifyResults);


const maxSpotifyAlbums = Math.floor(numOfSpotifySuggestions / 2);
const numOfSpotifyAlbums = Math.min(maxSpotifyAlbums, spotifyResponse.albums?.items.length ?? 0);
const maxSpotifyTracks = numOfSpotifySuggestions - numOfSpotifyAlbums;

// make room for spotify results

Check failure on line 55 in src/utils/get-youtube-and-spotify-suggestions-for.ts

View workflow job for this annotation

GitHub Actions / Lint

Comments should not begin with a lowercase character
const maxYouTubeSuggestions = limit - numOfSpotifySuggestions;
suggestions = suggestions.slice(0, maxYouTubeSuggestions)
suggestions = suggestions.slice(0, maxYouTubeSuggestions);

suggestions.push(
...spotifyAlbums.slice(0, maxSpotifyAlbums).map(album => ({
name: `Spotify: 💿 ${album.name}${album.artists.length > 0 ? ` - ${album.artists[0].name}` : ''}`,
value: `spotify:album:${album.id}`,
})),
);

suggestions.push(
...spotifyTracks.slice(0, maxSpotifyTracks).map(track => ({
name: `Spotify: 🎵 ${track.name}${track.artists.length > 0 ? ` - ${track.artists[0].name}` : ''}`,
Expand All @@ -75,7 +71,6 @@ const getYouTubeAndSpotifySuggestionsFor = async (query: string, spotify?: Spoti
);

Check failure on line 71 in src/utils/get-youtube-and-spotify-suggestions-for.ts

View workflow job for this annotation

GitHub Actions / Lint

Block must not be padded by blank lines

}

return suggestions;

Check failure on line 74 in src/utils/get-youtube-and-spotify-suggestions-for.ts

View workflow job for this annotation

GitHub Actions / Lint

Expected blank line before this statement
};

Expand Down

0 comments on commit b977b2f

Please sign in to comment.