From 81ba5df37d69e1a8ea6678c647a60eb41482869f Mon Sep 17 00:00:00 2001
From: 4Ventures <4ventures@MacBook-Air-de-4Ventures.local>
Date: Thu, 24 Sep 2026 12:22:41 +0200
Subject: [PATCH] fix: ficha no finge sync al guardar IDs; normaliza URL de
Drive
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
«Conectar» en la ficha solo guarda la referencia; last_sync queda
para syncs reales. Drive acepta URL completa → folder id.
Co-authored-by: Cursor
---
src/app/api/admin/integrations/route.ts | 15 +++++++++++++--
src/components/ClientIntegrationsPanel.tsx | 10 +++++++---
2 files changed, 20 insertions(+), 5 deletions(-)
diff --git a/src/app/api/admin/integrations/route.ts b/src/app/api/admin/integrations/route.ts
index 5916a53..4b3df22 100644
--- a/src/app/api/admin/integrations/route.ts
+++ b/src/app/api/admin/integrations/route.ts
@@ -129,13 +129,24 @@ export async function PATCH(req: NextRequest) {
};
if (status) patch.status = status;
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 (errorMessage !== undefined) patch.error_message = errorMessage || null;
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') {
- patch.last_sync_at = new Date().toISOString();
patch.error_message = null;
}
if (status === 'disconnected') {
diff --git a/src/components/ClientIntegrationsPanel.tsx b/src/components/ClientIntegrationsPanel.tsx
index 36ac948..c773cf0 100644
--- a/src/components/ClientIntegrationsPanel.tsx
+++ b/src/components/ClientIntegrationsPanel.tsx
@@ -205,12 +205,16 @@ export default function ClientIntegrationsPanel({
Carpeta: {folderHint}
)}
- {row?.last_sync_at && (
+ {row?.last_sync_at ? (
- Último sync{' '}
+ Último sync real{' '}
{new Date(row.last_sync_at).toLocaleString('es-ES')}
- )}
+ ) : status === 'connected' ? (
+
+ Referencia guardada (aún sin sync de datos)
+
+ ) : null}
{row?.error_message && (
{row.error_message}