fix: re-sign token

Signed-off-by: Innei <i@innei.in>
This commit is contained in:
Innei
2023-06-23 23:46:57 +08:00
parent 33539aa696
commit 719a49ca77
2 changed files with 39 additions and 35 deletions

View File

@@ -201,10 +201,10 @@ export class NoteService {
}
scheduleManager.schedule(async () => {
this.eventManager.emit(EventBusEvents.CleanAggregateCache, null, {
scope: EventScope.TO_SYSTEM,
})
await Promise.all([
this.eventManager.emit(EventBusEvents.CleanAggregateCache, null, {
scope: EventScope.TO_SYSTEM,
}),
this.imageService.saveImageDimensionsFromMarkdownText(
updated.text,
updated.images,
@@ -223,37 +223,40 @@ export class NoteService {
.exec()
},
),
async () => {
if (!updated) {
return
}
this.eventManager.broadcast(BusinessEvents.NOTE_UPDATE, updated, {
scope: EventScope.TO_SYSTEM,
})
if (updated.password || updated.hide || updated.secret) {
return
}
this.eventManager.broadcast(
BusinessEvents.NOTE_UPDATE,
{
...updated,
text: await this.textMacrosService.replaceTextMacro(
updated.text,
updated,
),
},
{
scope: EventScope.TO_VISITOR,
},
)
},
])
})
await this.boardcaseNoteUpdateEvent(updated)
return updated
}
private async boardcaseNoteUpdateEvent(updated: NoteModel) {
if (!updated) {
return
}
this.eventManager.broadcast(BusinessEvents.NOTE_UPDATE, updated, {
scope: EventScope.TO_SYSTEM,
})
if (updated.password || updated.hide || updated.secret) {
return
}
this.eventManager.broadcast(
BusinessEvents.NOTE_UPDATE,
{
...updated,
text: await this.textMacrosService.replaceTextMacro(
updated.text,
updated,
),
},
{
scope: EventScope.TO_VISITOR,
},
)
}
async deleteById(id: string) {
const doc = await this.noteModel.findById(id)
if (!doc) {

View File

@@ -54,13 +54,14 @@ export class UserController {
@CurrentUserToken() token: string,
) {
await this.userService.recordFootstep(ipLocation.ip)
const singedToken = await this.authService.jwtServicePublic.sign(user.id, {
ip: ipLocation.ip,
ua: ipLocation.agent,
})
this.authService.jwtServicePublic.revokeToken(token, 6000)
return {
token: await this.authService.jwtServicePublic
.sign(user.id, {
ip: ipLocation.ip,
ua: ipLocation.agent,
})
.then(() => this.authService.jwtServicePublic.revokeToken(token, 6000)),
token: singedToken,
}
}