a fun bot for the hc slack
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: use hackclub cdn for modal uploads

dunkirk.sh b0a69bd1 a8c672b1

verified
+47 -18
+1
README.md
··· 36 36 API_URL="https://casual-renewing-reptile.ngrok-free.app" 37 37 SENTRY_DSN="https://xxxxxx@xxxxxx.ingest.us.sentry.io/xxxx" 38 38 DATABASE_URL="postgres://username:password@host:5432/smokie" 39 + CDN_TOKEN="cdn_token" 39 40 ``` 40 41 41 42 ## 📜 License
+8 -18
src/features/takes/handlers/settings.ts
··· 10 10 HACKATIME_VERSIONS, 11 11 type HackatimeVersion, 12 12 } from "../../../libs/hackatime"; 13 + import { deployToHackClubCDN } from "../../../libs/cdn"; 13 14 14 15 export async function handleSettings( 15 16 triggerID: string, ··· 192 193 const values = payload.view.state.values; 193 194 const userId = body.user.id; 194 195 195 - const file = values.project_banner?.project_banner_input 196 - ?.files?.[0] as UploadedFile; 196 + const file = [ 197 + values.project_banner?.project_banner_input?.files?.[0] 198 + ?.url_private_download as string, 199 + ]; 197 200 try { 198 - // If file is already public, use it directly 199 - const fileData = file.is_public 200 - ? file 201 - : ( 202 - await slackClient.files.sharedPublicURL({ 203 - file: file.id, 204 - token: process.env.SLACK_USER_TOKEN, 205 - }) 206 - ).file; 207 - 208 - const html = await ( 209 - await fetch(fileData?.permalink_public as string) 210 - ).text(); 211 - const projectBannerUrl = html.match( 212 - /https:\/\/files.slack.com\/files-pri\/[^"]+pub_secret=([^"&]*)/, 213 - )?.[0]; 201 + const projectBannerUrl = await deployToHackClubCDN(file).then( 202 + (res) => res.files[0]?.deployedUrl, 203 + ); 214 204 215 205 const hackatimeVersion = values.hackatime_version 216 206 ?.hackatime_version_input?.selected_option
+38
src/libs/cdn.ts
··· 1 + export type DeployedFile = { 2 + deployedUrl: string; 3 + file: string; 4 + sha: string; 5 + size: number; 6 + }; 7 + 8 + export 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 + */ 20 + export 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 + }