🐛 Fixed non-existing file with preferred width

…use original image as fallback
This commit is contained in:
Jan Andrle 2024-06-18 16:52:06 +02:00
parent de3f93e1eb
commit 0868374471
Signed by: jaandrle
GPG Key ID: B3A25AED155AFFAB

View File

@ -9,7 +9,7 @@ const path_home= $.xdg.home`Obrázky/Bing Image Of The Day/`;
const path_info= join(path_home, "images.json"); const path_info= join(path_home, "images.json");
$.api() $.api()
.version("2024-05-12") .version("2024-06-17")
.command("pull", "Pull new/today image(s)") .command("pull", "Pull new/today image(s)")
.action(async function pull(){ .action(async function pull(){
const images= { const images= {
@ -90,14 +90,19 @@ async function getImagePath(shift= 0){
* */ * */
return { return {
caption: caption, caption: caption,
url: url_image+encodeURI(filepath+img_params) url: url_image+encodeURI(filepath)
}; };
} }
/** @param {T_response} image @param {"prev"|"now"} type */ /** @param {T_response} image @param {"prev"|"now"} type */
async function downloadImage({ url }, type){ async function downloadImage({ url }, type){
const filename= join(path_home, `${type}.jpg`); 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(); const buffer= await response.arrayBuffer();
writeFileSync(filename, Buffer.from(buffer)); writeFileSync(filename, Buffer.from(buffer));
return filename; return filename;