fix: update file path handling for template file operations

This commit is contained in:
2026-01-12 12:03:34 +01:00
parent 97a12a3bcd
commit a8db92731f
2 changed files with 5 additions and 5 deletions

View File

@@ -58,7 +58,7 @@ export async function PUT(request, { params }) {
// Delete old file
try {
const oldFilePath = path.join(process.cwd(), "public", existingTemplate.file_path);
const oldFilePath = path.join(process.cwd(), existingTemplate.file_path);
await unlink(oldFilePath);
} catch (fileError) {
console.warn("Could not delete old template file:", fileError);
@@ -67,10 +67,10 @@ export async function PUT(request, { params }) {
// Save new file
const fileExtension = path.extname(file.name);
const fileName = `${Date.now()}-${Math.random().toString(36).substring(2)}${fileExtension}`;
const filePath = path.join(process.cwd(), "public", "templates", fileName);
const filePath = path.join(process.cwd(), "templates", fileName);
// Ensure templates directory exists
const templatesDir = path.join(process.cwd(), "public", "templates");
const templatesDir = path.join(process.cwd(), "templates");
try {
await fs.promises.access(templatesDir);
} catch {
@@ -80,7 +80,7 @@ export async function PUT(request, { params }) {
const buffer = Buffer.from(await file.arrayBuffer());
await fs.promises.writeFile(filePath, buffer);
updateData.file_path = `/templates/${fileName}`;
updateData.file_path = `templates/${fileName}`;
updateData.original_filename = file.name;
updateData.file_size = file.size;
}

View File

@@ -65,7 +65,7 @@ export async function POST(request) {
`).all(projectId);
// Load template file
const templatePath = path.join(process.cwd(), "public", template.file_path);
const templatePath = path.join(process.cwd(), template.file_path);
const templateContent = await readFile(templatePath);
// Load the docx file as a binary