diff --git a/config.json.example b/config.json.example index f8548c1..d859e4d 100644 --- a/config.json.example +++ b/config.json.example @@ -38,5 +38,30 @@ "max": 20, // 20 requests in 15min time window "statusCode": 200 } + }, + "dumpDatabase": { + "enabled": true, + "minTimeBetweenMs": 60000, // 1 minute between dumps + "exportPath": "/opt/exports", + "tables": [{ + "name": "sponsorTimes", + "order": "timeSubmitted" + }, + { + "name": "userNames" + }, + { + "name": "categoryVotes" + }, + { + "name": "noSegments", + }, + { + "name": "warnings", + "order": "issueTime" + }, + { + "name": "vipUsers" + }] } } diff --git a/src/config.ts b/src/config.ts index 93c6a43..477aa72 100644 --- a/src/config.ts +++ b/src/config.ts @@ -45,7 +45,32 @@ addDefaults(config, { }, userCounterURL: null, youtubeAPIKey: null, - postgres: null + postgres: null, + dumpDatabase: { + enabled: true, + minTimeBetweenMs: 60000, + exportPath: '/opt/exports', + tables: [{ + name: "sponsorTimes", + order: "timeSubmitted" + }, + { + name: "userNames" + }, + { + name: "categoryVotes" + }, + { + name: "noSegments", + }, + { + name: "warnings", + order: "issueTime" + }, + { + name: "vipUsers" + }] + } }); // Add defaults diff --git a/src/routes/dumpDatabase.ts b/src/routes/dumpDatabase.ts index d687f07..ec3e801 100644 --- a/src/routes/dumpDatabase.ts +++ b/src/routes/dumpDatabase.ts @@ -11,26 +11,13 @@ const licenseHeader = `
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.
`; -const tables = [{ - name: "sponsorTimes", - order: "timeSubmitted" -}, -{ - name: "userNames" -}, -{ - name: "categoryVotes" -}, -{ - name: "noSegments", -}, -{ - name: "warnings", - order: "issueTime" -}, -{ - name: "vipUsers" -}]; +const tables = config?.dumpDatabase?.tables ?? []; +const MILLISECONDS_BETWEEN_DUMPS = config?.dumpDatabase?.minTimeBetweenMs ?? ONE_MINUTE; +const exportPath = config?.dumpDatabase?.exportPath ?? '/opt/exports'; + +if (tables.length === 0) { + Logger.warn('[dumpDatabase] No tables configured'); +} const links: string[] = tables.map((table) => `/database/${table.name}.csv`); @@ -40,13 +27,17 @@ const linksHTML: string = tables.map((table) => `