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 ( | export default async function ( | ||||||
| 	story: Document<number, {}, IStory> & IStory, | 	story: Document<number, {}, IStory> & IStory, | ||||||
| 	event: H3Event<EventHandlerRequest>, | 	event: H3Event<EventHandlerRequest>, | ||||||
|  | 	cindex?: number, | ||||||
| ) { | ) { | ||||||
| 	const finObj: any = story.toObject(); | 	const finObj: any = story.toObject(); | ||||||
| 	const cloned: any & { chapters: IChapter[] } = { ...finObj }; | 	const cloned: any & { chapters: IChapter[] } = { ...finObj }; | ||||||
| 	delete finObj.chapters; | 	delete finObj.chapters; | ||||||
| 	const bucket = getBucket(); | 	const bucket = getBucket(); | ||||||
| 	let ds = bucket.openDownloadStreamByName( | 	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); | 	let stream = await stringifyStream(ds); | ||||||
| 	finObj.currentChapter = { | 	finObj.currentChapter = { | ||||||
| 		...cloned.chapters[event.context.chapterIndex || 0], | 		...cloned.chapters[cindex || event.context.chapterIndex || 0], | ||||||
| 		text: stream | 		text: stream | ||||||
| 			.replace(/\n/g, "<br>") | 			.replace(/\n/g, "<br>") | ||||||
| 			.replace(/<br><p>/gm, "<p>") | 			.replace(/<br><p>/gm, "<p>") | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user