sarlink-portal/lib/utils.ts
i701 c06c4fee3f Implement parental control features and enhance device management
- Added a new Parental Control page for managing device access and notifications.
- Introduced blockDevice function to handle blocking and unblocking devices based on payment status.
- Enhanced omada-actions.ts to include device blocking logic and improved error handling.
- Updated DevicesTable component to integrate BlockDeviceButton for managing device states.
- Implemented API route for checking device statuses and sending notifications for expiring devices.
- Refactored payment processing to update device statuses upon successful payment verification.
- Added new utility functions for API key validation and SMS notifications.

These changes improve user control over device management and enhance the overall functionality of the application.
2024-12-22 21:34:57 +05:00

49 lines
1.2 KiB
TypeScript

import { type ClassValue, clsx } from "clsx";
import { twMerge } from "tailwind-merge";
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}
export const formatDate = (date: Date): string => {
const pad = (num: number): string => num.toString().padStart(2, "0");
const year = date.getFullYear();
const month = pad(date.getMonth() + 1); // Months are zero-based
const day = pad(date.getDate());
const hours = pad(date.getHours());
const minutes = pad(date.getMinutes() + 5);
return `${year}-${month}-${day} ${hours}:${minutes}`;
};
export const formatMacAddress = (mac: string): string => {
const formatted = mac
.replace(/[^A-Fa-f0-9]/g, "")
.toUpperCase()
.match(/.{2}/g);
// Provide a fallback if formatted is null
return formatted ? formatted.join("-") : "";
};
export function validateApiKey(request: Request) {
// Get API key from environment variable
const validApiKey = process.env.CRON_API_KEY;
if (!validApiKey) {
throw new Error("CRON_API_KEY is not configured");
}
// Get API key from request header
const apiKey = request.headers.get("x-api-key");
if (!apiKey) {
throw new Error("API key is missing");
}
if (apiKey !== validApiKey) {
throw new Error("Invalid API key");
}
}