From 8bf8d0bcacca7da91c9e86e540f5ffee6fc88e88 Mon Sep 17 00:00:00 2001 From: Patrick Fic Date: Mon, 12 Jan 2026 14:26:30 -0800 Subject: [PATCH] Basic remote scrub. --- serverless/src/handlers/emsupload.js | 7 ++++--- serverless/src/handlers/scrub.js | 7 ++++--- src/main/decoder/decoder.ts | 18 ++++++++++-------- src/main/decoder/emsbackup.ts | 19 +++++++------------ 4 files changed, 25 insertions(+), 26 deletions(-) diff --git a/serverless/src/handlers/emsupload.js b/serverless/src/handlers/emsupload.js index fbf3858..4910fd8 100644 --- a/serverless/src/handlers/emsupload.js +++ b/serverless/src/handlers/emsupload.js @@ -1,6 +1,6 @@ const { S3Client, PutObjectCommand } = require('@aws-sdk/client-s3'); const { getSignedUrl } = require('@aws-sdk/s3-request-presigner'); -const { randomUUID } = require('crypto'); + const s3Client = new S3Client({ region: process.env.AWS_REGION || 'ca-central-1' }); const BUCKET_NAME = process.env.UPLOAD_BUCKET_NAME; @@ -49,7 +49,7 @@ exports.handler = async (event) => { // Generate a unique key for the upload - const key = `esdpuploads/${esApiKey}/${ciecaid}-${clm_no}-${ownr_ln}-${new Date().toISOString().replace(/T/, '--').replace(/\..+/, '').replace(/:/g, '-')}.zip`; + const key = `${esApiKey}/${ciecaid}-${clm_no}-${ownr_ln}-${new Date().toISOString().replace(/T/, '--').replace(/\..+/, '').replace(/:/g, '-')}.zip`; // Create the presigned URL for upload (valid for 15 minutes) const command = new PutObjectCommand({ @@ -61,7 +61,8 @@ exports.handler = async (event) => { const presignedUrl = await getSignedUrl(s3Client, command, { expiresIn: 900 // 15 minutes }); - + console.log('Generated presigned URL for key:', key); + console.log('Presigned URL:', presignedUrl); // Return success response with presigned URL and key return { statusCode: 200, diff --git a/serverless/src/handlers/scrub.js b/serverless/src/handlers/scrub.js index 78c3baf..84b7c03 100644 --- a/serverless/src/handlers/scrub.js +++ b/serverless/src/handlers/scrub.js @@ -15,8 +15,6 @@ exports.handler = async (event) => { estimate.v_type = getVehicleType(estimate.v_model).type; estimate.sendingEntityId = "87330f61-412b-4251-baaa-d026565b23c5"; - console.log("Updated type", estimate.v_type); - const fileName = `${esApiKey}-${estimate.clm_no}-${Date.now()}`; const formData = new FormData(); const jsonString = JSON.stringify(estimate); @@ -46,7 +44,10 @@ exports.handler = async (event) => { const reportIssueUrl = `https://insurtechtoolkit.com/pcontactUs.aspx?apiKey=${esApiKey}&file=${fileName}.json`; return { - resultPDFUrl, reportIssueUrl + statusCode: 200, + body: JSON.stringify({ + resultPDFUrl, reportIssueUrl, identified_item: result.data?.identified_item + }), } } catch (error) { diff --git a/src/main/decoder/decoder.ts b/src/main/decoder/decoder.ts index 6c0c19d..73b11ab 100644 --- a/src/main/decoder/decoder.ts +++ b/src/main/decoder/decoder.ts @@ -158,14 +158,16 @@ async function ImportJob(filepath: string): Promise { //Scrub the estimate const scrubResults = await ScrubEstimate({ job: jobObject }); - console.log("Scrub Results:", scrubResults); - // UploadEmsToS3({ - // extensionlessFilePath, - // bodyshopid: newAvailableJob.bodyshopid, - // ciecaid: jobObject.ciecaid ?? "", - // clm_no: jobObject.clm_no ?? "", - // ownr_ln: jobObject.ownr_ln ?? "", - // }); + + const esApiKey = store.get("settings.esApiKey") as string; + UploadEmsToS3({ + extensionlessFilePath, + esApiKey: esApiKey, + ciecaid: jobObject.ciecaid ?? "", + clm_no: jobObject.clm_no ?? "", + ownr_ln: jobObject.ownr_ln ?? "", + }); + console.log("Got past the job upload."); } catch (error) { log.error("Error encountered while decoding job. ", errorTypeCheck(error)); const uploadNotificationFailure = new Notification({ diff --git a/src/main/decoder/emsbackup.ts b/src/main/decoder/emsbackup.ts index 69e8fdb..533b34f 100644 --- a/src/main/decoder/emsbackup.ts +++ b/src/main/decoder/emsbackup.ts @@ -1,7 +1,7 @@ import axios from "axios"; import archiver from "archiver"; import errorTypeCheck from "../../util/errorTypeCheck"; -import { UUID } from "crypto"; + import fs from "fs"; import path from "path"; import stream from "stream"; @@ -10,13 +10,13 @@ import store from "../store/store"; async function UploadEmsToS3({ extensionlessFilePath, - bodyshopid, + esApiKey, clm_no, ciecaid, ownr_ln, }: { extensionlessFilePath: string; - bodyshopid: UUID; + esApiKey: string; clm_no: string; ciecaid: string; ownr_ln: string; @@ -63,21 +63,15 @@ async function UploadEmsToS3({ // Get the presigned URL from the server const presignedUrlResponse = await axios.post( - `${ - store.get("app.isTest") - ? import.meta.env.VITE_API_TEST_URL - : import.meta.env.VITE_API_URL - }/emsupload`, + "https://dev.es.imex.online/emsupload", { - bodyshopid, + esApiKey, ciecaid, clm_no, ownr_ln, }, { - headers: { - Authorization: `Bearer ${await getTokenFromRenderer()}`, - }, + headers: {}, }, ); @@ -95,6 +89,7 @@ async function UploadEmsToS3({ }); } catch (error) { console.error("Error uploading EMS to S3:", errorTypeCheck(error)); + //TODO: Add some sort of remote logging here. return false; }