mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-13 15:06:59 +03:00
Require time when generating key
This commit is contained in:
@@ -8,6 +8,7 @@ interface GenerateTokenRequest extends Request {
|
|||||||
code: string;
|
code: string;
|
||||||
adminUserID?: string;
|
adminUserID?: string;
|
||||||
total?: string;
|
total?: string;
|
||||||
|
key?: string;
|
||||||
},
|
},
|
||||||
params: {
|
params: {
|
||||||
type: TokenType;
|
type: TokenType;
|
||||||
@@ -15,13 +16,17 @@ 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, total }, params: { type } } = req;
|
const { query: { code, adminUserID, total, key }, params: { type } } = req;
|
||||||
const adminUserIDHash = adminUserID ? (await getHashCache(adminUserID)) : null;
|
const adminUserIDHash = adminUserID ? (await getHashCache(adminUserID)) : null;
|
||||||
|
|
||||||
if (!type || (!code && type === TokenType.patreon)) {
|
if (!type || (!code && type === TokenType.patreon)) {
|
||||||
return res.status(400).send("Invalid request");
|
return res.status(400).send("Invalid request");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (type === TokenType.free && (!key || Math.abs(Date.now() - parseInt(key)) > 1000 * 60 * 60 * 24)) {
|
||||||
|
return res.status(400).send("Invalid request");
|
||||||
|
}
|
||||||
|
|
||||||
if (type === TokenType.patreon
|
if (type === TokenType.patreon
|
||||||
|| ([TokenType.local, TokenType.gift].includes(type) && adminUserIDHash === config.adminUserID)
|
|| ([TokenType.local, TokenType.gift].includes(type) && adminUserIDHash === config.adminUserID)
|
||||||
|| type === TokenType.free) {
|
|| type === TokenType.free) {
|
||||||
|
|||||||
Reference in New Issue
Block a user