···
8
8
type HackatimeVersion,
9
9
} from "../../../libs/hackatime";
10
10
import { prettyPrintTime } from "../../../libs/time";
11
11
+
import { deployToHackClubCDN } from "../../../libs/cdn";
11
12
12
13
export default async function upload() {
13
14
slackApp.anyMessage(async ({ payload, context }) => {
···
102
103
.replace(/~(.*?)~/g, "~~$1~~") // Strikethrough
103
104
.replace(/<(https?:\/\/[^|]+)\|([^>]+)>/g, "[$2]($1)"); // Links
104
105
105
105
-
const mediaUrls = [];
106
106
-
107
107
-
if (payload.files && payload.files.length > 0) {
108
108
-
for (const file of payload.files) {
109
109
-
if (
110
110
-
file.mimetype &&
111
111
-
(file.mimetype.startsWith("image/") ||
112
112
-
file.mimetype.startsWith("video/"))
113
113
-
) {
114
114
-
const fileres = await slackClient.files.sharedPublicURL(
115
115
-
{
116
116
-
file: file.id as string,
117
117
-
token: process.env.SLACK_USER_TOKEN,
118
118
-
},
119
119
-
);
120
120
-
121
121
-
const fetchRes = await fetch(
122
122
-
fileres.file?.permalink_public as string,
123
123
-
);
124
124
-
const html = await fetchRes.text();
125
125
-
const match = html.match(
126
126
-
/https:\/\/files.slack.com\/files-pri\/[^"]+pub_secret=([^"&]*)/,
127
127
-
);
128
128
-
const filePublicUrl = match?.[0];
129
129
-
130
130
-
if (filePublicUrl) {
131
131
-
mediaUrls.push(filePublicUrl);
132
132
-
}
133
133
-
}
134
134
-
}
135
135
-
}
106
106
+
const mediaUrls = payload.files?.length
107
107
+
? await deployToHackClubCDN(
108
108
+
payload.files.map((file) => file.url_private),
109
109
+
).then((res) => res.files)
110
110
+
: [];
136
111
137
112
// fetch time spent on project via hackatime
138
113
const timeSpent = await fetchHackatimeSummary(