a fun bot for the hc slack
1export type DeployedFile = {
2 deployedUrl: string;
3 file: string;
4 sha: string;
5 size: number;
6};
7
8export type DeployResponse = {
9 files: DeployedFile[];
10 cdnBase: string;
11};
12
13/**
14 * Deploys files to the Hack Club CDN
15 * @param fileUrls Array of URLs to deploy
16 * @param token Authorization token
17 * @param downloadToken Download authorization token
18 * @returns Promise that resolves to the deployment response
19 */
20export async function deployToHackClubCDN(
21 fileUrls: string[],
22): Promise<DeployResponse> {
23 const response = await fetch("https://cdn.hackclub.com/api/v3/new", {
24 method: "POST",
25 headers: {
26 Authorization: `Bearer ${process.env.CDN_TOKEN}`,
27 "X-Download-Authorization": `Bearer ${process.env.SLACK_BOT_TOKEN}`,
28 "Content-Type": "application/json",
29 },
30 body: JSON.stringify(fileUrls),
31 });
32
33 if (!response.ok) {
34 throw new Error(`Failed to deploy files: ${response.statusText}`);
35 }
36
37 return response.json();
38}