code clean up, remove frontend sms api??? why was it there at all?? and some cron things
Build and Push Docker Images / Build and Push Docker Images (push) Failing after 4s

This commit is contained in:
2026-08-02 06:10:25 +05:00
parent 446a501053
commit c137ef0847
4 changed files with 0 additions and 187 deletions
-5
View File
@@ -27,8 +27,3 @@ OMADA_PROXY_API_KEY=""
# Invoice Ninja — finance/clients integration # Invoice Ninja — finance/clients integration
# ============================================================================= # =============================================================================
NINJA_API_KEY="" NINJA_API_KEY=""
# =============================================================================
# Cron — shared secret that protects the /api/check-devices route
# =============================================================================
CRON_API_KEY=""
-20
View File
@@ -192,26 +192,6 @@ export async function signup(_actionState: ActionState, formData: FormData) {
return { message: "User created successfully", error: "success" }; return { message: "User created successfully", error: "success" };
} }
export const sendOtp = async (phoneNumber: string, code: string) => {
// Implement sending OTP code via SMS
console.log("Send OTP server fn", phoneNumber, code);
const respose = await fetch(`${process.env.SMS_API_BASE_URL}/api/sms`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${process.env.SMS_API_KEY}`,
},
body: JSON.stringify({
check_delivery: false,
number: phoneNumber,
message: `Your OTP code is ${code}`,
}),
});
const data = await respose.json();
console.log(data);
return data;
};
export async function backendMobileLogin({ mobile }: { mobile: string }) { export async function backendMobileLogin({ mobile }: { mobile: string }) {
const response = await fetch( const response = await fetch(
`${process.env.SARLINK_API_BASE_URL}/auth/mobile/`, `${process.env.SARLINK_API_BASE_URL}/auth/mobile/`,
-142
View File
@@ -1,146 +1,4 @@
export async function GET(request: Request) { export async function GET(request: Request) {
console.log(request.url); console.log(request.url);
return Response.json({ message: "Request received" }); return Response.json({ message: "Request received" });
// try {
// // Validate API key before proceeding
// validateApiKey(request);
// const currentTime = new Date();
// const hoursSinceLastRun =
// (currentTime.getTime() - lastRunTime.getTime()) / (1000 * 60 * 60);
// // Get all active and unblocked devices with their latest payment
// const devices = await prisma.device.findMany({
// where: {
// isActive: true,
// blocked: false,
// },
// include: {
// payments: true,
// User: {
// include: {
// devices: true,
// },
// },
// },
// });
// let devicesNeedingNotification = 0;
// let devicesBlocked = 0;
// for (const device of devices) {
// let expiryDate = new Date();
// const payment = device.payments[0];
// expiryDate = addMonths(
// payment?.paidAt || new Date(),
// payment?.numberOfMonths || 0,
// );
// // Calculate notification threshold (5 days before expiry)
// const notificationThreshold = addDays(expiryDate, -5);
// const currentDate = new Date();
// console.log("device name -> ", device.name);
// console.log("paid date -> ", device.payments[0]?.paidAt);
// console.log("no of months paid -> ", device.payments[0]?.numberOfMonths);
// console.log("calculated expire date -> ", expiryDate);
// console.log("notification threshold -> ", notificationThreshold);
// console.log("current date -> ", currentDate);
// // Check if device is within notification period
// if (
// isWithinInterval(currentDate, {
// start: notificationThreshold,
// end: expiryDate,
// })
// ) {
// // Device is within 5 days of expiring
// if (device.User?.phoneNumber) {
// await sendNotifySms(
// new Date(expiryDate),
// device.User?.phoneNumber ?? "",
// device.name,
// );
// devicesNeedingNotification++;
// }
// }
// // Check if device has expired
// if (isAfter(currentDate, expiryDate)) {
// // Device has expired, block it
// // TODO: add a reason for blocking
// await blockDevice({
// macAddress: device.mac,
// type: "block",
// });
// await prisma.device.update({
// where: { id: device.id },
// data: {
// isActive: false,
// blocked: true,
// },
// });
// devicesBlocked++;
// }
// }
// if (hoursSinceLastRun < 24) {
// return Response.json({
// totalActiveDevices: devices.length,
// devicesChecked: {
// notified: devicesNeedingNotification,
// blocked: devicesBlocked,
// },
// message: "Check was run recently",
// nextCheckIn: `${Math.round(24 - hoursSinceLastRun)} hours`,
// });
// }
// return Response.json({
// success: true,
// totalActiveDevices: devices.length,
// devicesChecked: {
// notified: devicesNeedingNotification,
// blocked: devicesBlocked,
// },
// runAt: currentTime,
// });
// } catch (error) {
// if (error instanceof Error) {
// if (error.message === "API key is missing") {
// return Response.json({ error: "API key is required" }, { status: 401 });
// }
// if (error.message === "Invalid API key") {
// return Response.json({ error: "Invalid API key" }, { status: 403 });
// }
// }
// console.error("Error in device check:", error);
// return Response.json({ error: "Failed to check devices" }, { status: 500 });
// }
// }
// // Mock function - replace with your actual SMS implementation
// async function sendNotifySms(
// expireDate: Date,
// phoneNumber: string,
// deviceName?: string,
// ) {
// const respose = await fetch(`${process.env.SMS_API_BASE_URL}/api/sms`, {
// method: "POST",
// headers: {
// "Content-Type": "application/json",
// Authorization: `Bearer ${process.env.SMS_API_KEY}`,
// },
// body: JSON.stringify({
// check_delivery: false,
// number: phoneNumber,
// message: `REMINDER! Your device [${deviceName}] will expire on ${new Date(expireDate)}.`,
// }),
// });
// const data = await respose.json();
// console.log(data);
// return data;
//
} }
-20
View File
@@ -28,26 +28,6 @@ export const formatMacAddress = (mac: string): string => {
return formatted ? formatted.join("-") : ""; 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");
}
}
export function shouldShowTopupPaymentInfo(topup: Topup | undefined): boolean { export function shouldShowTopupPaymentInfo(topup: Topup | undefined): boolean {
if (!topup) return false; if (!topup) return false;