Basic remote scrub.
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
const { S3Client, PutObjectCommand } = require('@aws-sdk/client-s3');
|
const { S3Client, PutObjectCommand } = require('@aws-sdk/client-s3');
|
||||||
const { getSignedUrl } = require('@aws-sdk/s3-request-presigner');
|
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 s3Client = new S3Client({ region: process.env.AWS_REGION || 'ca-central-1' });
|
||||||
const BUCKET_NAME = process.env.UPLOAD_BUCKET_NAME;
|
const BUCKET_NAME = process.env.UPLOAD_BUCKET_NAME;
|
||||||
@@ -49,7 +49,7 @@ exports.handler = async (event) => {
|
|||||||
|
|
||||||
// Generate a unique key for the upload
|
// 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)
|
// Create the presigned URL for upload (valid for 15 minutes)
|
||||||
const command = new PutObjectCommand({
|
const command = new PutObjectCommand({
|
||||||
@@ -61,7 +61,8 @@ exports.handler = async (event) => {
|
|||||||
const presignedUrl = await getSignedUrl(s3Client, command, {
|
const presignedUrl = await getSignedUrl(s3Client, command, {
|
||||||
expiresIn: 900 // 15 minutes
|
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 success response with presigned URL and key
|
||||||
return {
|
return {
|
||||||
statusCode: 200,
|
statusCode: 200,
|
||||||
|
|||||||
@@ -15,8 +15,6 @@ exports.handler = async (event) => {
|
|||||||
estimate.v_type = getVehicleType(estimate.v_model).type;
|
estimate.v_type = getVehicleType(estimate.v_model).type;
|
||||||
estimate.sendingEntityId = "87330f61-412b-4251-baaa-d026565b23c5";
|
estimate.sendingEntityId = "87330f61-412b-4251-baaa-d026565b23c5";
|
||||||
|
|
||||||
console.log("Updated type", estimate.v_type);
|
|
||||||
|
|
||||||
const fileName = `${esApiKey}-${estimate.clm_no}-${Date.now()}`;
|
const fileName = `${esApiKey}-${estimate.clm_no}-${Date.now()}`;
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
const jsonString = JSON.stringify(estimate);
|
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`;
|
const reportIssueUrl = `https://insurtechtoolkit.com/pcontactUs.aspx?apiKey=${esApiKey}&file=${fileName}.json`;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
resultPDFUrl, reportIssueUrl
|
statusCode: 200,
|
||||||
|
body: JSON.stringify({
|
||||||
|
resultPDFUrl, reportIssueUrl, identified_item: result.data?.identified_item
|
||||||
|
}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
|
|||||||
@@ -158,14 +158,16 @@ async function ImportJob(filepath: string): Promise<void> {
|
|||||||
|
|
||||||
//Scrub the estimate
|
//Scrub the estimate
|
||||||
const scrubResults = await ScrubEstimate({ job: jobObject });
|
const scrubResults = await ScrubEstimate({ job: jobObject });
|
||||||
console.log("Scrub Results:", scrubResults);
|
|
||||||
// UploadEmsToS3({
|
const esApiKey = store.get("settings.esApiKey") as string;
|
||||||
// extensionlessFilePath,
|
UploadEmsToS3({
|
||||||
// bodyshopid: newAvailableJob.bodyshopid,
|
extensionlessFilePath,
|
||||||
// ciecaid: jobObject.ciecaid ?? "",
|
esApiKey: esApiKey,
|
||||||
// clm_no: jobObject.clm_no ?? "",
|
ciecaid: jobObject.ciecaid ?? "",
|
||||||
// ownr_ln: jobObject.ownr_ln ?? "",
|
clm_no: jobObject.clm_no ?? "",
|
||||||
// });
|
ownr_ln: jobObject.ownr_ln ?? "",
|
||||||
|
});
|
||||||
|
console.log("Got past the job upload.");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
log.error("Error encountered while decoding job. ", errorTypeCheck(error));
|
log.error("Error encountered while decoding job. ", errorTypeCheck(error));
|
||||||
const uploadNotificationFailure = new Notification({
|
const uploadNotificationFailure = new Notification({
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import archiver from "archiver";
|
import archiver from "archiver";
|
||||||
import errorTypeCheck from "../../util/errorTypeCheck";
|
import errorTypeCheck from "../../util/errorTypeCheck";
|
||||||
import { UUID } from "crypto";
|
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import stream from "stream";
|
import stream from "stream";
|
||||||
@@ -10,13 +10,13 @@ import store from "../store/store";
|
|||||||
|
|
||||||
async function UploadEmsToS3({
|
async function UploadEmsToS3({
|
||||||
extensionlessFilePath,
|
extensionlessFilePath,
|
||||||
bodyshopid,
|
esApiKey,
|
||||||
clm_no,
|
clm_no,
|
||||||
ciecaid,
|
ciecaid,
|
||||||
ownr_ln,
|
ownr_ln,
|
||||||
}: {
|
}: {
|
||||||
extensionlessFilePath: string;
|
extensionlessFilePath: string;
|
||||||
bodyshopid: UUID;
|
esApiKey: string;
|
||||||
clm_no: string;
|
clm_no: string;
|
||||||
ciecaid: string;
|
ciecaid: string;
|
||||||
ownr_ln: string;
|
ownr_ln: string;
|
||||||
@@ -63,21 +63,15 @@ async function UploadEmsToS3({
|
|||||||
|
|
||||||
// Get the presigned URL from the server
|
// Get the presigned URL from the server
|
||||||
const presignedUrlResponse = await axios.post(
|
const presignedUrlResponse = await axios.post(
|
||||||
`${
|
"https://dev.es.imex.online/emsupload",
|
||||||
store.get("app.isTest")
|
|
||||||
? import.meta.env.VITE_API_TEST_URL
|
|
||||||
: import.meta.env.VITE_API_URL
|
|
||||||
}/emsupload`,
|
|
||||||
{
|
{
|
||||||
bodyshopid,
|
esApiKey,
|
||||||
ciecaid,
|
ciecaid,
|
||||||
clm_no,
|
clm_no,
|
||||||
ownr_ln,
|
ownr_ln,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {},
|
||||||
Authorization: `Bearer ${await getTokenFromRenderer()}`,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -95,6 +89,7 @@ async function UploadEmsToS3({
|
|||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error uploading EMS to S3:", errorTypeCheck(error));
|
console.error("Error uploading EMS to S3:", errorTypeCheck(error));
|
||||||
|
//TODO: Add some sort of remote logging here.
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user