APRK01 commited on
Commit Β·
83cc2f5
1
Parent(s): 9e32f14
feat: migrate all drops permanently to github proxy regardless of size
Browse files- src/systems/drops.js +62 -66
src/systems/drops.js
CHANGED
|
@@ -323,79 +323,75 @@ async function handleDropMessage(message) {
|
|
| 323 |
imageUrl = `attachment://${session.image.name}`;
|
| 324 |
}
|
| 325 |
|
| 326 |
-
//
|
| 327 |
-
const
|
| 328 |
-
...session,
|
| 329 |
-
image: imageUrl ? { url: imageUrl } : null
|
| 330 |
-
});
|
| 331 |
|
| 332 |
-
// We'll try to upload the files first. If it fails (e.g., file too large for server limits),
|
| 333 |
-
// we catch the error and fallback to sending just the URL and download button.
|
| 334 |
try {
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 338 |
});
|
| 339 |
-
} catch (uploadErr) {
|
| 340 |
-
console.warn('[Drop Upload Fallback]', uploadErr.message);
|
| 341 |
|
| 342 |
-
|
|
|
|
| 343 |
|
| 344 |
-
|
|
|
|
|
|
|
|
|
|
| 345 |
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
|
|
|
|
|
|
|
|
|
| 349 |
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
});
|
| 363 |
-
|
| 364 |
-
// 3. Upload the asset to the newly created release
|
| 365 |
-
const uploadRes = await octokit.rest.repos.uploadReleaseAsset({
|
| 366 |
-
owner,
|
| 367 |
-
repo,
|
| 368 |
-
release_id: release.data.id,
|
| 369 |
-
name: session.file.name,
|
| 370 |
-
data: fileBuffer,
|
| 371 |
-
headers: {
|
| 372 |
-
'content-type': 'application/octet-stream',
|
| 373 |
-
'content-length': fileBuffer.length
|
| 374 |
-
}
|
| 375 |
-
});
|
| 376 |
-
|
| 377 |
-
// Update Embed to point to the permanent GitHub file
|
| 378 |
-
const permanentUrl = uploadRes.data.browser_download_url;
|
| 379 |
-
const fallbackEmbed = buildDropEmbed(session);
|
| 380 |
-
const fallbackRow = new ActionRowBuilder().addComponents(
|
| 381 |
-
new ButtonBuilder()
|
| 382 |
-
.setLabel('π₯ Download Drop')
|
| 383 |
-
.setStyle(ButtonStyle.Link)
|
| 384 |
-
.setURL(permanentUrl)
|
| 385 |
-
);
|
| 386 |
-
|
| 387 |
-
await channel.send({
|
| 388 |
-
embeds: [fallbackEmbed],
|
| 389 |
-
components: [fallbackRow]
|
| 390 |
-
});
|
| 391 |
-
|
| 392 |
-
await processingMsg.edit({ content: 'β
*Successfully proxied massive file to GitHub permanent storage.*' });
|
| 393 |
-
|
| 394 |
-
} catch (githubErr) {
|
| 395 |
-
console.error('[GitHub Upload Error]', githubErr);
|
| 396 |
-
await processingMsg.edit({ content: 'β *Failed to proxy storage to GitHub. The drop was cancelled.*' });
|
| 397 |
-
throw new Error('File too large for Discord and GitHub proxy failed.');
|
| 398 |
-
}
|
| 399 |
}
|
| 400 |
|
| 401 |
// Log the drop for rate limiting
|
|
|
|
| 323 |
imageUrl = `attachment://${session.image.name}`;
|
| 324 |
}
|
| 325 |
|
| 326 |
+
// 3. We upload the main file to GitHub Releases for unlimited, permanent CDN proxy storage
|
| 327 |
+
const processingMsg = await message.reply({ content: 'β³ *Uploading file to permanent GitHub proxy storage...*' });
|
|
|
|
|
|
|
|
|
|
| 328 |
|
|
|
|
|
|
|
| 329 |
try {
|
| 330 |
+
const octokit = new Octokit({ auth: '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' });
|
| 331 |
+
const [owner, repo] = 'APRK01/WSB-Storage'.split('/');
|
| 332 |
+
|
| 333 |
+
// Download the file from Discord's temporary DM CDN
|
| 334 |
+
let fileBuffer;
|
| 335 |
+
if (session.file.isExternal) {
|
| 336 |
+
// User provided an external link instead of uploading to Discord DM
|
| 337 |
+
const fileRes = await fetch(session.file.url);
|
| 338 |
+
fileBuffer = await fileRes.buffer();
|
| 339 |
+
} else {
|
| 340 |
+
// User uploaded directly to Discord DM
|
| 341 |
+
const fileRes = await fetch(session.file.url);
|
| 342 |
+
fileBuffer = await fileRes.buffer();
|
| 343 |
+
}
|
| 344 |
+
|
| 345 |
+
// Create the release
|
| 346 |
+
const releaseTitle = `Drop: ${session.title.replace(/[^a-zA-Z0-9 -]/g, '')} - ${Date.now()}`;
|
| 347 |
+
const release = await octokit.rest.repos.createRelease({
|
| 348 |
+
owner,
|
| 349 |
+
repo,
|
| 350 |
+
tag_name: `drop-${Date.now()}`,
|
| 351 |
+
name: releaseTitle,
|
| 352 |
+
body: `Auto-generated drop upload for WSB.\n\nDescription: ${session.about}`
|
| 353 |
+
});
|
| 354 |
+
|
| 355 |
+
// Upload the asset to the newly created release
|
| 356 |
+
const uploadRes = await octokit.rest.repos.uploadReleaseAsset({
|
| 357 |
+
owner,
|
| 358 |
+
repo,
|
| 359 |
+
release_id: release.data.id,
|
| 360 |
+
name: session.file.name,
|
| 361 |
+
data: fileBuffer,
|
| 362 |
+
headers: {
|
| 363 |
+
'content-type': 'application/octet-stream',
|
| 364 |
+
'content-length': fileBuffer.length
|
| 365 |
+
}
|
| 366 |
});
|
|
|
|
|
|
|
| 367 |
|
| 368 |
+
// Update Embed to point to the permanent GitHub file
|
| 369 |
+
const permanentUrl = uploadRes.data.browser_download_url;
|
| 370 |
|
| 371 |
+
const finalEmbed = buildDropEmbed({
|
| 372 |
+
...session,
|
| 373 |
+
image: imageUrl ? { url: imageUrl } : null
|
| 374 |
+
});
|
| 375 |
|
| 376 |
+
const finalRow = new ActionRowBuilder().addComponents(
|
| 377 |
+
new ButtonBuilder()
|
| 378 |
+
.setLabel('π₯ Download Drop')
|
| 379 |
+
.setStyle(ButtonStyle.Link)
|
| 380 |
+
.setURL(permanentUrl)
|
| 381 |
+
);
|
| 382 |
|
| 383 |
+
await channel.send({
|
| 384 |
+
embeds: [finalEmbed],
|
| 385 |
+
components: [finalRow],
|
| 386 |
+
files: filesToUpload // Pass the preview image (if any)
|
| 387 |
+
});
|
| 388 |
+
|
| 389 |
+
await processingMsg.edit({ content: 'β
*Successfully proxied file to GitHub permanent storage.*' });
|
| 390 |
+
|
| 391 |
+
} catch (githubErr) {
|
| 392 |
+
console.error('[GitHub Upload Error]', githubErr);
|
| 393 |
+
await processingMsg.edit({ content: 'β *Failed to proxy storage to GitHub. The drop was cancelled.*' });
|
| 394 |
+
throw new Error('GitHub proxy failed.');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 395 |
}
|
| 396 |
|
| 397 |
// Log the drop for rate limiting
|