-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgenUtAPIKey.ts
More file actions
39 lines (38 loc) · 1.08 KB
/
genUtAPIKey.ts
File metadata and controls
39 lines (38 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import z from "zod";
import { APP_ID, BASE_URL, API_SECRET } from "lib/constants";
const ConfigSchema = z.object({
apiKey: z.string(),
appId: z.string(),
regions: z.array(z.string()),
ingestHost: z.string(),
});
type Config = z.infer<typeof ConfigSchema>;
/**
* Reads API_SECRET from env, validates it, and
* encodes the config to Base64.
*/
export function encodeConfigToBase64(): string {
if (!API_SECRET) {
throw new Error("Missing API_SECRET in environment variables");
}
if (!API_SECRET.startsWith("sk_")) {
throw new Error('API_SECRET must start with "sk_"');
}
// even though the ingets url doesn't do anything as it handled by another env variable in the ut app
const config: Config = {
apiKey: API_SECRET,
appId: APP_ID,
regions: ["us-east-1"],
ingestHost: BASE_URL,
};
const jsonString = JSON.stringify(config);
return Buffer.from(jsonString).toString("base64");
}
try {
const base64 = encodeConfigToBase64();
console.log("Here is your uploadthing token");
console.log(base64);
} catch (err) {
console.error(err);
process.exit(1);
}