fix: complete KPI HTML dashboard integration (mock window.claude, add ig.fol, map piezas, pass wData)
This commit is contained in:
@@ -42,7 +42,7 @@ export async function GET() {
|
||||
gsc: { m: { clk: Array(daysCount).fill(null), imp: Array(daysCount).fill(null), posw: Array(daysCount).fill(null) }, from: startStr, to: endStr },
|
||||
ga4: { m: { ses: Array(daysCount).fill(null), usr: Array(daysCount).fill(null), new: Array(daysCount).fill(null), key: Array(daysCount).fill(null) }, from: startStr, to: endStr },
|
||||
gbp: { m: { imp: Array(daysCount).fill(null), call: Array(daysCount).fill(null), web: Array(daysCount).fill(null), dir: Array(daysCount).fill(null) }, from: startStr, to: endStr },
|
||||
ig: { m: { views: Array(daysCount).fill(null), inter: Array(daysCount).fill(null), likes: Array(daysCount).fill(null), com: Array(daysCount).fill(null), saves: Array(daysCount).fill(null), shares: Array(daysCount).fill(null), taps: Array(daysCount).fill(null) }, from: startStr, to: endStr },
|
||||
ig: { m: { views: Array(daysCount).fill(null), inter: Array(daysCount).fill(null), likes: Array(daysCount).fill(null), com: Array(daysCount).fill(null), saves: Array(daysCount).fill(null), shares: Array(daysCount).fill(null), taps: Array(daysCount).fill(null), fol: Array(daysCount).fill(null) }, from: startStr, to: endStr },
|
||||
fb: { m: { imp: Array(daysCount).fill(null), eng: Array(daysCount).fill(null), views: Array(daysCount).fill(null), fol: Array(daysCount).fill(null) }, from: startStr, to: endStr },
|
||||
li: { m: { imp: Array(daysCount).fill(null), clk: Array(daysCount).fill(null), eng: Array(daysCount).fill(null), fol: Array(daysCount).fill(null) }, from: startStr, to: endStr }
|
||||
}
|
||||
@@ -83,10 +83,29 @@ export async function GET() {
|
||||
|
||||
const kData = { seguidores: 0, posts: [], actualizado: endStr, desde: startStr, hasta: endStr };
|
||||
|
||||
// Inject data
|
||||
const dataPayload = { K, KC: {}, kData, piezas: creativePipeline || [] };
|
||||
// Map creative_pipeline to HTML's expected format (estado, formato, titulo, fecha, etc.)
|
||||
const piezasMapped = (creativePipeline || []).map((cp: any) => ({
|
||||
id: cp.id,
|
||||
titulo: cp.title || cp.titulo || 'Sin título',
|
||||
formato: cp.format || cp.formato || 'post',
|
||||
estado: cp.status || cp.estado || 'borrador',
|
||||
pilar: cp.pillar || cp.pilar || '',
|
||||
copy: cp.caption || cp.copy || '',
|
||||
visual: cp.visual_idea || cp.visual || '',
|
||||
fecha: cp.published_at ? String(cp.published_at).slice(0, 10) : (cp.created_at ? String(cp.created_at).slice(0, 10) : endStr),
|
||||
imgs: Array.isArray(cp.images) ? cp.images : (cp.images ? [cp.images] : []),
|
||||
comentarios: []
|
||||
}));
|
||||
|
||||
// Inject data and mock window.claude so early calls to downloads/sample don't throw
|
||||
const dataPayload = { K, KC: {}, kData, piezas: piezasMapped };
|
||||
|
||||
let htmlStr = htmlTemplate.replace(
|
||||
'<script>',
|
||||
'<script>\nwindow.claude = { use: function() { return Promise.resolve(null); } };\n'
|
||||
);
|
||||
|
||||
htmlStr = htmlStr.replace(
|
||||
/\/\* ---------- datos ---------- \*\/[\s\S]*?\}\)\(\);/g,
|
||||
`/* ---------- datos ---------- */
|
||||
window.__INJECTED_DATA__ = ${JSON.stringify(dataPayload).replace(/</g, '\\u003c')};
|
||||
@@ -97,7 +116,7 @@ export async function GET() {
|
||||
piezasOk = true;
|
||||
|
||||
if (!K) { $("wk").innerHTML="<b>Sin KPIs todavía.</b>"; $("r-body").innerHTML=$("wk").innerHTML; }
|
||||
else { renderK(); renderWk(); renderResumen(); }
|
||||
else { renderK(); renderWk({}); renderResumen(); }
|
||||
if (kData) { renderKpi(kData); }
|
||||
renderPiezas();
|
||||
})();`
|
||||
|
||||
Reference in New Issue
Block a user