Include cover path

This commit is contained in:
Lynn Smeria 2018-08-20 18:42:59 +02:00
parent 4e2c11aabb
commit 7c8138c386
2 changed files with 18 additions and 12 deletions

View file

@ -1,6 +1,6 @@
{ {
"name": "publikator", "name": "publikator",
"version": "0.5.0", "version": "0.6.0",
"main": "index.js", "main": "index.js",
"repository": "https://github.com/aengl/publikator.git", "repository": "https://github.com/aengl/publikator.git",
"author": "Lynn Smeria <ae@cephea.de>", "author": "Lynn Smeria <ae@cephea.de>",

View file

@ -19,17 +19,16 @@ const getFileName = file =>
const extractCoverArt = async filePath => { const extractCoverArt = async filePath => {
const pictures = await tags.extractCoverArt(filePath); const pictures = await tags.extractCoverArt(filePath);
if (pictures) { if (pictures) {
await Promise.all( const picture = pictures[0];
pictures.map(async picture => { const pictureExt = mime.extension(picture.format);
const pictureExt = mime.extension(picture.format); const picturePath = `${filePath.replace(
const picturePath = `${filePath.replace( path.extname(filePath),
path.extname(filePath), ''
'' )}.${pictureExt}`;
)}.${pictureExt}`; await fs.writeFile(picturePath, picture.data);
await fs.writeFile(picturePath, picture.data); return picturePath;
})
);
} }
return null;
}; };
module.exports = { module.exports = {
@ -70,7 +69,7 @@ module.exports = {
const fileName = getFileName(file); const fileName = getFileName(file);
const newPath = path.resolve(root, folderName, fileName); const newPath = path.resolve(root, folderName, fileName);
await fs.copyFile(file.path, newPath); await fs.copyFile(file.path, newPath);
await extractCoverArt(newPath); const coverPath = await extractCoverArt(newPath);
return _.assign( return _.assign(
{}, {},
{ {
@ -79,6 +78,13 @@ module.exports = {
folderName, folderName,
fileName, fileName,
}, },
coverPath
? {
coverPath,
relativeCoverPath: `${folderName}/${path.basename(coverPath)}`,
coverFileName: path.basename(coverPath),
}
: {},
_.omit(file, 'path') _.omit(file, 'path')
); );
}) })