refactor(server/utils): add chapter index argument to chapterTransformer
This commit is contained in:
parent
8d162c8029
commit
64f3bf23ea
@ -9,17 +9,20 @@ import getBucket from "../storyHelpers/getBucket";
|
||||
export default async function (
|
||||
story: Document<number, {}, IStory> & IStory,
|
||||
event: H3Event<EventHandlerRequest>,
|
||||
cindex?: number,
|
||||
) {
|
||||
const finObj: any = story.toObject();
|
||||
const cloned: any & { chapters: IChapter[] } = { ...finObj };
|
||||
delete finObj.chapters;
|
||||
const bucket = getBucket();
|
||||
let ds = bucket.openDownloadStreamByName(
|
||||
`/stories/${cloned.chapters[event.context.chapterIndex || 0].id}.txt`,
|
||||
`/stories/${
|
||||
cloned.chapters[cindex || event.context.chapterIndex || 0].id
|
||||
}.txt`,
|
||||
);
|
||||
let stream = await stringifyStream(ds);
|
||||
finObj.currentChapter = {
|
||||
...cloned.chapters[event.context.chapterIndex || 0],
|
||||
...cloned.chapters[cindex || event.context.chapterIndex || 0],
|
||||
text: stream
|
||||
.replace(/\n/g, "<br>")
|
||||
.replace(/<br><p>/gm, "<p>")
|
||||
|
Loading…
x
Reference in New Issue
Block a user