From b7b65a966b00b13e1b4eb1d92594049bf0410f3d Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Tue, 1 Apr 2025 09:05:08 +0700 Subject: [PATCH] feat: add triggered by metadata --- src/controllers/backup-controller.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/controllers/backup-controller.ts b/src/controllers/backup-controller.ts index 7ae4ba3..ffe98ae 100644 --- a/src/controllers/backup-controller.ts +++ b/src/controllers/backup-controller.ts @@ -131,7 +131,7 @@ export class BackupController extends Controller { @Post("create") @Security("keycloak") async runBackup( - @Request() req: Request & { user: { sub: string } }, + @Request() req: Request & { user: { sub: string; preferred_username: string } }, @Body() body?: { name?: string }, ) { const timestamp = Math.round(Date.now() / 1000); @@ -177,6 +177,10 @@ export class BackupController extends Controller { db_password: DB_PASSWORD, db_list: DB_LIST?.replaceAll(",", " "), }, + metadata: { + triggered_by: req.user.preferred_username, + triggered_by_id: req.user.sub, + }, }), }, ).then(async (r) => jsonParseOrPlainText(await r.text())); @@ -198,7 +202,10 @@ export class BackupController extends Controller { @Post("restore") @Security("keycloak") - async restoreBackup(@Body() body: { name: string }) { + async restoreBackup( + @Request() req: Request & { user: { sub: string; preferred_username: string } }, + @Body() body: { name: string }, + ) { const listRunning = await this.runningRestoreStatus(); if (!listRunning || listRunning.length > 0) { @@ -234,6 +241,10 @@ export class BackupController extends Controller { db_user: DB_USERNAME, db_password: DB_PASSWORD, }, + metadata: { + triggered_by: req.user.preferred_username, + triggered_by_id: req.user.sub, + }, }), }, ).then(async (r) => jsonParseOrPlainText(await r.text()));