fixed filename length exceeding limit

This commit is contained in:
Daniel Sommer 2017-03-29 16:17:10 +02:00
parent dcd91ce8bf
commit f04fb9209e
2 changed files with 11 additions and 4 deletions

View file

@ -128,10 +128,17 @@ function getPathByMetadata(source, output, metadata, callback) {
if (metadata.title) {
fileName += metadata.title.trim();
}
// append extension
fileName += path.extname(source).trim();
// check length of filename, append extension and replace illegal chars
const ext = path.extname(source).trim();
const max = (255 - ext.length);
fileName = fileName.trim();
if (fileName.length > max) {
const suffix = ' (...)';
fileName = fileName.substr(0, max - suffix.length).trim() + suffix;
}
fileName = replaceIllegalChars(fileName + ext);
// replace illegal chars, join directory and name
callback(null, path.join(filePath, replaceIllegalChars(fileName)));
callback(null, path.join(filePath, fileName));
}
// fill a string beginning from the front

View file

@ -1,6 +1,6 @@
{
"name": "badger-am",
"version": "0.7.0",
"version": "0.7.1",
"license": "MIT",
"description": "audio manager",
"author": "Daniel Sommer <daniel.sommer@velvettear.de>",