import { Request, Response } from "express"; import { config } from "../config"; import { createAndSaveToken, TokenType } from "../utils/tokenUtils"; interface GenerateTokenRequest extends Request { query: { code: string; adminUserID?: string; }, params: { type: TokenType; } } export async function generateTokenRequest(req: GenerateTokenRequest, res: Response): Promise { const { query: { code, adminUserID }, params: { type } } = req; if (!code || !type) { return res.status(400).send("Invalid request"); } if (type === TokenType.patreon || (type === TokenType.local && adminUserID === config.adminUserID)) { const licenseKey = await createAndSaveToken(type, code); if (licenseKey) { return res.status(200).send(`

Your license key:

${licenseKey}

Copy this into the textbox in the other tab

`); } else { return res.status(401).send(`

Failed to generate an license key

`); } } }