mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-08 20:47:02 +03:00
Add json page for database export
This commit is contained in:
@@ -129,7 +129,8 @@ function setupRoutes(app: Express) {
|
|||||||
app.post('/api/segmentShift', postSegmentShift);
|
app.post('/api/segmentShift', postSegmentShift);
|
||||||
|
|
||||||
if (config.postgres) {
|
if (config.postgres) {
|
||||||
app.get('/database', dumpDatabase);
|
app.get('/database', (req, res) => dumpDatabase(req, res, true));
|
||||||
|
app.get('/database.json', (req, res) => dumpDatabase(req, res, false));
|
||||||
} else {
|
} else {
|
||||||
app.get('/database.db', function (req: Request, res: Response) {
|
app.get('/database.db', function (req: Request, res: Response) {
|
||||||
res.sendFile("./databases/sponsorTimes.db", {root: "./"});
|
res.sendFile("./databases/sponsorTimes.db", {root: "./"});
|
||||||
|
|||||||
@@ -32,12 +32,14 @@ const tables = [{
|
|||||||
name: "vipUsers"
|
name: "vipUsers"
|
||||||
}];
|
}];
|
||||||
|
|
||||||
const links: string = tables.map((table) => `<p><a href="/database/${table.name}.csv">${table.name}.csv</a></p>`)
|
const links: string[] = tables.map((table) => `/database/${table.name}.csv`);
|
||||||
|
|
||||||
|
const linksHTML: string = tables.map((table) => `<p><a href="/database/${table.name}.csv">${table.name}.csv</a></p>`)
|
||||||
.reduce((acc, url) => acc + url, "");
|
.reduce((acc, url) => acc + url, "");
|
||||||
|
|
||||||
let lastUpdate = 0;
|
let lastUpdate = 0;
|
||||||
|
|
||||||
export default function dumpDatabase(req: Request, res: Response) {
|
export default function dumpDatabase(req: Request, res: Response, showPage: boolean) {
|
||||||
if (!config.postgres) {
|
if (!config.postgres) {
|
||||||
res.status(404).send("Not supported on this instance");
|
res.status(404).send("Not supported on this instance");
|
||||||
return;
|
return;
|
||||||
@@ -46,9 +48,19 @@ export default function dumpDatabase(req: Request, res: Response) {
|
|||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
const updateQueued = now - lastUpdate > ONE_MINUTE;
|
const updateQueued = now - lastUpdate > ONE_MINUTE;
|
||||||
|
|
||||||
res.status(200).send(`${styleHeader}
|
res.status(200)
|
||||||
<h1>SponsorBlock database dumps</h1>${licenseHeader}${links}<br/>
|
|
||||||
${updateQueued ? `Update queued.` : ``} Last updated: ${lastUpdate ? new Date(lastUpdate).toUTCString() : `Unknown`}`);
|
if (showPage) {
|
||||||
|
res.send(`${styleHeader}
|
||||||
|
<h1>SponsorBlock database dumps</h1>${licenseHeader}${linksHTML}<br/>
|
||||||
|
${updateQueued ? `Update queued.` : ``} Last updated: ${lastUpdate ? new Date(lastUpdate).toUTCString() : `Unknown`}`);
|
||||||
|
} else {
|
||||||
|
res.send({
|
||||||
|
lastUpdated: lastUpdate,
|
||||||
|
updateQueued,
|
||||||
|
links
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
if (updateQueued) {
|
if (updateQueued) {
|
||||||
lastUpdate = Date.now();
|
lastUpdate = Date.now();
|
||||||
|
|||||||
Reference in New Issue
Block a user