mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-10 21:47:02 +03:00
more endpoints!
This commit is contained in:
@@ -3,6 +3,7 @@ import {Logger} from "../utils/logger";
|
|||||||
import {Request, Response} from "express";
|
import {Request, Response} from "express";
|
||||||
|
|
||||||
export async function getStatus(req: Request, res: Response): Promise<Response> {
|
export async function getStatus(req: Request, res: Response): Promise<Response> {
|
||||||
|
const startTime = Date.now();
|
||||||
let value = req.params.value as string[] | string;
|
let value = req.params.value as string[] | string;
|
||||||
value = Array.isArray(value) ? value[0] : value;
|
value = Array.isArray(value) ? value[0] : value;
|
||||||
try {
|
try {
|
||||||
@@ -11,6 +12,8 @@ export async function getStatus(req: Request, res: Response): Promise<Response>
|
|||||||
uptime: process.uptime(),
|
uptime: process.uptime(),
|
||||||
commit: (global as any).HEADCOMMIT || "unknown",
|
commit: (global as any).HEADCOMMIT || "unknown",
|
||||||
db: Number(dbVersion),
|
db: Number(dbVersion),
|
||||||
|
startTime,
|
||||||
|
processTime: Date.now() - startTime,
|
||||||
};
|
};
|
||||||
return value ? res.send(String(statusValues[value])) : res.send(statusValues);
|
return value ? res.send(String(statusValues[value])) : res.send(statusValues);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
@@ -15,9 +15,11 @@ describe("getStatus", () => {
|
|||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
assert.ok(data.uptime >= 1); // uptime should be greater than 1s
|
assert.ok(data.uptime); // uptime should be greater than 1s
|
||||||
assert.strictEqual(data.commit, "test");
|
assert.strictEqual(data.commit, "test");
|
||||||
assert.strictEqual(data.db, Number(dbVersion));
|
assert.strictEqual(data.db, Number(dbVersion));
|
||||||
|
assert.ok(data.startTime);
|
||||||
|
assert.ok(data.processTime >= 0);
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
@@ -28,7 +30,6 @@ describe("getStatus", () => {
|
|||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.text();
|
const data = await res.text();
|
||||||
console.log(data);
|
|
||||||
assert.ok(Number(data) >= 1); // uptime should be greater than 1s
|
assert.ok(Number(data) >= 1); // uptime should be greater than 1s
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
@@ -40,7 +41,6 @@ describe("getStatus", () => {
|
|||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.text();
|
const data = await res.text();
|
||||||
console.log(data);
|
|
||||||
assert.strictEqual(data, "test"); // commit should be test
|
assert.strictEqual(data, "test"); // commit should be test
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
@@ -52,10 +52,32 @@ describe("getStatus", () => {
|
|||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.text();
|
const data = await res.text();
|
||||||
console.log(data);
|
|
||||||
assert.strictEqual(Number(data), Number(dbVersion)); // commit should be test
|
assert.strictEqual(Number(data), Number(dbVersion)); // commit should be test
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("Should be able to get startTime only", (done: Done) => {
|
||||||
|
fetch(`${getbaseURL()}/api/status/startTime`)
|
||||||
|
.then(async res => {
|
||||||
|
assert.strictEqual(res.status, 200);
|
||||||
|
const data = await res.text();
|
||||||
|
const now = Date.now();
|
||||||
|
assert.ok(Number(data) <= now); // startTime should be more than now
|
||||||
|
done();
|
||||||
|
})
|
||||||
|
.catch(err => done(err));
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Should be able to get processTime only", (done: Done) => {
|
||||||
|
fetch(`${getbaseURL()}/api/status/processTime`)
|
||||||
|
.then(async res => {
|
||||||
|
assert.strictEqual(res.status, 200);
|
||||||
|
const data = await res.text();
|
||||||
|
assert.ok(Number(data) >= 0);
|
||||||
|
done();
|
||||||
|
})
|
||||||
|
.catch(err => done(err));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user