APRK01 commited on
Commit
7822b5f
Β·
1 Parent(s): 91be398

feat: add external link support to drop sessions (Mega, MediaFire)

Browse files
Files changed (1) hide show
  1. 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
- await message.reply({ content: '❌ Please attach a file.' });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
- const octokit = new Octokit({ auth: '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' });
329
- const [owner, repo] = 'APRK01/WSB-Storage'.split('/');
330
-
331
- // Download the file from Discord's temporary DM CDN
332
- let fileBuffer;
333
- if (session.file.isExternal) {
334
- // User provided an external link instead of uploading to Discord DM
335
- const fileRes = await fetch(session.file.url);
336
- fileBuffer = await fileRes.buffer();
337
- } else {
338
- // User uploaded directly to Discord DM
339
- const fileRes = await fetch(session.file.url);
340
- fileBuffer = await fileRes.buffer();
341
- }
342
-
343
- // Create the release
344
- const releaseTitle = `Drop: ${session.title.replace(/[^a-zA-Z0-9 -]/g, '')} - ${Date.now()}`;
345
- const release = await octokit.rest.repos.createRelease({
346
- owner,
347
- repo,
348
- tag_name: `drop-${Date.now()}`,
349
- name: releaseTitle,
350
- body: `Auto-generated drop upload for WSB.\n\nDescription: ${session.about}`
351
- });
352
-
353
- // Upload the asset to the newly created release
354
- const uploadRes = await octokit.rest.repos.uploadReleaseAsset({
355
- owner,
356
- repo,
357
- release_id: release.data.id,
358
- name: session.file.name,
359
- data: fileBuffer,
360
- headers: {
361
- 'content-type': 'application/octet-stream',
362
- 'content-length': fileBuffer.length
 
 
 
 
 
 
 
 
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