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:
DebaucheryLibrarian 2024-09-11 05:16:57 +02:00
parent e5d439cbaf
commit 12e17c7c3c
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;