Serve database csv from node

This commit is contained in:
Ajay Ramachandran
2021-12-04 22:55:36 -05:00
parent e3042f7623
commit 4964c72e71
2 changed files with 8 additions and 5 deletions

View File

@@ -31,7 +31,7 @@ const licenseHeader = `<p>The API and database follow <a href="https://creativec
const tables = config?.dumpDatabase?.tables ?? [];
const MILLISECONDS_BETWEEN_DUMPS = config?.dumpDatabase?.minTimeBetweenMs ?? ONE_MINUTE;
const appExportPath = config?.dumpDatabase?.appExportPath ?? "./docker/database-export";
export const appExportPath = config?.dumpDatabase?.appExportPath ?? "./docker/database-export";
const postgresExportPath = config?.dumpDatabase?.postgresExportPath ?? "/opt/exports";
const tableNames = tables.map(table => table.name);
@@ -182,15 +182,16 @@ export async function redirectLink(req: Request, res: Response): Promise<void> {
const file = latestDumpFiles.find((value) => `/database/${value.tableName}.csv` === req.path);
updateQueueTime();
if (file) {
res.redirect(`/download/${file.fileName}`);
} else {
res.sendStatus(404);
}
if (req.query.generate !== "false") await queueDump();
if (req.query.generate !== "false"){
updateQueueTime();
await queueDump();
}
}
function updateQueueTime(): void {