From 086837447145ab20518ba5010fc83f8717937a8c Mon Sep 17 00:00:00 2001 From: Jan Andrle Date: Tue, 18 Jun 2024 16:52:06 +0200 Subject: [PATCH] :bug: Fixed non-existing file with preferred width MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …use original image as fallback --- bin/§wallpaper_WCPOTD.mjs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/bin/§wallpaper_WCPOTD.mjs b/bin/§wallpaper_WCPOTD.mjs index e8a2299..f4f058f 100755 --- a/bin/§wallpaper_WCPOTD.mjs +++ b/bin/§wallpaper_WCPOTD.mjs @@ -9,7 +9,7 @@ const path_home= $.xdg.home`Obrázky/Bing Image Of The Day/`; const path_info= join(path_home, "images.json"); $.api() -.version("2024-05-12") +.version("2024-06-17") .command("pull", "Pull new/today image(s)") .action(async function pull(){ const images= { @@ -90,14 +90,19 @@ async function getImagePath(shift= 0){ * */ return { caption: caption, - url: url_image+encodeURI(filepath+img_params) + url: url_image+encodeURI(filepath) }; } /** @param {T_response} image @param {"prev"|"now"} type */ async function downloadImage({ url }, type){ const filename= join(path_home, `${type}.jpg`); - const response= await fetch(url); + let response= await fetch(url+img_params); + if(response.status!==200){ + response= await fetch(url); + if(response.status!==200) + throw new Error(`Failed to download image: ${response.status} ${response.statusText}`); + } const buffer= await response.arrayBuffer(); writeFileSync(filename, Buffer.from(buffer)); return filename;