- Added schema for users, licenses, and license hostnames in the database. - Created storage utility for reading and writing JSON files. - Developed user service for user registration, authentication, and retrieval. - Implemented authentication middleware to protect routes. - Built LicenseCard component to display license details. - Created SiteNav component for navigation with user authentication status. - Established AuthContext for managing authentication state and actions. - Developed Home page to display available plugins. - Created LicenseManager page for managing licenses with forms for creation and verification. - Implemented PluginDetail page to show detailed information about a specific plugin. - Added utility functions for date formatting.
20 lines
572 B
JavaScript
20 lines
572 B
JavaScript
import fs from "fs/promises";
|
|
|
|
export async function readJsonFile(filePath, fallback = []) {
|
|
try {
|
|
const content = await fs.readFile(filePath, "utf-8");
|
|
const parsed = JSON.parse(content);
|
|
return parsed ?? fallback;
|
|
} catch (error) {
|
|
if (error.code === "ENOENT") {
|
|
await fs.writeFile(filePath, JSON.stringify(fallback, null, 2));
|
|
return fallback;
|
|
}
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
export async function writeJsonFile(filePath, data) {
|
|
await fs.writeFile(filePath, JSON.stringify(data, null, 2));
|
|
}
|