Basic remote scrub.
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -158,14 +158,16 @@ async function ImportJob(filepath: string): Promise<void> {
|
||||
|
||||
//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({
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user