alpha
Login
or
Join now
dunkirk.sh
/
smokie
Star
0
Fork
0
Atom
Configure Feed
Issues
Pull Requests
Commits
Tags
Feed URL
Select the types of activity you want to include in your feed.
This repository has no description
Star
0
Fork
0
Atom
Configure Feed
Issues
Pull Requests
Commits
Tags
Feed URL
Select the types of activity you want to include in your feed.
Overview
Issues
Pulls
Pipelines
feat: speed up file deployment
author
Kieran Klukas
date
1 year ago
(Apr 30, 2025, 11:25 PM -0400)
commit
7abc1085
7abc1085ef56233cfc8888cd2aecfa028fb45df1
parent
a91c3962
a91c396294b005c993a4ce4422b481c3f61ce1d4
+55
-4
1 changed file
Expand all
Collapse all
Unified
Split
src
features
takes
handlers
upload.ts
+55
-4
src/features/takes/handlers/upload.ts
Reviewed
···
110
110
.replace(/~(.*?)~/g, "~~$1~~") // Strikethrough
111
111
.replace(/<(https?:\/\/[^|]+)\|([^>]+)>/g, "[$2]($1)"); // Links
112
112
113
113
-
const mediaUrls = payload.files?.length
114
114
-
? await deployToHackClubCDN(
113
113
+
const mediaUrls = [];
114
114
+
// Check if the message is from a private channel
115
115
+
if (
116
116
+
payload.channel_type === "im" ||
117
117
+
payload.channel_type === "mpim"
118
118
+
) {
119
119
+
// Process all files in one batch for private channels
120
120
+
if (payload.files && payload.files.length > 0) {
121
121
+
const cdnUrls = await deployToHackClubCDN(
115
122
payload.files.map((file) => file.url_private),
116
116
-
).then((res) => res.files)
117
117
-
: [];
123
123
+
);
124
124
+
mediaUrls.push(...cdnUrls.files);
125
125
+
}
126
126
+
} else if (payload.files && payload.files.length > 0) {
127
127
+
// For public channels, process media files in parallel
128
128
+
const mediaFiles = payload.files.filter(
129
129
+
(file) =>
130
130
+
file.mimetype &&
131
131
+
(file.mimetype.startsWith("image/") ||
132
132
+
file.mimetype.startsWith("video/")),
133
133
+
);
134
134
+
135
135
+
if (mediaFiles.length > 0) {
136
136
+
const results = await Promise.all(
137
137
+
mediaFiles.map(async (file) => {
138
138
+
try {
139
139
+
const fileres =
140
140
+
await slackClient.files.sharedPublicURL({
141
141
+
file: file.id as string,
142
142
+
token: process.env.SLACK_USER_TOKEN,
143
143
+
});
144
144
+
145
145
+
const fetchRes = await fetch(
146
146
+
fileres.file?.permalink_public as string,
147
147
+
);
148
148
+
const html = await fetchRes.text();
149
149
+
const match = html.match(
150
150
+
/https:\/\/files.slack.com\/files-pri\/[^"]+pub_secret=([^"&]*)/,
151
151
+
);
152
152
+
153
153
+
return match?.[0] || null;
154
154
+
} catch (error) {
155
155
+
console.error(
156
156
+
"Error processing file:",
157
157
+
file.id,
158
158
+
error,
159
159
+
);
160
160
+
return null;
161
161
+
}
162
162
+
}),
163
163
+
);
164
164
+
165
165
+
// Filter out null results and add to mediaUrls
166
166
+
mediaUrls.push(...results.filter(Boolean));
167
167
+
}
168
168
+
}
118
169
119
170
// fetch time spent on project via hackatime
120
171
const timeSpent = await fetchHackatimeSummary(