mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-08 20:47:02 +03:00
Add endpoints for config setting
This commit is contained in:
@@ -60,6 +60,8 @@ import { getReady } from "./routes/getReady";
|
|||||||
import { getMetrics } from "./routes/getMetrics";
|
import { getMetrics } from "./routes/getMetrics";
|
||||||
import { getSegmentID } from "./routes/getSegmentID";
|
import { getSegmentID } from "./routes/getSegmentID";
|
||||||
import { postCasual } from "./routes/postCasual";
|
import { postCasual } from "./routes/postCasual";
|
||||||
|
import { getConfigEndpoint } from "./routes/getConfig";
|
||||||
|
import { setConfig } from "./routes/setConfig";
|
||||||
|
|
||||||
export function createServer(callback: () => void): Server {
|
export function createServer(callback: () => void): Server {
|
||||||
// Create a service (the app object is just a callback).
|
// Create a service (the app object is just a callback).
|
||||||
@@ -235,6 +237,9 @@ function setupRoutes(router: Router, server: Server) {
|
|||||||
router.get("/api/branding/:prefix", getBrandingByHashEndpoint);
|
router.get("/api/branding/:prefix", getBrandingByHashEndpoint);
|
||||||
router.post("/api/branding", postBranding);
|
router.post("/api/branding", postBranding);
|
||||||
|
|
||||||
|
router.get("/api/config", getConfigEndpoint);
|
||||||
|
router.get("/api/config", setConfig);
|
||||||
|
|
||||||
router.post("/api/casual", postCasual);
|
router.post("/api/casual", postCasual);
|
||||||
|
|
||||||
/* istanbul ignore next */
|
/* istanbul ignore next */
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
import { getHashCache } from "../utils/getHashCache";
|
import { getHashCache } from "../utils/getHashCache";
|
||||||
import { db } from "../databases/databases";
|
|
||||||
import { Request, Response } from "express";
|
import { Request, Response } from "express";
|
||||||
import { isUserVIP } from "../utils/isUserVIP";
|
import { isUserVIP } from "../utils/isUserVIP";
|
||||||
import { UserID } from "../types/user.model";
|
import { UserID } from "../types/user.model";
|
||||||
import { Logger } from "../utils/logger";
|
import { Logger } from "../utils/logger";
|
||||||
|
import { getServerConfig } from "../utils/serverConfig";
|
||||||
|
|
||||||
export async function getConfig(req: Request, res: Response): Promise<Response> {
|
export async function getConfigEndpoint(req: Request, res: Response): Promise<Response> {
|
||||||
const userID = req.query.userID as string;
|
const userID = req.query.userID as string;
|
||||||
const key = req.query.key as string;
|
const key = req.query.key as string;
|
||||||
|
|
||||||
@@ -24,10 +24,8 @@ export async function getConfig(req: Request, res: Response): Promise<Response>
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const row = await db.prepare("run", `SELECT "value" FROM "config" WHERE "key" = ?`, [key]);
|
|
||||||
|
|
||||||
return res.status(200).json({
|
return res.status(200).json({
|
||||||
value: row.value
|
value: getServerConfig(key)
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
Logger.error(e as string);
|
Logger.error(e as string);
|
||||||
|
|||||||
7
src/utils/serverConfig.ts
Normal file
7
src/utils/serverConfig.ts
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
import { db } from "../databases/databases";
|
||||||
|
|
||||||
|
export async function getServerConfig(key: string): Promise<string | null> {
|
||||||
|
const row = await db.prepare("run", `SELECT "value" FROM "config" WHERE "key" = ?`, [key]);
|
||||||
|
|
||||||
|
return row?.value ?? null;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user