mirror of
https://github.com/Radiquum/AniX.git
synced 2025-04-30 18:09:40 +05:00
fix: pages that use fetchDataViaGET
This commit is contained in:
parent
f9ba62d525
commit
8e56a39fe1
7 changed files with 131 additions and 55 deletions
|
@ -3,12 +3,31 @@ import { fetchDataViaGet } from "#/api/utils";
|
|||
import type { Metadata, ResolvingMetadata } from "next";
|
||||
export const dynamic = 'force-static';
|
||||
|
||||
const _getData = async (url: string) => {
|
||||
const { data, error } = await fetchDataViaGet(url);
|
||||
return [data, error];
|
||||
}
|
||||
|
||||
export async function generateMetadata({ params }, parent: ResolvingMetadata): Promise<Metadata> {
|
||||
const id:string = params.id;
|
||||
const related: any = await fetchDataViaGet(`https://api.anixart.tv/related/${id}/0`);
|
||||
const firstRelease: any = await fetchDataViaGet(`https://api.anixart.tv/release/${related.content[0].id}`);
|
||||
const previousOG = (await parent).openGraph;
|
||||
|
||||
const [ related, relatedError ] = await _getData(`https://api.anixart.tv/related/${id}/0`);
|
||||
if (relatedError || related.content.length == 0) {
|
||||
return {
|
||||
title: "Ошибка",
|
||||
description: "Ошибка",
|
||||
};
|
||||
};
|
||||
|
||||
const [ firstRelease, firstReleaseError ] = await _getData(`https://api.anixart.tv/release/${related.content[0].id}`);
|
||||
if (firstReleaseError) {
|
||||
return {
|
||||
title: "Ошибка",
|
||||
description: "Ошибка",
|
||||
};
|
||||
};
|
||||
|
||||
return {
|
||||
title: "Франшиза - " + firstRelease.release.related.name_ru || firstRelease.release.related.name,
|
||||
description: firstRelease.release.description,
|
||||
|
@ -27,7 +46,25 @@ export async function generateMetadata({ params }, parent: ResolvingMetadata): P
|
|||
|
||||
export default async function Related({ params }) {
|
||||
const id: string = params.id;
|
||||
const related: any = await fetchDataViaGet(`https://api.anixart.tv/related/${id}/0`);
|
||||
const firstRelease: any = await fetchDataViaGet(`https://api.anixart.tv/release/${related.content[0].id}`);
|
||||
const [ related, relatedError ] = await _getData(`https://api.anixart.tv/related/${id}/0`);
|
||||
if (relatedError || related.content.length == 0) {
|
||||
return <main className="flex items-center justify-center min-h-screen">
|
||||
<div className="flex flex-col gap-2">
|
||||
<h1 className="text-2xl font-bold">Ошибка</h1>
|
||||
<p className="text-lg">Произошла ошибка при загрузке франшизы. Попробуйте обновить страницу или зайдите позже.</p>
|
||||
</div>
|
||||
</main>
|
||||
};
|
||||
|
||||
const [ firstRelease, firstReleaseError ] = await _getData(`https://api.anixart.tv/release/${related.content[0].id}`);
|
||||
if (firstReleaseError) {
|
||||
return <main className="flex items-center justify-center min-h-screen">
|
||||
<div className="flex flex-col gap-2">
|
||||
<h1 className="text-2xl font-bold">Ошибка</h1>
|
||||
<p className="text-lg">Произошла ошибка при загрузке франшизы. Попробуйте обновить страницу или зайдите позже.</p>
|
||||
</div>
|
||||
</main>
|
||||
};
|
||||
|
||||
return <RelatedPage id={id} title={firstRelease.release.related.name_ru || firstRelease.release.related.name} />;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue