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 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;
|
||||
|
|
Loading…
Reference in New Issue