diff --git a/src/routes/v1/validate.ts b/src/routes/v1/validate.ts index ce0c874..e3d736d 100644 --- a/src/routes/v1/validate.ts +++ b/src/routes/v1/validate.ts @@ -1,5 +1,5 @@ import { Request, Response, Router } from "express"; -import { validateLicense } from "@controller/validation"; +import { validateLicense, signOfflineKey } from "@controller/validation"; const app: Router = Router(); @@ -10,4 +10,18 @@ app.get("/:licenseKey", async (req: Request, res: Response) => { res.json(await validateLicense(validationKey, req.params.licenseKey)); }); +app.get("/:licenseKey/sign", async (req: Request, res: Response) => { + const validationKey = req.header("X-Validation-Key"); + if (!validationKey) return res.status(400).json({ code: 1, message: "You need to provide a validation key" }); + + const offlineKey = await signOfflineKey(validationKey, req.params.licenseKey); + + if (offlineKey.status !== "VALID") return res.json(offlineKey); + + res.header("Content-Type", "application/octet-stream") + .header("Content-Disposition", `attachment; filename=${req.params.licenseKey}.lkey`) + .send(offlineKey.file); + +}); + export default app; \ No newline at end of file