W n8n attention vm

This commit is contained in:
alma 2025-05-24 20:38:23 +02:00
parent 6ba5c2dd6d
commit 97f1313a18

View File

@ -254,26 +254,67 @@ export async function POST(request: Request) {
console.log('Mission created successfully:', JSON.stringify(mission, null, 2));
// Move uploaded files to final location
if (logoPath) {
const finalLogoPath = logoPath.replace('temp', mission.id);
await s3Client.send(new CopyObjectCommand({
Bucket: 'missions',
CopySource: `missions/${logoPath}`,
Key: finalLogoPath.replace('missions/', '')
}));
await s3Client.send(new DeleteObjectCommand({
Bucket: 'missions',
Key: logoPath.replace('missions/', '')
}));
// Handle attachments if present
if (body.attachments && body.attachments.length > 0) {
try {
const attachmentPromises = body.attachments.map(async (attachment: any) => {
const base64Data = attachment.data.split(',')[1];
const buffer = Buffer.from(base64Data, 'base64');
const file = new File([buffer], attachment.name || 'attachment', { type: attachment.type || 'application/octet-stream' });
// Upload attachment
const { filePath } = await uploadMissionLogo(userId, 'temp', file);
uploadedFiles.push({ type: 'attachment', path: filePath });
// Create attachment record in database
return prisma.attachment.create({
data: {
missionId: mission.id,
filename: attachment.name || 'attachment',
filePath: filePath,
fileType: attachment.type || 'application/octet-stream',
fileSize: buffer.length,
uploaderId: userId
}
});
});
await Promise.all(attachmentPromises);
console.log('Attachments uploaded successfully');
} catch (attachmentError) {
console.error('Error uploading attachments:', attachmentError);
throw new Error('Failed to upload attachments');
}
}
// Step 3: Trigger n8n workflow only after mission is created and logo is uploaded
// Move uploaded files to final location
try {
const movePromises = uploadedFiles.map(async (file) => {
const finalPath = file.path.replace('temp', mission.id);
await s3Client.send(new CopyObjectCommand({
Bucket: 'missions',
CopySource: `missions/${file.path}`,
Key: finalPath.replace('missions/', '')
}));
await s3Client.send(new DeleteObjectCommand({
Bucket: 'missions',
Key: file.path.replace('missions/', '')
}));
});
await Promise.all(movePromises);
console.log('All files moved to final location successfully');
} catch (moveError) {
console.error('Error moving files to final location:', moveError);
throw new Error('Failed to move files to final location');
}
// Only trigger n8n workflow after all Minio operations are complete
try {
console.log('=== Starting N8N Workflow ===');
const n8nService = new N8nService();
// Prepare data for n8n
// Prepare data for n8n with final file paths
const n8nData = {
...body,
creatorId: userId,