fix: ficha no finge sync al guardar IDs; normaliza URL de Drive

«Conectar» en la ficha solo guarda la referencia; last_sync queda
para syncs reales. Drive acepta URL completa → folder id.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
4Ventures
2026-09-24 12:22:41 +02:00
parent 5501f45a67
commit 81ba5df37d
2 changed files with 20 additions and 5 deletions

View File

@@ -129,13 +129,24 @@ export async function PATCH(req: NextRequest) {
}; };
if (status) patch.status = status; if (status) patch.status = status;
if (externalAccountId !== undefined) { if (externalAccountId !== undefined) {
patch.external_account_id = externalAccountId || null; let id = externalAccountId || null;
// Drive: accept full folder URL → store folder id only
if (provider === 'google_drive' && id) {
const m = id.match(/\/folders\/([a-zA-Z0-9_-]+)/);
if (m) id = m[1];
else if (id.includes('http')) {
const q = id.match(/[?&]id=([a-zA-Z0-9_-]+)/);
if (q) id = q[1];
}
}
patch.external_account_id = id;
} }
if (label !== undefined) patch.label = label || null; if (label !== undefined) patch.label = label || null;
if (errorMessage !== undefined) patch.error_message = errorMessage || null; if (errorMessage !== undefined) patch.error_message = errorMessage || null;
if (enabled !== undefined) patch.enabled = enabled; if (enabled !== undefined) patch.enabled = enabled;
// Manual «Conectar» only marks the reference — do not fake a data sync timestamp.
// Real syncs (Ads discover, Orgánico, Superhuman…) set last_sync_at themselves.
if (status === 'connected') { if (status === 'connected') {
patch.last_sync_at = new Date().toISOString();
patch.error_message = null; patch.error_message = null;
} }
if (status === 'disconnected') { if (status === 'disconnected') {

View File

@@ -205,12 +205,16 @@ export default function ClientIntegrationsPanel({
Carpeta: {folderHint} Carpeta: {folderHint}
</p> </p>
)} )}
{row?.last_sync_at && ( {row?.last_sync_at ? (
<p className="text-[10px] text-gray-500"> <p className="text-[10px] text-gray-500">
Último sync{' '} Último sync real{' '}
{new Date(row.last_sync_at).toLocaleString('es-ES')} {new Date(row.last_sync_at).toLocaleString('es-ES')}
</p> </p>
)} ) : status === 'connected' ? (
<p className="text-[10px] text-amber-700">
Referencia guardada (aún sin sync de datos)
</p>
) : null}
{row?.error_message && ( {row?.error_message && (
<p className="text-[11px] text-red-600 mt-1"> <p className="text-[11px] text-red-600 mt-1">
{row.error_message} {row.error_message}