mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-19 22:18:35 +03:00
38 lines
1.0 KiB
TypeScript
38 lines
1.0 KiB
TypeScript
import { getHashCache } from "../utils/getHashCache";
|
|
import { db } from "../databases/databases";
|
|
import { Request, Response } from "express";
|
|
import { isUserVIP } from "../utils/isUserVIP";
|
|
import { UserID } from "../types/user.model";
|
|
import { Logger } from "../utils/logger";
|
|
|
|
export async function getConfig(req: Request, res: Response): Promise<Response> {
|
|
const userID = req.query.userID as string;
|
|
const key = req.query.key as string;
|
|
|
|
if (!userID || !key) {
|
|
// invalid request
|
|
return res.sendStatus(400);
|
|
}
|
|
|
|
// hash the userID
|
|
const hashedUserID = await getHashCache(userID as UserID);
|
|
const isVIP = (await isUserVIP(hashedUserID));
|
|
|
|
if (!isVIP) {
|
|
// not authorized
|
|
return res.sendStatus(403);
|
|
}
|
|
|
|
try {
|
|
const row = await db.prepare("run", `SELECT "value" FROM "config" WHERE "key" = ?`, [key]);
|
|
|
|
return res.status(200).json({
|
|
value: row.value
|
|
});
|
|
} catch (e) {
|
|
Logger.error(e as string);
|
|
|
|
return res.sendStatus(500);
|
|
}
|
|
}
|