refactor(server/utils): add chapter index parameter to storyCheck function

This commit is contained in:
parent 653d5c5f32
commit 22816477eb
Signed by: tablet
GPG Key ID: 924A5F6AF051E87C
2 changed files with 5 additions and 5 deletions

@ -6,9 +6,9 @@ import { messages } from "../constants";
export default async function (
event: H3Event<EventHandlerRequest>,
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];

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