diff --git a/app/api/draft/disable/route.ts b/app/api/draft/disable/route.ts deleted file mode 100644 index 71f91a2..0000000 --- a/app/api/draft/disable/route.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { draftMode } from 'next/headers' - -export async function POST() { - draftMode().disable() - return new Response('Draft mode is disabled') -} diff --git a/app/api/draft/enable/route.ts b/app/api/draft/enable/route.ts deleted file mode 100644 index e0c663d..0000000 --- a/app/api/draft/enable/route.ts +++ /dev/null @@ -1,44 +0,0 @@ -import { basehub } from '@/.basehub' -import { getAritcleSlugFromSlugPath } from '@/basehub-helpers/util' -import { draftMode } from 'next/headers' -import { redirect } from 'next/navigation' - -export async function GET(request: Request) { - const { searchParams } = new URL(request.url) - const secret = searchParams.get('secret') - - if (secret !== 'TODO_SECRET') { - return new Response('Invalid token', { status: 401 }) - } - - draftMode().enable() - - let redirectTo = '/' - const next = searchParams.get('next') - const articleId = searchParams.get('article') - if (next) { - // prevent open redirect attacks - const parsedNext = new URL(next, request.url) - redirectTo = parsedNext.pathname + parsedNext.search + parsedNext.hash - } else if (articleId) { - const data = await basehub({ draft: true }).query({ - _componentInstances: { - article: { - __args: { first: 1, filter: { _sys_id: { eq: articleId } } }, - items: { - _slugPath: true, - }, - }, - }, - }) - - const article = data._componentInstances.article.items[0] - if (article) { - // _slugPath will have something like root/pages//articles//children//children/... - // remove root/pages and then filter out every other part - redirectTo = getAritcleSlugFromSlugPath(article._slugPath) - } - } - - redirect(redirectTo) -}