mime change
This commit is contained in:
parent
71cb01d540
commit
75cb80df22
@ -4,11 +4,16 @@ import { parseEmail } from '@/lib/server/email-parser';
|
|||||||
export async function POST(request: Request) {
|
export async function POST(request: Request) {
|
||||||
try {
|
try {
|
||||||
const body = await request.json();
|
const body = await request.json();
|
||||||
|
console.log('Received request body:', body);
|
||||||
|
|
||||||
const { emailContent } = body;
|
const { emailContent } = body;
|
||||||
|
console.log('Email content type:', typeof emailContent);
|
||||||
|
console.log('Email content length:', emailContent?.length);
|
||||||
|
|
||||||
if (!emailContent || typeof emailContent !== 'string') {
|
if (!emailContent || typeof emailContent !== 'string') {
|
||||||
|
console.log('Invalid email content:', { emailContent, type: typeof emailContent });
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{ error: 'Invalid email content. Expected a string.' },
|
{ error: 'Invalid email content. Expected a string.', received: { type: typeof emailContent, length: emailContent?.length } },
|
||||||
{ status: 400 }
|
{ status: 400 }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -114,7 +114,11 @@ async function renderEmailContent(email: Email) {
|
|||||||
try {
|
try {
|
||||||
if (!email.body) return null;
|
if (!email.body) return null;
|
||||||
|
|
||||||
const parsedEmail = await decodeEmail(email.body);
|
// Ensure the email content is properly formatted
|
||||||
|
const formattedEmail = email.body.trim();
|
||||||
|
if (!formattedEmail) return null;
|
||||||
|
|
||||||
|
const parsedEmail = await decodeEmail(formattedEmail);
|
||||||
|
|
||||||
if (parsedEmail.html) {
|
if (parsedEmail.html) {
|
||||||
return (
|
return (
|
||||||
|
|||||||
@ -21,16 +21,23 @@ export interface ParsedEmail {
|
|||||||
|
|
||||||
export async function decodeEmail(emailContent: string): Promise<ParsedEmail> {
|
export async function decodeEmail(emailContent: string): Promise<ParsedEmail> {
|
||||||
try {
|
try {
|
||||||
|
// Ensure the email content is properly formatted
|
||||||
|
const formattedContent = emailContent.trim();
|
||||||
|
if (!formattedContent) {
|
||||||
|
throw new Error('Email content is empty');
|
||||||
|
}
|
||||||
|
|
||||||
const response = await fetch('/api/parse-email', {
|
const response = await fetch('/api/parse-email', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
},
|
},
|
||||||
body: JSON.stringify({ emailContent }),
|
body: JSON.stringify({ emailContent: formattedContent }),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error('Failed to parse email');
|
const errorData = await response.json();
|
||||||
|
throw new Error(errorData.error || 'Failed to parse email');
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user