This repository has no description
0

Configure Feed

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

feat: speed up file deployment

+55 -4
+55 -4
src/features/takes/handlers/upload.ts
··· 110 110 .replace(/~(.*?)~/g, "~~$1~~") // Strikethrough 111 111 .replace(/<(https?:\/\/[^|]+)\|([^>]+)>/g, "[$2]($1)"); // Links 112 112 113 - const mediaUrls = payload.files?.length 114 - ? await deployToHackClubCDN( 113 + const mediaUrls = []; 114 + // Check if the message is from a private channel 115 + if ( 116 + payload.channel_type === "im" || 117 + payload.channel_type === "mpim" 118 + ) { 119 + // Process all files in one batch for private channels 120 + if (payload.files && payload.files.length > 0) { 121 + const cdnUrls = await deployToHackClubCDN( 115 122 payload.files.map((file) => file.url_private), 116 - ).then((res) => res.files) 117 - : []; 123 + ); 124 + mediaUrls.push(...cdnUrls.files); 125 + } 126 + } else if (payload.files && payload.files.length > 0) { 127 + // For public channels, process media files in parallel 128 + const mediaFiles = payload.files.filter( 129 + (file) => 130 + file.mimetype && 131 + (file.mimetype.startsWith("image/") || 132 + file.mimetype.startsWith("video/")), 133 + ); 134 + 135 + if (mediaFiles.length > 0) { 136 + const results = await Promise.all( 137 + mediaFiles.map(async (file) => { 138 + try { 139 + const fileres = 140 + await slackClient.files.sharedPublicURL({ 141 + file: file.id as string, 142 + token: process.env.SLACK_USER_TOKEN, 143 + }); 144 + 145 + const fetchRes = await fetch( 146 + fileres.file?.permalink_public as string, 147 + ); 148 + const html = await fetchRes.text(); 149 + const match = html.match( 150 + /https:\/\/files.slack.com\/files-pri\/[^"]+pub_secret=([^"&]*)/, 151 + ); 152 + 153 + return match?.[0] || null; 154 + } catch (error) { 155 + console.error( 156 + "Error processing file:", 157 + file.id, 158 + error, 159 + ); 160 + return null; 161 + } 162 + }), 163 + ); 164 + 165 + // Filter out null results and add to mediaUrls 166 + mediaUrls.push(...results.filter(Boolean)); 167 + } 168 + } 118 169 119 170 // fetch time spent on project via hackatime 120 171 const timeSpent = await fetchHackatimeSummary(