Compare commits
No commits in common. "497f49e85daebfead031a8f0396be38755f42e26" and "36e947480132560a38bed59115434eed9bdf71f9" have entirely different histories.
497f49e85d
...
36e9474801
|
|
@ -25,7 +25,6 @@ pnpm-debug.log*
|
||||||
/generated/prisma
|
/generated/prisma
|
||||||
prisma/*.db
|
prisma/*.db
|
||||||
prisma/dev.db
|
prisma/dev.db
|
||||||
data/
|
|
||||||
|
|
||||||
# opencode - agentes y scripts locales (no subir a producción)
|
# opencode - agentes y scripts locales (no subir a producción)
|
||||||
opencode/
|
opencode/
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import type { APIRoute } from "astro";
|
import type { APIRoute } from "astro";
|
||||||
import { appendRegistrationToSheet } from "../lib/googleSheets";
|
import { appendRegistrationToSheet } from "../lib/googleSheets";
|
||||||
import { sendEmailCf } from "../lib/email";
|
import { sendEmailCf } from "../lib/email";
|
||||||
import { emailExistsInRegistry, addEmailToRegistry } from "../lib/emailsRegistry";
|
|
||||||
export const prerender = false;
|
export const prerender = false;
|
||||||
|
|
||||||
const COLUMNS = [
|
const COLUMNS = [
|
||||||
|
|
@ -102,13 +101,6 @@ export const POST: APIRoute = async ({ request }) => {
|
||||||
timeZone: "America/Puerto_Rico",
|
timeZone: "America/Puerto_Rico",
|
||||||
});
|
});
|
||||||
|
|
||||||
if (emailExistsInRegistry(formData.correo)) {
|
|
||||||
return Response.json(
|
|
||||||
{ success: false, message: "Este correo ya está registrado. No se permiten 2 registros." },
|
|
||||||
{ status: 409 }
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const row = COLUMNS.map((key) => flattenValue(formData[key]));
|
const row = COLUMNS.map((key) => flattenValue(formData[key]));
|
||||||
row.push(timestamp);
|
row.push(timestamp);
|
||||||
|
|
||||||
|
|
@ -119,8 +111,6 @@ export const POST: APIRoute = async ({ request }) => {
|
||||||
apellidos: formData.apellido,
|
apellidos: formData.apellido,
|
||||||
}, formData.correo, "CENTRO_DEL_REINO_PAZ_Y_JUSTICIA_POSTULACION");
|
}, formData.correo, "CENTRO_DEL_REINO_PAZ_Y_JUSTICIA_POSTULACION");
|
||||||
|
|
||||||
addEmailToRegistry(formData.correo);
|
|
||||||
|
|
||||||
return Response.json(result);
|
return Response.json(result);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error en /api/formulario/send:", error);
|
console.error("Error en /api/formulario/send:", error);
|
||||||
|
|
|
||||||
|
|
@ -96,7 +96,7 @@ export async function sendEmailCf(data: Record<string, string>, to: string, type
|
||||||
text,
|
text,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!response.delivered.includes(to)) {
|
if (response.permanent_bounces.includes(to)) {
|
||||||
console.error("Cloudflare email not delivered", response);
|
console.error("Cloudflare email not delivered", response);
|
||||||
throw new Error("El correo no fue entregado");
|
throw new Error("El correo no fue entregado");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,22 +0,0 @@
|
||||||
import fs from "node:fs";
|
|
||||||
import path from "node:path";
|
|
||||||
|
|
||||||
const REGISTRY_PATH = path.resolve(process.cwd(), "data", "emails.txt");
|
|
||||||
|
|
||||||
export function emailExistsInRegistry(email: string): boolean {
|
|
||||||
try {
|
|
||||||
if (!fs.existsSync(REGISTRY_PATH)) return false;
|
|
||||||
const content = fs.readFileSync(REGISTRY_PATH, "utf-8");
|
|
||||||
return content.split("\n").some((line) => line.trim().toLowerCase() === email.trim().toLowerCase());
|
|
||||||
} catch {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function addEmailToRegistry(email: string): void {
|
|
||||||
const dir = path.dirname(REGISTRY_PATH);
|
|
||||||
if (!fs.existsSync(dir)) {
|
|
||||||
fs.mkdirSync(dir, { recursive: true });
|
|
||||||
}
|
|
||||||
fs.appendFileSync(REGISTRY_PATH, email.trim().toLowerCase() + "\n");
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue