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

@ -237,6 +237,13 @@ export default {
.leftJoin('user', 'user.id', 'favorites.user_id') .leftJoin('user', 'user.id', 'favorites.user_id')
.leftJoin('user_options', 'user_options.user_id', 'favorites.user_id') .leftJoin('user_options', 'user_options.user_id', 'favorites.user_id')
.where('favorites.item_id', itemid); .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 = { const data = {
success: true, success: true,
@ -252,7 +259,7 @@ export default {
short: url.parse(actitem.src).hostname, short: url.parse(actitem.src).hostname,
}, },
thumbnail: `${cfg.websrv.paths.thumbnails}/${actitem.id}.png`, 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}`, dest: `${cfg.websrv.paths.images}/${actitem.dest}`,
mime: actitem.mime, mime: actitem.mime,
size: lib.formatSize(actitem.size), size: lib.formatSize(actitem.size),