fix: cloned object

Signed-off-by: Innei <i@innei.in>
This commit is contained in:
Innei
2024-08-16 18:11:25 +08:00
parent 940db3fb35
commit 9a585a1fa0
4 changed files with 10 additions and 7 deletions

View File

@@ -156,7 +156,8 @@ export class NoteController {
@Put('/:id')
@Auth()
async modify(@Body() body: NoteModel, @Param() params: MongoIdDto) {
return await this.noteService.updateById(params.id, body)
await this.noteService.updateById(params.id, body)
return this.noteService.findOneByIdOrNid(params.id)
}
@Patch('/:id')

View File

@@ -48,12 +48,11 @@ export class PageService {
this.imageService.saveImageDimensionsFromMarkdownText(
doc.text,
res.images,
(images) => {
async (images) => {
res.images = images
return res.save().then(() => {
this.eventManager.broadcast(BusinessEvents.PAGE_UPDATE, res, {
scope: EventScope.TO_SYSTEM,
})
await res.save()
this.eventManager.broadcast(BusinessEvents.PAGE_UPDATE, res, {
scope: EventScope.TO_SYSTEM,
})
},
)

View File

@@ -82,11 +82,13 @@ export class PostService {
})
const doc = newPost.toJSON()
const cloned = { ...doc }
// 双向关联
await this.relatedEachOther(doc, relatedIds)
scheduleManager.schedule(async () => {
const doc = cloned
await Promise.all([
this.imageService.saveImageDimensionsFromMarkdownText(
doc.text,

View File

@@ -38,8 +38,9 @@ export class ImageService implements OnModuleInit {
const result = [] as ImageModel[]
const oldImagesMap = new Map(
(originImages ?? []).map((image) => [image.src, image]),
(originImages ?? []).map((image) => [image.src, { ...image }]),
)
const task = [] as Promise<ImageModel>[]
for (const src of newImages) {
const originImage = oldImagesMap.get(src)