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:
@@ -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') {
|
||||
|
||||
Reference in New Issue
Block a user