check if cover art exists

This commit is contained in:
Flummi 2022-01-07 18:51:18 +01:00
parent e3ae7fe475
commit 2e013317a5

View File

@ -238,6 +238,13 @@ export default {
.leftJoin('user_options', 'user_options.user_id', 'favorites.user_id')
.where('favorites.item_id', itemid);
let coverart = true;
try {
await fs.promises.access(`./public${cfg.websrv.paths.coverarts}/${actitem.id}.webp`);
} catch(err) {
coverart = false;
}
const data = {
success: true,
user: {
@ -252,7 +259,7 @@ export default {
short: url.parse(actitem.src).hostname,
},
thumbnail: `${cfg.websrv.paths.thumbnails}/${actitem.id}.png`,
coverart: `${cfg.websrv.paths.coverarts}/${actitem.id}.webp`,
coverart: coverart ? `${cfg.websrv.paths.coverarts}/${actitem.id}.webp` : '/s/img/music.webp',
dest: `${cfg.websrv.paths.images}/${actitem.dest}`,
mime: actitem.mime,
size: lib.formatSize(actitem.size),