feat(BillingService): implement fallback file path resolution for migrated workspaces
All checks were successful
Deploy tt-tagebuch / deploy (push) Successful in 42s

- Added logic to search for PDF templates in known upload directories when the base file name is provided.
- Enhanced the robustness of file handling by checking multiple potential template directories for existing files.
- Improved error handling by returning null for invalid base names, ensuring cleaner path resolution.
This commit is contained in:
Torsten Schulz (local)
2026-04-25 09:52:31 +02:00
parent 5f07a3e3d6
commit be9d26e51e

View File

@@ -51,6 +51,26 @@ class BillingService {
return candidate;
}
}
// Fallback fuer migrierte/verschobene Workspaces:
// Datei ueber den Dateinamen in bekannten Upload-Ordnern suchen.
const baseName = path.basename(rawPath);
if (!baseName || baseName === '.' || baseName === '/') {
return null;
}
const templateDirs = [
path.resolve(process.cwd(), 'uploads', 'billing-templates'),
path.resolve(process.cwd(), 'backend', 'uploads', 'billing-templates'),
path.resolve(process.cwd(), '..', 'backend', 'uploads', 'billing-templates'),
path.resolve(process.cwd(), '..', 'uploads', 'billing-templates')
];
for (const dir of templateDirs) {
const candidate = path.join(dir, baseName);
if (fs.existsSync(candidate)) {
return candidate;
}
}
return null;
}