Mirror pipeline creatives into each client's Drive folder tree.

On upload, create Pipeline-creatividades_{slug}/YYYY/MM under the linked client folder and name files DD-MM-YYYY_formato_hook[-N].

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
4Ventures
2026-10-07 12:44:07 +02:00
parent 5b895d830b
commit 233d3f202e
3 changed files with 296 additions and 30 deletions

View File

@@ -195,7 +195,7 @@ export default function CreativePipelineBoard() {
file: File,
slot: 'cover' | 'slide',
index = 0
): Promise<string | null> {
): Promise<{ error: string | null; driveWarning?: string | null }> {
const fd = new FormData();
fd.append('file', file);
fd.append('itemId', itemId);
@@ -206,8 +206,14 @@ export default function CreativePipelineBoard() {
body: fd,
});
const data = await res.json();
if (!res.ok) return data.error || 'Error al subir imagen';
return null;
if (!res.ok) {
return { error: data.error || 'Error al subir imagen' };
}
const driveWarning =
data.drive && !data.drive.ok
? data.drive.warning || 'No se pudo espejar en Drive'
: null;
return { error: null, driveWarning };
}
async function load() {
@@ -398,37 +404,36 @@ export default function CreativePipelineBoard() {
}
const newId = data.item?.id as string | undefined;
let driveNote: string | null = null;
if (newId && coverFile) {
const upErr = await uploadFileToItem(newId, coverFile, 'cover', 0);
if (upErr) {
const up = await uploadFileToItem(newId, coverFile, 'cover', 0);
if (up.error) {
setErr(
`Pieza creada, pero falló la portada: ${upErr}. Puedes subirla desde la tarjeta.`
`Pieza creada, pero falló la portada: ${up.error}. Puedes subirla desde la tarjeta.`
);
resetForm();
await load();
return;
}
if (up.driveWarning) driveNote = up.driveWarning;
}
if (newId && newFormat === 'carrusel' && slideFiles.length) {
for (let i = 0; i < slideFiles.length; i++) {
const upErr = await uploadFileToItem(
newId,
slideFiles[i],
'slide',
i
);
if (upErr) {
const up = await uploadFileToItem(newId, slideFiles[i], 'slide', i);
if (up.error) {
setErr(
`Pieza creada; error en slide ${i + 1}: ${upErr}. Completa el resto en la tarjeta.`
`Pieza creada; error en slide ${i + 1}: ${up.error}. Completa el resto en la tarjeta.`
);
resetForm();
await load();
return;
}
if (up.driveWarning) driveNote = up.driveWarning;
}
}
resetForm();
if (driveNote) setWarning(`Creativo en portal OK. Drive: ${driveNote}`);
await load();
} finally {
setCreating(false);
@@ -663,17 +668,14 @@ export default function CreativePipelineBoard() {
setBusyId(itemId);
setErr(null);
try {
const fd = new FormData();
fd.append('file', file);
fd.append('itemId', itemId);
fd.append('slot', slot);
fd.append('index', String(index));
const res = await fetch('/api/creative-pipeline/upload', { method: 'POST', body: fd });
const data = await res.json();
if (!res.ok) {
setErr(data.error || 'Error al subir imagen');
const up = await uploadFileToItem(itemId, file, slot, index);
if (up.error) {
setErr(up.error);
return;
}
if (up.driveWarning) {
setWarning(`Imagen en portal OK. Drive: ${up.driveWarning}`);
}
await load();
} finally {
setBusyId(null);