mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2025-09-24 04:26:14 +00:00
Accept rename from preserveBackendFilename in automation
This commit is contained in:
parent
022d7ec8a2
commit
202024a70d
@ -4,6 +4,7 @@ import { AUTOMATION_CONSTANTS } from '../constants/automation';
|
|||||||
import { AutomationFileProcessor } from './automationFileProcessor';
|
import { AutomationFileProcessor } from './automationFileProcessor';
|
||||||
import { ResourceManager } from './resourceManager';
|
import { ResourceManager } from './resourceManager';
|
||||||
import { ToolType } from '../hooks/tools/shared/useToolOperation';
|
import { ToolType } from '../hooks/tools/shared/useToolOperation';
|
||||||
|
import { processResponse } from './toolResponseProcessor';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -68,12 +69,17 @@ export const executeToolOperationWithPrefix = async (
|
|||||||
let result;
|
let result;
|
||||||
if (response.data.type === 'application/pdf' ||
|
if (response.data.type === 'application/pdf' ||
|
||||||
(response.headers && response.headers['content-type'] === 'application/pdf')) {
|
(response.headers && response.headers['content-type'] === 'application/pdf')) {
|
||||||
// Single PDF response (e.g. split with merge option) - use original filename
|
// Single PDF response (e.g. split with merge option) - use processResponse to respect preserveBackendFilename
|
||||||
const originalFileName = files[0]?.name || 'document.pdf';
|
const processedFiles = await processResponse(
|
||||||
const singleFile = new File([response.data], originalFileName, { type: 'application/pdf' });
|
response.data,
|
||||||
|
files,
|
||||||
|
filePrefix,
|
||||||
|
undefined,
|
||||||
|
config.preserveBackendFilename ? response.headers : undefined
|
||||||
|
);
|
||||||
result = {
|
result = {
|
||||||
success: true,
|
success: true,
|
||||||
files: [singleFile],
|
files: processedFiles,
|
||||||
errors: []
|
errors: []
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
@ -85,7 +91,8 @@ export const executeToolOperationWithPrefix = async (
|
|||||||
console.warn(`⚠️ File processing warnings:`, result.errors);
|
console.warn(`⚠️ File processing warnings:`, result.errors);
|
||||||
}
|
}
|
||||||
// Apply prefix to files, replacing any existing prefix
|
// Apply prefix to files, replacing any existing prefix
|
||||||
const processedFiles = filePrefix
|
// Skip prefixing if preserveBackendFilename is true and backend provided a filename
|
||||||
|
const processedFiles = filePrefix && !config.preserveBackendFilename
|
||||||
? result.files.map(file => {
|
? result.files.map(file => {
|
||||||
const nameWithoutPrefix = file.name.replace(/^[^_]*_/, '');
|
const nameWithoutPrefix = file.name.replace(/^[^_]*_/, '');
|
||||||
return new File([file], `${filePrefix}${nameWithoutPrefix}`, { type: file.type });
|
return new File([file], `${filePrefix}${nameWithoutPrefix}`, { type: file.type });
|
||||||
@ -117,15 +124,16 @@ export const executeToolOperationWithPrefix = async (
|
|||||||
|
|
||||||
console.log(`📥 Response ${i+1} status: ${response.status}, size: ${response.data.size} bytes`);
|
console.log(`📥 Response ${i+1} status: ${response.status}, size: ${response.data.size} bytes`);
|
||||||
|
|
||||||
// Create result file with automation prefix
|
// Create result file using processResponse to respect preserveBackendFilename setting
|
||||||
|
const processedFiles = await processResponse(
|
||||||
const resultFile = ResourceManager.createResultFile(
|
|
||||||
response.data,
|
response.data,
|
||||||
file.name,
|
[file],
|
||||||
filePrefix
|
filePrefix,
|
||||||
|
undefined,
|
||||||
|
config.preserveBackendFilename ? response.headers : undefined
|
||||||
);
|
);
|
||||||
resultFiles.push(resultFile);
|
resultFiles.push(...processedFiles);
|
||||||
console.log(`✅ Created result file: ${resultFile.name}`);
|
console.log(`✅ Created result file(s): ${processedFiles.map(f => f.name).join(', ')}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`🎉 Single-file processing complete: ${resultFiles.length} files`);
|
console.log(`🎉 Single-file processing complete: ${resultFiles.length} files`);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user