From 84b86bb6a1fd19a3a5ac75664df16190294ddfc5 Mon Sep 17 00:00:00 2001
From: Nanobyte The API and database follow Attribution Template If you need to use the database or API in a way that violates this license, contact me with your reason and I may grant you access under a different license.
ONE_MINUTE;
+ const updateQueued = now - lastUpdate > MILLISECONDS_BETWEEN_DUMPS;
res.status(200)
@@ -72,7 +63,7 @@ export default function dumpDatabase(req: Request, res: Response, showPage: bool
for (const table of tables) {
db.prepare('run', `COPY (SELECT * FROM "${table.name}"${table.order ? ` ORDER BY "${table.order}"` : ``})
- TO '/opt/exports/${table.name}.csv' WITH (FORMAT CSV, HEADER true);`);
+ TO '${exportPath}/${table.name}.csv' WITH (FORMAT CSV, HEADER true);`);
}
}
-}
\ No newline at end of file
+}
From 514ea03655f043fa8a65b1f1666b3ffea91247b8 Mon Sep 17 00:00:00 2001
From: Nanobyte The API and database follow CC BY-NC-SA 4.0 unless you have explicit permission. The API and database follow {
+ return new Promise((resolve, reject) => {
+ // Get list of table names
+ // Create array for each table
+ const tableFiles = tableNames.reduce((obj: any, tableName) => {
+ obj[tableName] = [];
+ return obj;
+ }, {});
+ // read files in export directory
+ fs.readdir(exportPath, (err: any, files: string[]) => {
+ if (err) Logger.error(err);
+ if (err) return resolve();
+ files.forEach(file => {
+ // we only care about files that start with "https://sponsor.ajay.app/database.json, or visit this page to trigger the database dump to run.
Then, you can download the csv files below, or use the links returned from the JSON request.
Links
- ${linksHTML}
+
+
+
+
+
+
+
+ ${latestDumpFiles.map((item:any) => {
+ return `
+ Table
+ CSV
+
+
+ `;
+ }).join('')}
+ ${latestDumpFiles.length === 0 ? '${item.tableName}
+ ${item.fileName}
+ ' : ''}
+
+ Please wait: Generating files
${updateQueued ? `Update queued.` : ``} Last updated: ${lastUpdate ? new Date(lastUpdate).toUTCString() : `Unknown`}`);
} else {
res.send({
lastUpdated: lastUpdate,
updateQueued,
- links
+ links: latestDumpFiles.map((item:any) => {
+ return {
+ table: item.tableName,
+ url: `/download/${item.fileName}`,
+ size: item.fileSize,
+ };
+ }),
})
}
if (updateQueued) {
lastUpdate = Date.now();
+
+ await removeOutdatedDumps(appExportPath);
+
+ const dumpFiles = [];
for (const table of tables) {
- db.prepare('run', `COPY (SELECT * FROM "${table.name}"${table.order ? ` ORDER BY "${table.order}"` : ``})
- TO '${exportPath}/${table.name}.csv' WITH (FORMAT CSV, HEADER true);`);
+ const fileName = `${table.name}_${lastUpdate}.csv`;
+ const file = `${postgresExportPath}/${fileName}`;
+ await db.prepare('run', `COPY (SELECT * FROM "${table.name}"${table.order ? ` ORDER BY "${table.order}"` : ``})
+ TO '${file}' WITH (FORMAT CSV, HEADER true);`);
+ dumpFiles.push({
+ fileName,
+ tableName: table.name,
+ });
}
+ latestDumpFiles = [...dumpFiles];
}
}
diff --git a/src/types/config.model.ts b/src/types/config.model.ts
index c0611b7..f46cc17 100644
--- a/src/types/config.model.ts
+++ b/src/types/config.model.ts
@@ -67,7 +67,8 @@ export interface PostgresConfig {
export interface DumpDatabase {
enabled: boolean;
minTimeBetweenMs: number;
- exportPath: string;
+ appExportPath: string;
+ postgresExportPath: string;
tables: DumpDatabaseTable[];
}
From a06ab724adab93c082cb7a972c859768304b8c24 Mon Sep 17 00:00:00 2001
From: Ajay Ramachandran