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",
"version": "0.5.0",
"version": "0.6.0",
"main": "index.js",
"repository": "https://github.com/aengl/publikator.git",
"author": "Lynn Smeria <ae@cephea.de>",

View file

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