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) { if (metadata.title) {
fileName += metadata.title.trim(); fileName += metadata.title.trim();
} }
// append extension // check length of filename, append extension and replace illegal chars
fileName += path.extname(source).trim(); 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 // 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 // fill a string beginning from the front

View file

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