From 4a71f897a87d79c6b8ae05648b143aeb853fd38a Mon Sep 17 00:00:00 2001 From: DrMint Date: Sun, 4 Dec 2022 19:41:38 +0100 Subject: [PATCH] Revalidate videos --- src/pages/api/revalidate.ts | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/pages/api/revalidate.ts b/src/pages/api/revalidate.ts index 94bc324..dd49406 100644 --- a/src/pages/api/revalidate.ts +++ b/src/pages/api/revalidate.ts @@ -1,6 +1,6 @@ import type { NextApiRequest, NextApiResponse } from "next"; import { i18n } from "../../../next.config"; -import { cartesianProduct, filterHasAttributes } from "helpers/others"; +import { cartesianProduct, filterHasAttributes, isDefined } from "helpers/others"; import { fetchLocalData } from "graphql/fetchLocalData"; import { getReadySdk } from "graphql/sdk"; @@ -26,6 +26,7 @@ type RequestProps = | StrapiLibraryItem | StrapiPostContent | StrapiRangedContent + | StrapiVideo | StrapiWebsiteInterface | StrapiWiki; @@ -134,6 +135,15 @@ interface StrapiChronicleChapter extends StrapiEvent { }; } +interface StrapiVideo extends StrapiEvent { + event: CRUDEvents; + model: "video"; + entry: { + uid: string; + channel: StrapiRelationalField; + }; +} + type ResponseProps = { message: string; revalidated: boolean; @@ -293,6 +303,19 @@ const Revalidate = async ( 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": { paths.push(`${body.path}`); break;