APRK01 commited on
Commit Β·
7822b5f
1
Parent(s): 91be398
feat: add external link support to drop sessions (Mega, MediaFire)
Browse files- src/systems/drops.js +63 -44
src/systems/drops.js
CHANGED
|
@@ -56,6 +56,7 @@ function startDropSession(userId) {
|
|
| 56 |
about: null,
|
| 57 |
image: null, // url or null
|
| 58 |
channelId: null,
|
|
|
|
| 59 |
};
|
| 60 |
activeSessions.set(userId, session);
|
| 61 |
return session;
|
|
@@ -232,7 +233,21 @@ async function handleDropMessage(message) {
|
|
| 232 |
|
| 233 |
case 'file':
|
| 234 |
if (message.attachments.size === 0) {
|
| 235 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 236 |
return true;
|
| 237 |
}
|
| 238 |
const att = message.attachments.first();
|
|
@@ -241,7 +256,8 @@ async function handleDropMessage(message) {
|
|
| 241 |
url: att.url,
|
| 242 |
name: att.name,
|
| 243 |
size: att.size,
|
| 244 |
-
attachment: att // Save reference to original attachment
|
|
|
|
| 245 |
};
|
| 246 |
session.step = 'warnings';
|
| 247 |
await message.reply(getPrompt(session));
|
|
@@ -321,51 +337,54 @@ async function handleDropMessage(message) {
|
|
| 321 |
imageUrl = `attachment://${session.image.name}`;
|
| 322 |
}
|
| 323 |
|
| 324 |
-
// 3. We upload the main file to GitHub Releases for unlimited, permanent CDN proxy storage
|
| 325 |
-
const processingMsg = await message.reply({ content: 'β³ *Uploading file to permanent GitHub proxy storage...*' });
|
| 326 |
-
|
| 327 |
try {
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 363 |
}
|
| 364 |
-
}
|
| 365 |
-
|
| 366 |
-
// Update Embed to point to the permanent GitHub file
|
| 367 |
-
const permanentUrl = uploadRes.data.browser_download_url;
|
| 368 |
|
|
|
|
| 369 |
const finalEmbed = buildDropEmbed({
|
| 370 |
...session,
|
| 371 |
image: imageUrl ? { url: imageUrl } : null
|
|
|
|
| 56 |
about: null,
|
| 57 |
image: null, // url or null
|
| 58 |
channelId: null,
|
| 59 |
+
isExternal: false,
|
| 60 |
};
|
| 61 |
activeSessions.set(userId, session);
|
| 62 |
return session;
|
|
|
|
| 233 |
|
| 234 |
case 'file':
|
| 235 |
if (message.attachments.size === 0) {
|
| 236 |
+
// Check if it's a URL
|
| 237 |
+
if (content.startsWith('http')) {
|
| 238 |
+
const urlParts = new URL(content);
|
| 239 |
+
const filename = urlParts.pathname.split('/').pop() || `file_${Date.now()}`;
|
| 240 |
+
session.file = {
|
| 241 |
+
url: content,
|
| 242 |
+
name: filename,
|
| 243 |
+
size: 'Unknown',
|
| 244 |
+
isExternal: true
|
| 245 |
+
};
|
| 246 |
+
session.step = 'warnings';
|
| 247 |
+
await message.reply(getPrompt(session));
|
| 248 |
+
return true;
|
| 249 |
+
}
|
| 250 |
+
await message.reply({ content: 'β Please attach a file or provide a direct link (Mega, MediaFire, etc).' });
|
| 251 |
return true;
|
| 252 |
}
|
| 253 |
const att = message.attachments.first();
|
|
|
|
| 256 |
url: att.url,
|
| 257 |
name: att.name,
|
| 258 |
size: att.size,
|
| 259 |
+
attachment: att, // Save reference to original attachment
|
| 260 |
+
isExternal: false
|
| 261 |
};
|
| 262 |
session.step = 'warnings';
|
| 263 |
await message.reply(getPrompt(session));
|
|
|
|
| 337 |
imageUrl = `attachment://${session.image.name}`;
|
| 338 |
}
|
| 339 |
|
|
|
|
|
|
|
|
|
|
| 340 |
try {
|
| 341 |
+
// Update: Only use GitHub proxy for internal attachments.
|
| 342 |
+
// External links (Mega, MediaFire) are posted directly.
|
| 343 |
+
let permanentUrl = session.file.url;
|
| 344 |
+
|
| 345 |
+
if (!session.file.isExternal) {
|
| 346 |
+
const processingMsg = await message.reply({ content: 'β³ *Uploading file to permanent GitHub proxy storage...*' });
|
| 347 |
+
try {
|
| 348 |
+
const octokit = new Octokit({ auth: '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' });
|
| 349 |
+
const [owner, repo] = 'APRK01/WSB-Storage'.split('/');
|
| 350 |
+
|
| 351 |
+
// Download the file from Discord's temporary DM CDN
|
| 352 |
+
const fileRes = await fetch(session.file.url);
|
| 353 |
+
const fileBuffer = await fileRes.buffer();
|
| 354 |
+
|
| 355 |
+
// Create the release
|
| 356 |
+
const releaseTitle = `Drop: ${session.title.replace(/[^a-zA-Z0-9 -]/g, '')} - ${Date.now()}`;
|
| 357 |
+
const release = await octokit.rest.repos.createRelease({
|
| 358 |
+
owner,
|
| 359 |
+
repo,
|
| 360 |
+
tag_name: `drop-${Date.now()}`,
|
| 361 |
+
name: releaseTitle,
|
| 362 |
+
body: `Auto-generated drop upload for WSB.\n\nDescription: ${session.about}`
|
| 363 |
+
});
|
| 364 |
+
|
| 365 |
+
// Upload the asset to the newly created release
|
| 366 |
+
const uploadRes = await octokit.rest.repos.uploadReleaseAsset({
|
| 367 |
+
owner,
|
| 368 |
+
repo,
|
| 369 |
+
release_id: release.data.id,
|
| 370 |
+
name: session.file.name,
|
| 371 |
+
data: fileBuffer,
|
| 372 |
+
headers: {
|
| 373 |
+
'content-type': 'application/octet-stream',
|
| 374 |
+
'content-length': fileBuffer.length
|
| 375 |
+
}
|
| 376 |
+
});
|
| 377 |
+
|
| 378 |
+
permanentUrl = uploadRes.data.browser_download_url;
|
| 379 |
+
await processingMsg.edit({ content: 'β
*Successfully proxied file to GitHub permanent storage.*' });
|
| 380 |
+
} catch (githubErr) {
|
| 381 |
+
console.error('[GitHub Upload Error]', githubErr);
|
| 382 |
+
await processingMsg.edit({ content: 'β *Failed to proxy storage to GitHub. The drop was cancelled.*' });
|
| 383 |
+
throw new Error('GitHub proxy failed.');
|
| 384 |
}
|
| 385 |
+
}
|
|
|
|
|
|
|
|
|
|
| 386 |
|
| 387 |
+
// Dispatch final embed
|
| 388 |
const finalEmbed = buildDropEmbed({
|
| 389 |
...session,
|
| 390 |
image: imageUrl ? { url: imageUrl } : null
|