Updates
This commit is contained in:
@@ -22,7 +22,7 @@ function suAddBackup(_a) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ targetUserId, }) {
|
||||
var _b, _c;
|
||||
try {
|
||||
const { mainBackupDir, userBackupDir } = (0, grab_dir_names_1.default)({
|
||||
const { mainBackupDir, userBackupDir, STATIC_ROOT, privateDataDir } = (0, grab_dir_names_1.default)({
|
||||
userId: targetUserId,
|
||||
});
|
||||
if (targetUserId && !userBackupDir) {
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ const export_mariadb_database_1 = __importDefault(require("../../../../../utils/
|
||||
function writeBackupFiles(_a) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ backup, }) {
|
||||
try {
|
||||
const { mainBackupDir, userBackupDir, sqlBackupDirName, schemasBackupDirName, targetUserPrivateDir, oldSchemasDir, } = (0, grab_dir_names_1.default)({
|
||||
const { mainBackupDir, userBackupDir, sqlBackupDirName, schemasBackupDirName, targetUserPrivateDir, oldSchemasDir, STATIC_ROOT, privateDataDir, } = (0, grab_dir_names_1.default)({
|
||||
userId: backup.user_id,
|
||||
});
|
||||
if (backup.user_id && !userBackupDir) {
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
import { DSQL_DATASQUIREL_BACKUPS } from "../../../../types/dsql";
|
||||
import { APIResponseObject } from "../../../../types";
|
||||
import { NextApiResponse } from "next";
|
||||
type Params = {
|
||||
backup: DSQL_DATASQUIREL_BACKUPS;
|
||||
res: NextApiResponse;
|
||||
};
|
||||
export default function downloadBackup({ backup, res, }: Params): Promise<APIResponseObject>;
|
||||
export {};
|
||||
@@ -0,0 +1,64 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = downloadBackup;
|
||||
const fs_1 = __importDefault(require("fs"));
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const grab_dir_names_1 = __importDefault(require("../../../../utils/backend/names/grab-dir-names"));
|
||||
const child_process_1 = require("child_process");
|
||||
function downloadBackup(_a) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ backup, res, }) {
|
||||
try {
|
||||
const { mainBackupDir, userBackupDir, tempBackupExportName } = (0, grab_dir_names_1.default)({
|
||||
userId: backup.user_id,
|
||||
});
|
||||
if (backup.user_id && !userBackupDir) {
|
||||
return {
|
||||
success: false,
|
||||
msg: `Error grabbing user backup directory`,
|
||||
};
|
||||
}
|
||||
if (!backup.uuid) {
|
||||
return {
|
||||
success: false,
|
||||
msg: `No UUID found for backup`,
|
||||
};
|
||||
}
|
||||
const allBackupsDir = backup.user_id && userBackupDir ? userBackupDir : mainBackupDir;
|
||||
const targetBackupDir = path_1.default.join(allBackupsDir, backup.uuid);
|
||||
const zipFilesCmd = (0, child_process_1.execSync)(`tar -cJf ${tempBackupExportName} ${backup.uuid}`, {
|
||||
cwd: allBackupsDir,
|
||||
});
|
||||
const exportFilePath = path_1.default.join(allBackupsDir, tempBackupExportName);
|
||||
const readStream = fs_1.default.createReadStream(exportFilePath);
|
||||
readStream.pipe(res);
|
||||
readStream.on("end", () => {
|
||||
console.log("Pipe Complete!");
|
||||
setTimeout(() => {
|
||||
(0, child_process_1.execSync)(`rm -f ${tempBackupExportName}`, {
|
||||
cwd: allBackupsDir,
|
||||
});
|
||||
}, 1000);
|
||||
});
|
||||
return { success: true };
|
||||
}
|
||||
catch (error) {
|
||||
return {
|
||||
success: false,
|
||||
msg: `Failed to write backup files`,
|
||||
error: error.message,
|
||||
};
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user