This commit is contained in:
2025-06-11 13:53:10 +02:00
8 changed files with 131 additions and 400 deletions

View File

@@ -13,6 +13,7 @@ interface EmailMessage {
timestamp: string;
direction: 'sent' | 'received';
threadId?: string;
attachments?: any[];
}
export default defineEventHandler(async (event) => {
@@ -304,6 +305,15 @@ async function fetchImapEmails(
return;
}
// Extract attachments
const attachments = parsed.attachments ? parsed.attachments.map((att: any) => ({
filename: att.filename || 'attachment',
name: att.filename || 'attachment',
size: att.size || 0,
type: att.contentType || 'application/octet-stream',
cid: att.cid || undefined
})) : [];
const email: EmailMessage = {
id: parsed.messageId || `${Date.now()}-${seqno}`,
from: fromEmail,
@@ -312,7 +322,8 @@ async function fetchImapEmails(
body: parsed.text || '',
html: parsed.html || undefined,
timestamp: parsed.date?.toISOString() || new Date().toISOString(),
direction: fromEmail.toLowerCase().includes(userEmail.toLowerCase()) ? 'sent' : 'received'
direction: fromEmail.toLowerCase().includes(userEmail.toLowerCase()) ? 'sent' : 'received',
attachments: attachments
};
if (parsed.headers.has('in-reply-to')) {

View File

@@ -29,6 +29,9 @@ export default defineEventHandler(async (event) => {
throw createError({ statusCode: 401, statusMessage: "unauthenticated" });
}
// Set longer timeout for this endpoint to prevent 502 errors
event.node.res.setTimeout(60000); // 60 seconds
try {
const body = await readBody(event);
const { interestId } = body;

View File

@@ -181,7 +181,8 @@ export default defineEventHandler(async (event) => {
html: htmlBody,
timestamp: new Date().toISOString(),
direction: 'sent',
interestId: interestId
interestId: interestId,
attachments: attachments // Include attachment info
};
const objectName = `interest-${interestId}/${Date.now()}-sent.json`;

View File

@@ -196,6 +196,7 @@ export const createInterest = async (data: Partial<Interest>) => {
"Date Added",
"Width",
"Depth",
"Created At",
"Source",
"Contact Method Preferred",
"Lead Category",
@@ -213,6 +214,11 @@ export const createInterest = async (data: Partial<Interest>) => {
}
}
// Set Created At to current timestamp if not provided
if (!cleanData["Created At"]) {
cleanData["Created At"] = new Date().toISOString();
}
// Remove any computed or relation fields that shouldn't be sent
delete cleanData.Id;
delete cleanData.Berths;