Merge pull request #235 from presenton/fix/pdf_export_mino
fix: minor issue with pdf export
This commit is contained in:
commit
65bff822eb
2 changed files with 5 additions and 3 deletions
|
|
@ -58,9 +58,11 @@ export function removeUUID(fileName: string) {
|
|||
|
||||
|
||||
|
||||
export function sanitizeFilename(input: string, replacement = '') {
|
||||
export function sanitizeFilename(input: string | null | undefined, replacement = '') {
|
||||
// Start with a safe base string to avoid calling string methods on null/undefined
|
||||
let sanitized = (input ?? '').toString();
|
||||
// Remove any null bytes first
|
||||
let sanitized = input.replace(/\0/g, '');
|
||||
sanitized = sanitized.replace(/\0/g, '');
|
||||
|
||||
// Remove or replace path traversal sequences
|
||||
sanitized = sanitized.replace(/\.\./g, replacement);
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ export async function POST(req: NextRequest) {
|
|||
|
||||
browser.close();
|
||||
|
||||
const sanitizedTitle = sanitizeFilename(title);
|
||||
const sanitizedTitle = sanitizeFilename(title ?? 'presentation');
|
||||
const destinationPath = path.join(process.env.APP_DATA_DIRECTORY!, 'exports', `${sanitizedTitle}.pdf`);
|
||||
await fs.promises.mkdir(path.dirname(destinationPath), { recursive: true });
|
||||
await fs.promises.writeFile(destinationPath, pdfBuffer);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue