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:
parent
263525c320
commit
6c15d2e88b
|
@ -3,11 +3,12 @@
|
||||||
const config = require('config');
|
const config = require('config');
|
||||||
const fs = require('fs-extra');
|
const fs = require('fs-extra');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
const truncate = require('../utils/truncate-bytes');
|
||||||
|
|
||||||
function limitPathElement(element, limit) {
|
function limitPathElement(element, limit) {
|
||||||
return element.split('/').map((component) => {
|
return element.split('/').map((component) => {
|
||||||
if (config.library.truncate && component.length > limit) {
|
if (config.library.truncate && Buffer.from(component).length > limit) {
|
||||||
return component.slice(0, limit - config.library.truncate.truncator.length) + config.library.truncate.truncator;
|
return truncate(component, limit - config.library.truncate.truncator.length) + config.library.truncate.truncator;
|
||||||
}
|
}
|
||||||
|
|
||||||
return component;
|
return component;
|
||||||
|
|
Loading…
Reference in New Issue