From 22816477eb9c923e37a8f2ed54e6df13f4a86f58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=98=99=E2=97=A6=20The=20Tablet=20=E2=9D=80=20GamerGirla?= =?UTF-8?q?ndCo=20=E2=97=A6=E2=9D=A7?= Date: Wed, 6 Dec 2023 21:59:34 -0500 Subject: [PATCH] refactor(server/utils): add chapter index parameter to `storyCheck` function --- lib/server/middlewareButNotReally/storyCheck.ts | 8 ++++---- server/api/story/[id]/index.get.ts | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/server/middlewareButNotReally/storyCheck.ts b/lib/server/middlewareButNotReally/storyCheck.ts index cfe3dcc..cb42b0a 100644 --- a/lib/server/middlewareButNotReally/storyCheck.ts +++ b/lib/server/middlewareButNotReally/storyCheck.ts @@ -6,9 +6,9 @@ import { messages } from "../constants"; export default async function ( event: H3Event, story: IStory, + idx: number, ) { let ret: any = {}; - let num: number = event.context.chapterIndex; if (story.ficmas != null) { if (isFicmasHidden(story)) { ret = { @@ -18,9 +18,9 @@ export default async function ( } } if ( - story.chapters[num]?.hidden || - (event.context.currentUser?._id !== story.author._id && - !event.context.currentUser?.profile.isAdmin) + story.chapters[idx]?.hidden && + event.context.currentUser?._id !== story.author._id && + !event.context.currentUser?.profile.isAdmin ) { ret.statusCode = 403; ret.message = messages[403]; diff --git a/server/api/story/[id]/index.get.ts b/server/api/story/[id]/index.get.ts index 9a55eaa..9246678 100644 --- a/server/api/story/[id]/index.get.ts +++ b/server/api/story/[id]/index.get.ts @@ -2,7 +2,7 @@ import queryStory from "~/lib/server/dbHelpers/storyQuerier"; import storyCheck from "~/lib/server/middlewareButNotReally/storyCheck"; export default eventHandler(async (ev) => { const story = await queryStory(ev); - let chrs = await storyCheck(ev, story); + let chrs = await storyCheck(ev, story, 0); if (chrs != null) { throw createError(chrs); }