fix: Update Discord API integration to use Bot token and channel ID for message handling
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import pool from '@/lib/db';
|
||||
|
||||
if (!process.env.DISCORD_WEBHOOK_URL) {
|
||||
throw new Error('Please define DISCORD_WEBHOOK_URL in .env.local');
|
||||
if (!process.env.DISCORD_BOT_TOKEN || !process.env.DISCORD_CHANNEL_ID) {
|
||||
throw new Error('Please define DISCORD_BOT_TOKEN and DISCORD_CHANNEL_ID in .env.local');
|
||||
}
|
||||
|
||||
const DISCORD_API_URL = `https://discord.com/api/v10/channels/${process.env.DISCORD_CHANNEL_ID}/messages`;
|
||||
|
||||
export async function POST(request: Request) {
|
||||
try {
|
||||
const formData = await request.formData();
|
||||
@@ -16,14 +18,15 @@ export async function POST(request: Request) {
|
||||
return NextResponse.json({ error: 'Missing required form fields' }, { status: 400 });
|
||||
}
|
||||
|
||||
// Forward the chunk to Discord
|
||||
// Forward the chunk to Discord via the Bot API
|
||||
const discordFormData = new FormData();
|
||||
discordFormData.append('file', chunk, `chunk-${partIndex}.bin`);
|
||||
// You can add content to the message if you want
|
||||
// discordFormData.append('content', `File chunk for ${fileId}, part ${partIndex}`);
|
||||
|
||||
const discordRes = await fetch(process.env.DISCORD_WEBHOOK_URL, {
|
||||
const discordRes = await fetch(DISCORD_API_URL, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Authorization': `Bot ${process.env.DISCORD_BOT_TOKEN}`,
|
||||
},
|
||||
body: discordFormData,
|
||||
});
|
||||
|
||||
@@ -41,7 +44,7 @@ export async function POST(request: Request) {
|
||||
}
|
||||
|
||||
const discordMessageId = discordData.id;
|
||||
const discordAttachmentUrl = attachment.url;
|
||||
const discordAttachmentUrl = attachment.url; // This URL is temporary
|
||||
const partSize = attachment.size;
|
||||
|
||||
// Save part metadata to the database
|
||||
|
||||
Reference in New Issue
Block a user