2023-10-02 15:44:55 -04:00
|
|
|
import type { H3Event, EventHandlerRequest } from "h3";
|
|
|
|
import type { Document } from "mongoose";
|
|
|
|
import { isFicmasHidden } from "~/lib/functions";
|
|
|
|
import { IStory } from "~/models/stories";
|
2023-10-03 00:50:00 -04:00
|
|
|
import { messages } from "../constants";
|
2023-10-02 15:44:55 -04:00
|
|
|
export default async function (
|
|
|
|
event: H3Event<EventHandlerRequest>,
|
|
|
|
story: IStory,
|
2023-12-06 21:59:34 -05:00
|
|
|
idx: number,
|
2023-10-02 15:44:55 -04:00
|
|
|
) {
|
|
|
|
let ret: any = {};
|
|
|
|
if (story.ficmas != null) {
|
|
|
|
if (isFicmasHidden(story)) {
|
|
|
|
ret = {
|
|
|
|
statusCode: 423,
|
|
|
|
message: `TOP SECRET! This story is part of an ongoing challenge. You'll be able to read it after the challenge's reveal date.`,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (
|
2023-12-06 21:59:34 -05:00
|
|
|
story.chapters[idx]?.hidden &&
|
|
|
|
event.context.currentUser?._id !== story.author._id &&
|
|
|
|
!event.context.currentUser?.profile.isAdmin
|
2023-10-02 15:44:55 -04:00
|
|
|
) {
|
|
|
|
ret.statusCode = 403;
|
2023-10-03 00:50:00 -04:00
|
|
|
ret.message = messages[403];
|
2023-10-02 15:44:55 -04:00
|
|
|
}
|
|
|
|
return !!Object.keys(ret).length ? ret : null;
|
|
|
|
}
|