Md Afiq Iskandar 84e8d8e42f Enhance Process Builder with New Variables and External Menu Support
- Added new variables for 'namaAsnaf', 'todoStatus', 'asnafScore', 'resultTimestamp', and 'resultSummary' to improve data handling in process definitions.
- Updated process definition JSON to include new output mappings and enhanced script logic for better API response handling.
- Implemented validation for external menu paths in the menu editor, ensuring proper URL formatting and handling for external links.
- Enhanced the user interface in the menu editor to support external URL inputs, improving user experience when adding or editing menu items.
- Updated API endpoints to skip file operations for external menus, streamlining the process of adding and editing external links.
2025-07-16 11:08:38 +08:00

60 lines
1.4 KiB
JavaScript

import fs from "fs";
import path from "path";
export default defineEventHandler(async (event) => {
const body = await readBody(event);
try {
// If external, skip file operations
if (body.formData.external === true) {
return {
statusCode: 200,
message: "External menu successfully added!",
};
}
// Check if last character is not slash
if (body.formData.path.slice(-1) != "/") {
body.formData.path = body.formData.path + "/";
}
// Check if the path already exists
if (fs.existsSync(path.join(process.cwd(), "pages", body.formData.path))) {
return {
statusCode: 500,
message: "Path already exists. Please choose another path.",
};
}
// Create new file path with index.vue
const newFilePath = path.join(
process.cwd(),
"pages",
body.formData.path,
"index.vue"
);
// Create the folder if doesn't exist
fs.mkdirSync(path.dirname(newFilePath), { recursive: true });
// Create template content
const templateContent = buildNuxtTemplate({
title: body.formData.title || body.formData.name,
name: body.formData.name,
});
// Write file with template
fs.writeFileSync(newFilePath, templateContent);
return {
statusCode: 200,
message: "Menu successfully added!",
};
} catch (error) {
return {
statusCode: 500,
message: error.message,
};
}
});