mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-13 23:17:02 +03:00
Better token generation
This commit is contained in:
@@ -7,6 +7,7 @@ interface GenerateTokenRequest extends Request {
|
||||
query: {
|
||||
code: string;
|
||||
adminUserID?: string;
|
||||
total?: string;
|
||||
},
|
||||
params: {
|
||||
type: TokenType;
|
||||
@@ -14,31 +15,41 @@ interface GenerateTokenRequest extends Request {
|
||||
}
|
||||
|
||||
export async function generateTokenRequest(req: GenerateTokenRequest, res: Response): Promise<Response> {
|
||||
const { query: { code, adminUserID }, params: { type } } = req;
|
||||
const { query: { code, adminUserID, total }, params: { type } } = req;
|
||||
const adminUserIDHash = adminUserID ? (await getHashCache(adminUserID)) : null;
|
||||
|
||||
if (!code || !type) {
|
||||
if (!type || (!code && type === TokenType.patreon)) {
|
||||
return res.status(400).send("Invalid request");
|
||||
}
|
||||
|
||||
if (type === TokenType.patreon || (type === TokenType.local && adminUserIDHash === config.adminUserID)) {
|
||||
const licenseKey = await createAndSaveToken(type, code);
|
||||
if (type === TokenType.patreon
|
||||
|| ([TokenType.local, TokenType.gift].includes(type) && adminUserIDHash === config.adminUserID)
|
||||
|| type === TokenType.free) {
|
||||
const licenseKey = await createAndSaveToken(type, code, adminUserIDHash === config.adminUserID ? parseInt(total) : 1);
|
||||
|
||||
/* istanbul ignore else */
|
||||
if (licenseKey) {
|
||||
return res.status(200).send(`
|
||||
<h1>
|
||||
Your license key:
|
||||
</h1>
|
||||
<p>
|
||||
<b>
|
||||
${licenseKey}
|
||||
</b>
|
||||
</p>
|
||||
<p>
|
||||
Copy this into the textbox in the other tab
|
||||
</p>
|
||||
`);
|
||||
if (type === TokenType.patreon) {
|
||||
return res.status(200).send(`
|
||||
<h1>
|
||||
Your license key:
|
||||
</h1>
|
||||
<p>
|
||||
<b>
|
||||
${licenseKey[0]}
|
||||
</b>
|
||||
</p>
|
||||
<p>
|
||||
Copy this into the textbox in the other tab
|
||||
</p>
|
||||
`);
|
||||
} else if (type === TokenType.free) {
|
||||
return res.status(200).send({
|
||||
licenseKey: licenseKey[0]
|
||||
});
|
||||
} else {
|
||||
return res.status(200).send(licenseKey.join("<br/>"));
|
||||
}
|
||||
} else {
|
||||
return res.status(401).send(`
|
||||
<h1>
|
||||
|
||||
Reference in New Issue
Block a user