Update fetchers to support search

This commit is contained in:
jeffvli 2023-06-09 02:36:38 -07:00 committed by Jeff
parent 01608fa875
commit f8ecb3fc53
8 changed files with 69 additions and 38 deletions

View file

@ -5,7 +5,7 @@ import type {
InternetProviderLyricSearchResponse,
LyricSearchQuery,
} from '/@/renderer/api/types';
import { LyricSource } from '../../../../renderer/types';
import { LyricSource } from '../../../../renderer/api/types';
const SEARCH_URL = 'https://genius.com/api/search/song';
@ -117,7 +117,7 @@ async function getSongURL(params: LyricSearchQuery): Promise<GeniusResponse | un
};
}
async function getLyricsFromGenius(url: string): Promise<string | null> {
export async function getLyricsByURL(url: string): Promise<string | null> {
let result: AxiosResponse<string, any>;
try {
result = await axios.get<string>(url, { responseType: 'text' });
@ -147,7 +147,7 @@ export async function query(
return null;
}
const lyrics = await getLyricsFromGenius(response.url);
const lyrics = await getLyricsByURL(response.url);
if (!lyrics) {
console.error('Could not get lyrics on Genius!');
return null;