mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-14 23:47:00 +03:00
Merge pull request #513 from mchangrh/tokenValidation
add additional token validation
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import { Request, Response } from "express";
|
import { Request, Response } from "express";
|
||||||
import { config } from "../config";
|
import { config } from "../config";
|
||||||
import { createAndSaveToken, TokenType } from "../utils/tokenUtils";
|
import { createAndSaveToken, TokenType } from "../utils/tokenUtils";
|
||||||
|
import { getHashCache } from "../utils/getHashCache";
|
||||||
|
|
||||||
interface GenerateTokenRequest extends Request {
|
interface GenerateTokenRequest extends Request {
|
||||||
query: {
|
query: {
|
||||||
@@ -15,12 +15,13 @@ interface GenerateTokenRequest extends Request {
|
|||||||
|
|
||||||
export async function generateTokenRequest(req: GenerateTokenRequest, res: Response): Promise<Response> {
|
export async function generateTokenRequest(req: GenerateTokenRequest, res: Response): Promise<Response> {
|
||||||
const { query: { code, adminUserID }, params: { type } } = req;
|
const { query: { code, adminUserID }, params: { type } } = req;
|
||||||
|
const adminUserIDHash = await getHashCache(adminUserID);
|
||||||
|
|
||||||
if (!code || !type) {
|
if (!code || !type) {
|
||||||
return res.status(400).send("Invalid request");
|
return res.status(400).send("Invalid request");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type === TokenType.patreon || (type === TokenType.local && adminUserID === config.adminUserID)) {
|
if (type === TokenType.patreon || (type === TokenType.local && adminUserIDHash === config.adminUserID)) {
|
||||||
const licenseKey = await createAndSaveToken(type, code);
|
const licenseKey = await createAndSaveToken(type, code);
|
||||||
|
|
||||||
if (licenseKey) {
|
if (licenseKey) {
|
||||||
|
|||||||
Reference in New Issue
Block a user