n8n-nodes-seclore/dist/nodes/SecloreProtect/Services/Utils.js

43 lines
2.0 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getFileNameFromHeaders = getFileNameFromHeaders;
const n8n_workflow_1 = require("n8n-workflow");
function getFileNameFromHeaders(headers) {
const who = "Utils::getFileNameFromHeaders:: ";
if (!headers) {
n8n_workflow_1.LoggerProxy.debug(who + 'No headers provided');
return null;
}
const contentDisposition = Object.keys(headers).find(key => key.toLowerCase() === 'content-disposition');
if (!contentDisposition || !headers[contentDisposition]) {
n8n_workflow_1.LoggerProxy.debug(who + 'Content-Disposition header not found');
return null;
}
const headerValue = headers[contentDisposition];
n8n_workflow_1.LoggerProxy.debug(who + 'Found Content-Disposition header', { headerValue });
const utf8Match = headerValue.match(/filename\*=UTF-8''([^;]+)/i);
if (utf8Match) {
try {
const decodedFilename = decodeURIComponent(utf8Match[1]);
n8n_workflow_1.LoggerProxy.debug(who + 'Extracted filename from UTF-8 format', { filename: decodedFilename });
return decodedFilename;
}
catch (error) {
n8n_workflow_1.LoggerProxy.error(who + 'Failed to decode UTF-8 filename', { error, encodedFilename: utf8Match[1] });
}
}
const quotedMatch = headerValue.match(/filename="([^"]+)"/i);
if (quotedMatch) {
n8n_workflow_1.LoggerProxy.debug(who + 'Extracted filename from quoted format', { filename: quotedMatch[1] });
return quotedMatch[1];
}
const unquotedMatch = headerValue.match(/filename=([^;]+)/i);
if (unquotedMatch) {
const filename = unquotedMatch[1].trim();
n8n_workflow_1.LoggerProxy.debug(who + 'Extracted filename from unquoted format', { filename });
return filename;
}
n8n_workflow_1.LoggerProxy.debug(who + 'Could not extract filename from Content-Disposition header', { headerValue });
return null;
}
//# sourceMappingURL=Utils.js.map