canina/frontend/application/app/videos/page.tsx
parsaaghayi bd49fbc4a0
Some checks failed
Deploy Canina / deploy (push) Successful in 2m25s
E2E Playwright Tests / Run Full E2E & Security Suites (push) Failing after 7s
fix(security): remediate audit vulnerabilities SEC-001 through SEC-023
2026-09-23 23:00:25 +03:30

75 lines
2.8 KiB
TypeScript

import type { Metadata } from 'next';
import VideosPage from "../../components/VideosPage";
import { getPageMetadata } from "../../lib/seo";
import { generateVideoObjectSchema, generateBreadcrumbSchema, safeJsonLd } from "../../lib/schema";
export async function generateMetadata(): Promise<Metadata> {
return getPageMetadata('videos', {
canonicalPath: '/videos',
fallbackTitle: 'ویدئوهای آموزشی و توصیه‌های بالینی دامپزشکان',
fallbackDesc: 'مشاهده ویدئوهای تخصصی نحوه مصرف مکمل‌های درمانی، نظرات دامپزشکان و راهکارهای بالینی تصویری کنینا آلمان.',
});
}
async function getInitialVideos() {
const apiUrl = process.env.INTERNAL_API_URL || process.env.NEXT_PUBLIC_API_URL || 'http://localhost:4001/api';
const apiBase = apiUrl.endsWith('/api') ? apiUrl : `${apiUrl.replace(/\/$/, '')}/api`;
try {
const res = await fetch(`${apiBase}/videos?limit=20`, {
next: { revalidate: 3600, tags: ['videos'] },
});
if (!res.ok) return [];
const data = await res.json();
return Array.isArray(data) ? data : Array.isArray(data.data) ? data.data : [];
} catch (e) {
console.error('[Videos] Error fetching server videos for schema:', e);
return [];
}
}
export default async function Videos() {
const videos = await getInitialVideos();
const videoSchemas = videos.map((v: any) =>
generateVideoObjectSchema({
name: v.title || 'ویدیو آموزشی کنینا',
description: v.description || `آموزش و توصیه‌های تخصصی دامپزشکی درباره مصرف مکمل‌های درمانی کنینا توسط ${v.doctor || 'متخصصین کنینا'}.`,
thumbnailUrl: v.coverUrl || v.thumbnail || 'https://canina.ir/assets/images/logo.png',
uploadDate: v.createdAt || '2025-01-01T00:00:00Z',
contentUrl: v.videoUrl || undefined,
embedUrl: v.videoUrl || undefined,
})
);
const breadcrumbs = generateBreadcrumbSchema([
{ name: 'صفحه اصلی', url: 'https://canina.ir' },
{ name: 'آکادمی ویدیوها', url: 'https://canina.ir/videos' },
]);
const itemListSchema = {
'@context': 'https://schema.org',
'@type': 'ItemList',
itemListElement: videoSchemas.map((vSchema: any, idx: number) => ({
'@type': 'ListItem',
position: idx + 1,
item: vSchema,
})),
};
return (
<>
{videoSchemas.length > 0 && (
<script
type="application/ld+json"
dangerouslySetInnerHTML={{ __html: safeJsonLd(itemListSchema) }}
/>
)}
<script
type="application/ld+json"
dangerouslySetInnerHTML={{ __html: safeJsonLd(breadcrumbs) }}
/>
<VideosPage />
</>
);
}