Notes/src/routes/api/database.ts

61 lines
1.5 KiB
TypeScript
Raw Normal View History

"use strict";
import sql from "../../services/sql.js";
import log from "../../services/log.js";
import backupService from "../../services/backup.js";
import anonymizationService from "../../services/anonymization.js";
import consistencyChecksService from "../../services/consistency_checks.js";
import { Request } from 'express';
import ValidationError from "../../errors/validation_error.js";
2018-01-07 14:07:59 -05:00
function getExistingBackups() {
return backupService.getExistingBackups();
2020-06-02 23:13:55 +02:00
}
async function backupDatabase() {
return {
backupFile: await backupService.backupNow("now")
};
}
2020-06-20 12:31:38 +02:00
function vacuumDatabase() {
sql.execute("VACUUM");
2017-12-23 13:16:18 -05:00
log.info("Database has been vacuumed.");
}
2017-12-23 13:16:18 -05:00
function findAndFixConsistencyIssues() {
consistencyChecksService.runOnDemandChecks(true);
}
function getExistingAnonymizedDatabases() {
return anonymizationService.getExistingAnonymizedDatabases();
}
async function anonymize(req: Request) {
if (req.params.type !== "full" && req.params.type !== "light") {
throw new ValidationError("Invalid type provided.");
}
return await anonymizationService.createAnonymizedCopy(req.params.type);
}
function checkIntegrity() {
const results = sql.getRows("PRAGMA integrity_check");
log.info(`Integrity check result: ${JSON.stringify(results)}`);
return {
results
};
}
export = {
getExistingBackups,
backupDatabase,
2019-12-10 22:03:00 +01:00
vacuumDatabase,
2020-06-02 23:13:55 +02:00
findAndFixConsistencyIssues,
getExistingAnonymizedDatabases,
anonymize,
checkIntegrity
};