Add full project structure: backend API + frontend
- Move repo to project root to include both public/ and api/ - Add .gitignore excluding node_modules and .env - Include API routes (erase, gmail_oauth), services (mailer), and config Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
36b918b95d
commit
614d5af397
20 changed files with 2419 additions and 0 deletions
55
api/routes/erase.js
Normal file
55
api/routes/erase.js
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
'use strict';
|
||||
|
||||
const crypto = require('crypto');
|
||||
const { sendErasureMail, PROVIDER_DATA } = require('../services/mailer');
|
||||
|
||||
const ALLOWED_PROVIDERS = new Set(Object.keys(PROVIDER_DATA));
|
||||
|
||||
module.exports = async (req, res) => {
|
||||
try {
|
||||
const { provider, email, nickname, phone, address, extra } = req.body;
|
||||
|
||||
// Validación mínima
|
||||
if (!provider || !email) {
|
||||
return res.status(400).json({ error: 'provider y email son obligatorios' });
|
||||
}
|
||||
|
||||
// Validar proveedor conocido (previene abusos de relay)
|
||||
if (!ALLOWED_PROVIDERS.has(provider)) {
|
||||
return res.status(400).json({ error: 'Proveedor no soportado. Usa el formulario oficial.' });
|
||||
}
|
||||
|
||||
// Validación básica de email
|
||||
if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) {
|
||||
return res.status(400).json({ error: 'Email inválido' });
|
||||
}
|
||||
|
||||
// Hash irreversible para referencia (auditoría sin almacenar PII)
|
||||
const hash = crypto
|
||||
.createHash('sha256')
|
||||
.update(email + (process.env.SALT || 'resetea-default-salt'))
|
||||
.digest('hex');
|
||||
|
||||
const result = await sendErasureMail({ provider, email, nickname, phone, address, extra });
|
||||
|
||||
if (result.skipped) {
|
||||
return res.json({
|
||||
status: 'use_form',
|
||||
message: 'Este proveedor no acepta solicitudes por email. Usa su formulario oficial.',
|
||||
formUrl: result.formUrl,
|
||||
reference: hash.substring(0, 12),
|
||||
});
|
||||
}
|
||||
|
||||
// PII fuera de scope aquí — solo el hash queda
|
||||
res.json({
|
||||
status: 'ok',
|
||||
message: 'Solicitud enviada. Guarda el código de referencia.',
|
||||
reference: hash.substring(0, 12),
|
||||
});
|
||||
|
||||
} catch (e) {
|
||||
console.error('erase route error:', e.message);
|
||||
res.status(500).json({ error: 'Error interno. Inténtalo de nuevo o usa el formulario oficial del proveedor.' });
|
||||
}
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue