feat: download backup endpoint (db)

This commit is contained in:
Methapon2001 2025-01-16 14:45:24 +07:00
parent 3c32096c0f
commit 5488b68226

View file

@ -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();