feat: upload backups

This commit is contained in:
izzy
2025-11-21 12:52:27 +00:00
parent 3d2d7fa64c
commit 19ba23056c
12 changed files with 297 additions and 13 deletions

View File

@@ -1,5 +1,7 @@
import { BadRequestException } from '@nestjs/common';
import { debounce } from 'lodash';
import { DateTime } from 'luxon';
import { stat, writeFile } from 'node:fs/promises';
import path, { join } from 'node:path';
import { PassThrough, Readable, Writable } from 'node:stream';
import { pipeline } from 'node:stream/promises';
@@ -269,6 +271,18 @@ export async function listBackups({
};
}
export async function uploadBackup(file: Express.Multer.File): Promise<void> {
const backupsFolder = StorageCore.getBaseFolder(StorageFolder.Backups);
const path = join(backupsFolder, file.originalname);
try {
await stat(path);
throw new BadRequestException('File already exists!');
} catch {
await writeFile(path, file.buffer);
}
}
function createSqlProgressStreams(cb: (progress: number) => void) {
const STDIN_START_MARKER = new TextEncoder().encode('FROM stdin');
const STDIN_END_MARKER = new TextEncoder().encode(String.raw`\.`);