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); }