From f04fb9209e07d151289c8b92fcfb8041b935b607 Mon Sep 17 00:00:00 2001 From: velvettear Date: Wed, 29 Mar 2017 16:17:10 +0200 Subject: [PATCH] fixed filename length exceeding limit --- lib/util.js | 13 ++++++++++--- package.json | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/util.js b/lib/util.js index cf70cb5..caaad70 100644 --- a/lib/util.js +++ b/lib/util.js @@ -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 diff --git a/package.json b/package.json index 29c0947..de753ae 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "badger-am", - "version": "0.7.0", + "version": "0.7.1", "license": "MIT", "description": "audio manager", "author": "Daniel Sommer ",