Calculating filename component limit in bytes rather than characters, preventing 'filename too long' errors when e.g. emojis are used

This commit is contained in:
ThePendulum 2018-07-07 00:37:10 +02:00
parent 263525c320
commit 6c15d2e88b
1 changed files with 3 additions and 2 deletions

View File

@ -3,11 +3,12 @@
const config = require('config');
const fs = require('fs-extra');
const path = require('path');
const truncate = require('../utils/truncate-bytes');
function limitPathElement(element, limit) {
return element.split('/').map((component) => {
if (config.library.truncate && component.length > limit) {
return component.slice(0, limit - config.library.truncate.truncator.length) + config.library.truncate.truncator;
if (config.library.truncate && Buffer.from(component).length > limit) {
return truncate(component, limit - config.library.truncate.truncator.length) + config.library.truncate.truncator;
}
return component;