Merge pull request #248 from MRuy/feature/add-version-to-databasejson

Add version to database.json
This commit is contained in:
Ajay Ramachandran 2021-06-15 11:58:24 -04:00 committed by GitHub
commit 87c6dab41d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -143,6 +143,7 @@ export default async function dumpDatabase(req: Request, res: Response, showPage
${updateQueued ? `Update queued.` : ``} Last updated: ${lastUpdate ? new Date(lastUpdate).toUTCString() : `Unknown`}`);
} else {
res.send({
dbVersion: await getDbVersion(),
lastUpdated: lastUpdate,
updateQueued,
links: latestDumpFiles.map((item:any) => {
@ -158,6 +159,12 @@ export default async function dumpDatabase(req: Request, res: Response, showPage
await queueDump();
}
async function getDbVersion(): Promise<number> {
const row = await db.prepare('get', `SELECT "value" FROM "config" WHERE "key" = 'version'`);
if (row === undefined) return 0;
return row.value;
}
export async function redirectLink(req: Request, res: Response): Promise<void> {
if (!config?.dumpDatabase?.enabled) {
res.status(404).send("Database dump is disabled");
@ -210,4 +217,4 @@ async function queueDump(): Promise<void> {
updateRunning = false;
lastUpdate = startTime;
}
}
}