Revalidate videos

This commit is contained in:
DrMint 2022-12-04 19:41:38 +01:00
parent 6a1be38613
commit 4a71f897a8
1 changed files with 24 additions and 1 deletions

View File

@ -1,6 +1,6 @@
import type { NextApiRequest, NextApiResponse } from "next"; import type { NextApiRequest, NextApiResponse } from "next";
import { i18n } from "../../../next.config"; import { i18n } from "../../../next.config";
import { cartesianProduct, filterHasAttributes } from "helpers/others"; import { cartesianProduct, filterHasAttributes, isDefined } from "helpers/others";
import { fetchLocalData } from "graphql/fetchLocalData"; import { fetchLocalData } from "graphql/fetchLocalData";
import { getReadySdk } from "graphql/sdk"; import { getReadySdk } from "graphql/sdk";
@ -26,6 +26,7 @@ type RequestProps =
| StrapiLibraryItem | StrapiLibraryItem
| StrapiPostContent | StrapiPostContent
| StrapiRangedContent | StrapiRangedContent
| StrapiVideo
| StrapiWebsiteInterface | StrapiWebsiteInterface
| StrapiWiki; | StrapiWiki;
@ -134,6 +135,15 @@ interface StrapiChronicleChapter extends StrapiEvent {
}; };
} }
interface StrapiVideo extends StrapiEvent {
event: CRUDEvents;
model: "video";
entry: {
uid: string;
channel: StrapiRelationalField;
};
}
type ResponseProps = { type ResponseProps = {
message: string; message: string;
revalidated: boolean; revalidated: boolean;
@ -293,6 +303,19 @@ const Revalidate = async (
break; break;
} }
case "video": {
if (body.entry.uid) {
paths.push(`/archives/videos`);
paths.push(`/archives/videos/v/${body.entry.uid}`);
const video = await sdk.getVideo({ uid: body.entry.uid });
const channelUid = video.videos?.data[0].attributes?.channel?.data?.attributes?.uid;
if (isDefined(channelUid)) {
paths.push(`/archives/videos/c/${channelUid}`);
}
}
break;
}
case "custom": { case "custom": {
paths.push(`${body.path}`); paths.push(`${body.path}`);
break; break;