From e13f9189dfa9921c854034e3761e5f829290ff29 Mon Sep 17 00:00:00 2001 From: snusxd Date: Tue, 14 Apr 2026 13:02:03 +0300 Subject: [PATCH] fix: update download_image_from_itunes function to accept safe artist and album parameters --- src/download_cover.ts | 16 +++++++++------- src/index.ts | 5 +++-- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/download_cover.ts b/src/download_cover.ts index b92abf8..7c1e2e2 100644 --- a/src/download_cover.ts +++ b/src/download_cover.ts @@ -49,18 +49,20 @@ export async function itunes_cover_url(artist: string, album: string) { } export async function download_image_from_itunes( - artist: string, - album: string, + rawArtist: string, + rawAlbum: string, + safeArtist: string, + safeAlbum: string, ) { - console.log("[DEBUG]: download_image_from_itunes:", artist, album); + console.log("[DEBUG]: download_image_from_itunes:", rawArtist, rawAlbum); try { - const itunes_url = await itunes_cover_url(artist, album); + const itunes_url = await itunes_cover_url(rawArtist, rawAlbum); if (!itunes_url) { - throw new Error(`iTunes URL not found for ${artist} - ${album}`); + throw new Error(`iTunes URL not found for ${rawArtist} - ${rawAlbum}`); } - const artist_dir = `public/covers/itunes/${artist}`; + const artist_dir = `public/covers/itunes/${safeArtist}`; if (!fs.existsSync(artist_dir)) { fs.mkdirSync(artist_dir, { recursive: true }); } @@ -69,7 +71,7 @@ export async function download_image_from_itunes( responseType: "arraybuffer", }); - fs.writeFileSync(`${artist_dir}/${album}.png`, img_response.data); + fs.writeFileSync(`${artist_dir}/${safeAlbum}.png`, img_response.data); } catch (error) { console.error("Error fetching data:", error); throw error; diff --git a/src/index.ts b/src/index.ts index a048dbf..2ad7582 100644 --- a/src/index.ts +++ b/src/index.ts @@ -46,11 +46,12 @@ async function get_image_from_server( resultFilePath = iTunesFilePath; } else { try { - await download_image_from_itunes(artist, album); + await download_image_from_itunes(artist, album, safeArtist, safeAlbum); resultFilePath = iTunesFilePath; } catch (first_error) { try { - if (safeMbid && safeMbid != "0") await download_image_from_caa(mbid); + if (safeMbid && safeMbid != "0") + await download_image_from_caa(safeMbid); else throw first_error; resultFilePath = MBFilePath; } catch (secong_error) {