From 5488b68226cced300d2b4bdb21ba03b2108c358b Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Thu, 16 Jan 2025 14:45:24 +0700 Subject: [PATCH] feat: download backup endpoint (db) --- src/controllers/backup-controller.ts | 29 +++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/controllers/backup-controller.ts b/src/controllers/backup-controller.ts index 6c0a5e0..35f59a7 100644 --- a/src/controllers/backup-controller.ts +++ b/src/controllers/backup-controller.ts @@ -1,7 +1,21 @@ -import { Body, Controller, Delete, Get, Path, Post, Put, Route, Security } from "tsoa"; +import express from "express"; +import { + Body, + Controller, + Delete, + Get, + Path, + Post, + Put, + Query, + Request, + Route, + Security, +} from "tsoa"; import HttpError from "../interfaces/http-error"; import HttpStatus from "../interfaces/http-status"; import { randomUUID } from "crypto"; +import { getFile } from "../services/minio"; function getEnvVar(environmentName: string) { const environmentValue = process.env[environmentName]; @@ -160,6 +174,19 @@ export class BackupController extends Controller { ).then(async (r) => jsonParseOrPlainText(await r.text())); } + @Get("{name}") + async downloadBackup( + @Request() req: express.Request, + @Path() name: string, + @Query() redirect?: boolean, + ) { + const url = await getFile(`${name}.sql.gz`); + if (redirect) { + return req.res?.redirect(url); + } + return url; + } + @Post("restore") async restoreBackup(@Body() body: { name: string }) { const listRunning = await this.runningRestoreStatus();