fix(stabilization): resolved media object fragility and refined sidebar error boundaries
This commit is contained in:
parent
5736efc915
commit
4c7c4d1468
@ -51,12 +51,14 @@ export async function GlobalTopBanner() {
|
||||
}
|
||||
|
||||
export async function GlobalSidebar() {
|
||||
const { createAdminClient } = await import('@/lib/appwrite.server');
|
||||
const client = await createAdminClient();
|
||||
let settings = { rotation_seconds: 5 };
|
||||
let groupedAds: Record<string, any[]> = {};
|
||||
let settings = await fetchSettings();
|
||||
|
||||
try {
|
||||
settings = await fetchSettings();
|
||||
const client = await createAdminClient();
|
||||
|
||||
// 1. Obtener tipos válidos para sidebar
|
||||
const typesRes = await client.databases.listDocuments(APPWRITE_ALMEIRA_CONFIG.databaseId, 'publication_types', []);
|
||||
const validCodes = ['DISPLAY_SLIDER', 'EVENTO', 'CLASIFICADO', 'AD_BANNER'];
|
||||
const validTypeIds = typesRes.documents.filter(t => validCodes.includes(t.codigo)).map(t => t.$id);
|
||||
@ -70,7 +72,9 @@ export async function GlobalSidebar() {
|
||||
|
||||
const now = new Date();
|
||||
const activePosts = postsRes.documents.filter(post => {
|
||||
if (!post.tipo_publicacion_id || !validTypeIds.includes(post.tipo_publicacion_id)) return false;
|
||||
if (!post.tipo_publicacion_id) return false;
|
||||
const typeId = typeof post.tipo_publicacion_id === 'string' ? post.tipo_publicacion_id : post.tipo_publicacion_id.$id;
|
||||
if (!validTypeIds.includes(typeId)) return false;
|
||||
if (post.fecha_finalizacion && new Date(post.fecha_finalizacion) < now) return false;
|
||||
return true;
|
||||
});
|
||||
@ -79,18 +83,16 @@ export async function GlobalSidebar() {
|
||||
let slogan = 'Patrocinado';
|
||||
if (post.cliente_id) {
|
||||
try {
|
||||
const client_id = typeof post.cliente_id === 'string' ? post.cliente_id : post.cliente_id.$id;
|
||||
const contracts = await client.databases.listDocuments(APPWRITE_ALMEIRA_CONFIG.databaseId, 'contracts', [
|
||||
Query.equal('cliente_id', post.cliente_id),
|
||||
Query.equal('cliente_id', client_id),
|
||||
Query.equal('estado', 'Activo'),
|
||||
Query.limit(1)
|
||||
]);
|
||||
if (contracts.documents.length > 0 && contracts.documents[0].eslogan) {
|
||||
slogan = contracts.documents[0].eslogan;
|
||||
} else {
|
||||
// Fallback to client name if we can fetch it or if it's in the object
|
||||
slogan = 'Patrocinado';
|
||||
}
|
||||
} catch(e) { slogan = 'Patrocinado'; }
|
||||
} catch(e) {}
|
||||
}
|
||||
|
||||
if (!groupedAds[slogan]) groupedAds[slogan] = [];
|
||||
@ -108,7 +110,6 @@ export async function GlobalSidebar() {
|
||||
|
||||
export async function hasSidebarContent(): Promise<boolean> {
|
||||
try {
|
||||
const { createAdminClient } = await import('@/lib/appwrite.server');
|
||||
const client = await createAdminClient();
|
||||
const typesRes = await client.databases.listDocuments(APPWRITE_ALMEIRA_CONFIG.databaseId, 'publication_types', []);
|
||||
const validCodes = ['DISPLAY_SLIDER', 'EVENTO', 'CLASIFICADO', 'AD_BANNER'];
|
||||
@ -123,11 +124,16 @@ export async function hasSidebarContent(): Promise<boolean> {
|
||||
|
||||
const now = new Date();
|
||||
return postsRes.documents.some(post => {
|
||||
if (!post.tipo_publicacion_id || !validTypeIds.includes(post.tipo_publicacion_id)) return false;
|
||||
if (!post.tipo_publicacion_id) return false;
|
||||
const typeId = typeof post.tipo_publicacion_id === 'string' ? post.tipo_publicacion_id : post.tipo_publicacion_id.$id;
|
||||
if (!validTypeIds.includes(typeId)) return false;
|
||||
if (post.fecha_finalizacion && new Date(post.fecha_finalizacion) < now) return false;
|
||||
return true;
|
||||
});
|
||||
} catch(e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -45,7 +45,14 @@ function ClientCarouselGroup({ eslogan, ads, rotationSeconds }: { eslogan: strin
|
||||
const ENDPOINT = process.env.NEXT_PUBLIC_APPWRITE_ENDPOINT || 'https://appwrite.almeira.com.co/v1';
|
||||
const PROJECT_ID = process.env.NEXT_PUBLIC_APPWRITE_PROJECT_ID || '69b84df5003bd8957c5c';
|
||||
|
||||
const imgUrl = `${ENDPOINT}/storage/buckets/${activeAd.imagen_destacada_id.bucket_id}/files/${activeAd.imagen_destacada_id.file_id}/view?project=${PROJECT_ID}`;
|
||||
let imgUrl = activeAd.og_image_url || null;
|
||||
if (activeAd.imagen_destacada_id) {
|
||||
if (typeof activeAd.imagen_destacada_id === 'object' && activeAd.imagen_destacada_id.bucket_id) {
|
||||
imgUrl = `${ENDPOINT}/storage/buckets/${activeAd.imagen_destacada_id.bucket_id}/files/${activeAd.imagen_destacada_id.file_id}/view?project=${PROJECT_ID}`;
|
||||
} else if (typeof activeAd.imagen_destacada_id === 'string') {
|
||||
imgUrl = `${ENDPOINT}/storage/buckets/media/files/${activeAd.imagen_destacada_id}/view?project=${PROJECT_ID}`;
|
||||
}
|
||||
}
|
||||
|
||||
const recordClickAndGo = () => {
|
||||
fetch('/api/metrics', {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user