From bed42d9eb74c9767d57b3927618c90d47b7575c1 Mon Sep 17 00:00:00 2001 From: Sawyer Date: Sun, 29 Sep 2024 15:41:15 -0700 Subject: [PATCH] Fix email parsing --- aws/email-importer/src/index.ts | 4 +++- aws/email-importer/src/services/parsing.ts | 7 ++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/aws/email-importer/src/index.ts b/aws/email-importer/src/index.ts index cf1fb3a2..dd8ab15c 100644 --- a/aws/email-importer/src/index.ts +++ b/aws/email-importer/src/index.ts @@ -37,7 +37,9 @@ export async function handler(event: ImporterEvent) { Key: s3Record.s3.object.key, }); - const { highlights, volume } = await getHighlightsAndVolumeFromEmail(Body); + const email = (await Body?.transformToString("utf-8")) ?? ""; + + const { highlights, volume } = await getHighlightsAndVolumeFromEmail(email); if (!volume) { console.error("Volume is missing in the email"); diff --git a/aws/email-importer/src/services/parsing.ts b/aws/email-importer/src/services/parsing.ts index c003153a..460ce9c0 100644 --- a/aws/email-importer/src/services/parsing.ts +++ b/aws/email-importer/src/services/parsing.ts @@ -1,4 +1,3 @@ -import { GetObjectCommandOutput } from "@aws-sdk/client-s3"; import textToJSON from "highlights-email-to-json"; import kindleClippingsToJSON from "kindle-clippings-to-json"; import kindleEmailToJSON from "kindle-email-to-json"; @@ -18,7 +17,7 @@ export interface ParsedVolume { title: string; } -export type ParserFn = (mail: GetObjectCommandOutput["Body"]) => Promise<{ +export type ParserFn = (mail: string) => Promise<{ highlights: ParsedHighlight[]; volume?: ParsedVolume; }>; @@ -33,9 +32,7 @@ const parsers: ParserFn[] = [ /** * Run all parsers on the email body until one finds highlights */ -export async function getHighlightsAndVolumeFromEmail( - email: GetObjectCommandOutput["Body"], -) { +export async function getHighlightsAndVolumeFromEmail(email: string) { let highlights: ParsedHighlight[] = []; let volume: ParsedVolume | undefined;