From 12e17c7c3c4fd6d7d6386e485de4b644d23ac493 Mon Sep 17 00:00:00 2001 From: DebaucheryLibrarian Date: Wed, 11 Sep 2024 05:16:57 +0200 Subject: [PATCH] Calculating filename component limit in bytes rather than characters, preventing 'filename too long' errors when e.g. emojis are used --- src/save/save.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/save/save.js b/src/save/save.js index ee3c270..f8e95cc 100644 --- a/src/save/save.js +++ b/src/save/save.js @@ -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;