From d6a986d6cf455860e4c736196dfe4dbf4d3632b3 Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Wed, 1 Sep 2021 15:28:39 -0400 Subject: [PATCH 1/2] Disable shadow hidden when vip upvotes --- src/routes/voteOnSponsorTime.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routes/voteOnSponsorTime.ts b/src/routes/voteOnSponsorTime.ts index 8235364..82cc446 100644 --- a/src/routes/voteOnSponsorTime.ts +++ b/src/routes/voteOnSponsorTime.ts @@ -431,7 +431,7 @@ export async function voteOnSponsorTime(req: Request, res: Response): Promise 0 && voteTypeEnum === voteTypes.normal) { // Unide and Lock this submission - await db.prepare("run", 'UPDATE "sponsorTimes" SET locked = 1, hidden = 0 WHERE "UUID" = ?', [UUID]); + await db.prepare("run", 'UPDATE "sponsorTimes" SET locked = 1, hidden = 0, "shadowHidden" = 0 WHERE "UUID" = ?', [UUID]); // Reset video duration in case that caused it to be hidden if (videoInfo.hidden) await db.prepare("run", 'UPDATE "sponsorTimes" SET "videoDuration" = 0 WHERE "UUID" = ?', [UUID]); From e12724af15b6953e726e7e97f1c5cdca191fb9d8 Mon Sep 17 00:00:00 2001 From: Michael C Date: Wed, 1 Sep 2021 16:52:41 -0400 Subject: [PATCH 2/2] add getStatus and cases --- src/app.ts | 4 ++++ src/index.ts | 5 ++++- src/routes/getStatus.ts | 18 ++++++++++++++++++ src/utils/getCommit.ts | 4 ++++ test/cases/getStatus.ts | 25 +++++++++++++++++++++++++ test/test.ts | 3 +++ 6 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 src/routes/getStatus.ts create mode 100644 src/utils/getCommit.ts create mode 100644 test/cases/getStatus.ts diff --git a/src/app.ts b/src/app.ts index 5e97f05..1fb7e57 100644 --- a/src/app.ts +++ b/src/app.ts @@ -35,6 +35,7 @@ import {postPurgeAllSegments} from "./routes/postPurgeAllSegments"; import {getUserID} from "./routes/getUserID"; import {getLockCategories} from "./routes/getLockCategories"; import {getLockCategoriesByHash} from "./routes/getLockCategoriesByHash"; +import {getStatus } from "./routes/getStatus"; import ExpressPromiseRouter from "express-promise-router"; import { Server } from "http"; @@ -164,6 +165,9 @@ function setupRoutes(router: Router) { // get privacy protecting lock categories functions router.get("/api/lockCategories/:prefix", getLockCategoriesByHash); + // get status + router.get("/api/status", getStatus); + if (config.postgres) { router.get("/database", (req, res) => dumpDatabase(req, res, true)); router.get("/database.json", (req, res) => dumpDatabase(req, res, false)); diff --git a/src/index.ts b/src/index.ts index bb6c7df..5cc7817 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,10 +3,13 @@ import {initDb} from "./databases/databases"; import {createServer} from "./app"; import {Logger} from "./utils/logger"; import {startAllCrons} from "./cronjob"; +import { getCommit } from "./utils/getCommit"; async function init() { await initDb(); - + (global as any).HEADCOMMIT = config.mode === "development" ? "development" + : config.mode === "test" ? "test" + : getCommit() as string; createServer(() => { Logger.info(`Server started on port ${config.port}.`); diff --git a/src/routes/getStatus.ts b/src/routes/getStatus.ts new file mode 100644 index 0000000..c53d9c4 --- /dev/null +++ b/src/routes/getStatus.ts @@ -0,0 +1,18 @@ +import {db} from "../databases/databases"; +import {Logger} from "../utils/logger"; +import {Request, Response} from "express"; + +export async function getStatus(req: Request, res: Response): Promise { + try { + const dbVersion = (await db.prepare("get", "SELECT key, value FROM config where key = ?", ["version"])).value; + + return res.send({ + uptime: process.uptime(), + commit: (global as any).HEADCOMMIT || "unknown", + db: Number(dbVersion), + }); + } catch (err) { + Logger.error(err as string); + return res.sendStatus(500); + } +} diff --git a/src/utils/getCommit.ts b/src/utils/getCommit.ts new file mode 100644 index 0000000..fcc9ccc --- /dev/null +++ b/src/utils/getCommit.ts @@ -0,0 +1,4 @@ +import { execSync } from "child_process"; +const gitCommand = "git rev-parse HEAD"; + +export const getCommit = ():string => execSync(gitCommand).toString().trim(); \ No newline at end of file diff --git a/test/cases/getStatus.ts b/test/cases/getStatus.ts new file mode 100644 index 0000000..3b5f3ed --- /dev/null +++ b/test/cases/getStatus.ts @@ -0,0 +1,25 @@ +import assert from "assert"; +import fetch from "node-fetch"; +import {Done, getbaseURL} from "../utils"; + +import {db} from "../../src/databases/databases"; +let dbVersion: number; + +describe("getStatus", () => { + before(async () => { + dbVersion = (await db.prepare("get", "SELECT key, value FROM config where key = ?", ["version"])).value; + }); + + it("Should be able to get status", (done: Done) => { + fetch(`${getbaseURL()}/api/status`) + .then(async res => { + assert.strictEqual(res.status, 200); + const data = await res.json(); + assert.ok(data.uptime >= 1); // uptime should be greater than 1s + assert.strictEqual(data.commit, "test"); + assert.strictEqual(data.db, Number(dbVersion)); + done(); + }) + .catch(err => done(err)); + }); +}); diff --git a/test/test.ts b/test/test.ts index 86d4ad4..992fb01 100644 --- a/test/test.ts +++ b/test/test.ts @@ -26,6 +26,9 @@ async function init() { : "sqlite"; Logger.info(`Database Mode: ${dbMode}`); + // set commit at headCommit + (global as any).HEADCOMMIT = "test"; + // Instantiate a Mocha instance. const mocha = new Mocha();