From 2b71a30f60bd8af4b75b2917df220f591bd77581 Mon Sep 17 00:00:00 2001 From: NextFire Date: Thu, 29 Aug 2024 20:29:48 +0200 Subject: [PATCH] fix: close unused fetch responses --- music-rpc.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/music-rpc.ts b/music-rpc.ts index 0fd858d..8249948 100755 --- a/music-rpc.ts +++ b/music-rpc.ts @@ -36,7 +36,7 @@ async function main(rpc: Client) { } } catch (err) { console.error("Error in main loop:", err); - await rpc.close(); // Ensure the connection is properly closed + rpc.close(); // Ensure the connection is properly closed console.log("Attempting to reconnect..."); await sleep(DEFAULT_TIMEOUT); // wait before attempting to reconnect @@ -113,7 +113,7 @@ async function _getTrackExtras( if (!resp.ok) { console.error("iTunes API error:", resp.statusText, url); - + await resp.body?.cancel(); return { artworkUrl: (await _getMBArtwork(artist, song, album)) ?? null, iTunesUrl: null, @@ -188,8 +188,10 @@ async function _getMBArtwork( for (const release of json.releases) { resp = await fetch( - `https://coverartarchive.org/release/${release.id}/front` + `https://coverartarchive.org/release/${release.id}/front`, + { method: "HEAD" } ); + await resp.body?.cancel(); if (resp.ok) { result = resp.url; break;