W n8n attention vm
This commit is contained in:
parent
6ba5c2dd6d
commit
97f1313a18
@ -254,26 +254,67 @@ export async function POST(request: Request) {
|
|||||||
|
|
||||||
console.log('Mission created successfully:', JSON.stringify(mission, null, 2));
|
console.log('Mission created successfully:', JSON.stringify(mission, null, 2));
|
||||||
|
|
||||||
// Move uploaded files to final location
|
// Handle attachments if present
|
||||||
if (logoPath) {
|
if (body.attachments && body.attachments.length > 0) {
|
||||||
const finalLogoPath = logoPath.replace('temp', mission.id);
|
try {
|
||||||
await s3Client.send(new CopyObjectCommand({
|
const attachmentPromises = body.attachments.map(async (attachment: any) => {
|
||||||
Bucket: 'missions',
|
const base64Data = attachment.data.split(',')[1];
|
||||||
CopySource: `missions/${logoPath}`,
|
const buffer = Buffer.from(base64Data, 'base64');
|
||||||
Key: finalLogoPath.replace('missions/', '')
|
const file = new File([buffer], attachment.name || 'attachment', { type: attachment.type || 'application/octet-stream' });
|
||||||
}));
|
|
||||||
await s3Client.send(new DeleteObjectCommand({
|
// Upload attachment
|
||||||
Bucket: 'missions',
|
const { filePath } = await uploadMissionLogo(userId, 'temp', file);
|
||||||
Key: logoPath.replace('missions/', '')
|
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 {
|
try {
|
||||||
console.log('=== Starting N8N Workflow ===');
|
console.log('=== Starting N8N Workflow ===');
|
||||||
const n8nService = new N8nService();
|
const n8nService = new N8nService();
|
||||||
|
|
||||||
// Prepare data for n8n
|
// Prepare data for n8n with final file paths
|
||||||
const n8nData = {
|
const n8nData = {
|
||||||
...body,
|
...body,
|
||||||
creatorId: userId,
|
creatorId: userId,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user