fix: minor issue with pdf export

This commit is contained in:
Suraj Jha 2025-08-19 18:06:04 +05:45
parent 6ce937ac1d
commit 05a9229d4a
No known key found for this signature in database
GPG key ID: 5AC6C16355CE2C14
2 changed files with 5 additions and 3 deletions

View file

@ -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);

View file

@ -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);