v1.7: overlay carga, baneos, carrito persistente, fix upload
Lista negra: - Migración 0007: tabla baneos con historial (soporta expires_at futuro) - Helper is_banned() usado por middleware - Middleware guard: user baneado → rewrite /banned (admin exento) - Página /banned con razón/fecha/expires + botón signout - Panel /admin/usuarios con banear/desbanear (razón obligatoria, self-ban bloqueado) - Nav admin nueva entrada Usuarios + icono users Fix upload de fotos (bug definitivo): - Root cause: browserClient no autentica al Storage (cookies httpOnly no legibles desde JS) - Nuevos endpoints proxy /api/upload/material-foto/[id] y /avatar - Validan sesión con cookie httpOnly, suben con service_role (bypass RLS) - Refactor MaterialForm y PerfilForm para usar fetch multipart - Cookies httpOnly intactas (cero riesgo XSS) Overlay de carga: - Layout.astro con #page-loader (backdrop-filter blur + spinner mono) - Script inline captura clicks en <a href> y submits de <form> mismo origen - Filtros: modifier keys, target=_blank, anchor#, cross-origin, defaultPrevented - Respeta prefers-reduced-motion; pageshow limpia por bfcache Carrito persistente + vaciar: - SolicitudCart: useEffect hidrata/persiste labre:cart:v1 en localStorage - Guard cartHydrated evita pisar en montaje inicial - Botón "Vaciar" en checkout con window.confirm (solo con perfilCompleto) Filtro inventario sin auto-submit: - Removido script debounced que hacía form.submit() en cada tecla - Botón "Filtrar" existente sigue funcionando
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import type { APIRoute } from 'astro';
|
||||
|
||||
export const prerender = false;
|
||||
|
||||
export const POST: APIRoute = async ({ locals, params }) => {
|
||||
if (locals.profile?.rol !== 'admin') {
|
||||
return Response.json({ error: 'No autorizado' }, { status: 403 });
|
||||
}
|
||||
|
||||
const id = Number(params.id);
|
||||
if (!Number.isInteger(id) || id <= 0) {
|
||||
return Response.json({ error: 'ID inválido' }, { status: 400 });
|
||||
}
|
||||
|
||||
const { data, error } = await locals.supabase
|
||||
.from('baneos')
|
||||
.update({ unbanned_at: new Date().toISOString(), unbanned_by: locals.user!.id })
|
||||
.eq('id', id)
|
||||
.is('unbanned_at', null)
|
||||
.select('id');
|
||||
|
||||
if (error) {
|
||||
return Response.json({ error: 'No se pudo desbanear' }, { status: 500 });
|
||||
}
|
||||
if (!data || data.length === 0) {
|
||||
return Response.json({ error: 'Baneo no encontrado o ya inactivo' }, { status: 404 });
|
||||
}
|
||||
|
||||
return Response.json({ ok: true });
|
||||
};
|
||||
@@ -0,0 +1,67 @@
|
||||
import type { APIRoute } from 'astro';
|
||||
|
||||
export const prerender = false;
|
||||
|
||||
export const POST: APIRoute = async ({ request, locals }) => {
|
||||
if (locals.profile?.rol !== 'admin') {
|
||||
return Response.json({ error: 'No autorizado' }, { status: 403 });
|
||||
}
|
||||
|
||||
let body: { profile_id?: unknown; razon?: unknown; expires_at?: unknown };
|
||||
try {
|
||||
body = await request.json();
|
||||
} catch {
|
||||
return Response.json({ error: 'JSON inválido' }, { status: 400 });
|
||||
}
|
||||
|
||||
const profile_id = typeof body.profile_id === 'string' ? body.profile_id.trim() : '';
|
||||
if (!profile_id) {
|
||||
return Response.json({ error: 'profile_id es obligatorio' }, { status: 400 });
|
||||
}
|
||||
if (profile_id === locals.user!.id) {
|
||||
return Response.json({ error: 'No puedes banearte a ti mismo' }, { status: 400 });
|
||||
}
|
||||
|
||||
const razon = typeof body.razon === 'string' ? body.razon.trim().slice(0, 500) : '';
|
||||
if (razon.length < 5) {
|
||||
return Response.json({ error: 'La razón debe tener al menos 5 caracteres' }, { status: 400 });
|
||||
}
|
||||
|
||||
let expires_at: string | null = null;
|
||||
if (body.expires_at != null && body.expires_at !== '') {
|
||||
if (typeof body.expires_at !== 'string') {
|
||||
return Response.json({ error: 'expires_at debe ser string ISO' }, { status: 400 });
|
||||
}
|
||||
const d = new Date(body.expires_at);
|
||||
if (Number.isNaN(d.getTime())) {
|
||||
return Response.json({ error: 'expires_at inválido' }, { status: 400 });
|
||||
}
|
||||
if (d <= new Date()) {
|
||||
return Response.json({ error: 'expires_at debe ser futuro' }, { status: 400 });
|
||||
}
|
||||
expires_at = d.toISOString();
|
||||
}
|
||||
|
||||
const { data, error } = await locals.supabase
|
||||
.from('baneos')
|
||||
.insert({
|
||||
profile_id,
|
||||
razon,
|
||||
expires_at,
|
||||
banned_by: locals.user!.id,
|
||||
})
|
||||
.select('id')
|
||||
.single();
|
||||
|
||||
if (error) {
|
||||
if ((error as { code?: string }).code === '23505') {
|
||||
return Response.json(
|
||||
{ error: 'El usuario ya tiene un baneo activo — desbaneálo primero' },
|
||||
{ status: 409 },
|
||||
);
|
||||
}
|
||||
return Response.json({ error: 'No se pudo crear el baneo' }, { status: 500 });
|
||||
}
|
||||
|
||||
return Response.json({ id: data.id }, { status: 201 });
|
||||
};
|
||||
Reference in New Issue
Block a user