EverydayTech Platform - Developer Reference
Complete Source Code Documentation - All Applications
Loading...
Searching...
No Matches
builderKeys.js
Go to the documentation of this file.
1// backend/utils/builderKey.js
2const crypto = require("crypto");
3const redis = require("../utils/redis");
4
5const KEY_PREFIX = "builder:key:";
6const KEY_TTL = 60 * 60 * 24 * 7; // 7 days
7
8// ------------------------------------------------------
9// Generate a new 72-char builder key
10// ------------------------------------------------------
11/**
12 *
13 */
14function generateBuilderKey() {
15 return crypto.randomBytes(36).toString("base64url");
16}
17
18// ------------------------------------------------------
19// Save key metadata
20// ------------------------------------------------------
21/**
22 *
23 * @param key
24 * @param data
25 */
26async function saveBuilderKey(key, data) {
27 await redis.setex(KEY_PREFIX + key, KEY_TTL, JSON.stringify(data));
28}
29
30// ------------------------------------------------------
31// Load metadata
32// ------------------------------------------------------
33/**
34 *
35 * @param key
36 */
37async function loadBuilderKey(key) {
38 const raw = await redis.get(KEY_PREFIX + key);
39 if (!raw) return null;
40 return JSON.parse(raw);
41}
42
43// ------------------------------------------------------
44// Touch TTL when polling download-status
45// ------------------------------------------------------
46/**
47 *
48 * @param key
49 */
50async function refreshBuilderKeyTTL(key) {
51 await redis.expire(KEY_PREFIX + key, KEY_TTL);
52}
53
54module.exports = {
55 generateBuilderKey,
56 saveBuilderKey,
57 loadBuilderKey,
58 refreshBuilderKeyTTL
59};