Skip to content

Commit

Permalink
Stub out updating S3 submissions with httpCode
Browse files Browse the repository at this point in the history
  • Loading branch information
WillNilges committed Oct 13, 2024
1 parent 96e8911 commit e46e7e0
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions app/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export async function recordJoinFormSubmissionToCSV(
}

// Records the submission we just got as a JSON object in an S3 bucket.
export async function recordJoinFormSubmissionToS3(submission: JoinFormValues) {
export async function recordJoinFormSubmissionToS3(submission: JoinFormValues, key: string = "", responseCode: string = "") {
if (S3_ACCESS_KEY === undefined || S3_SECRET_KEY === undefined) {
console.error(
"S3 credentials not configured. I WILL NOT SAVE THIS SUBMISSION.",
Expand All @@ -58,10 +58,14 @@ export async function recordJoinFormSubmissionToS3(submission: JoinFormValues) {
.replace(/[-:T]/g, "/")
.slice(0, 19);

key = key != "" ? key : `${S3_BASE_NAME}/${submissionKey}.json`;

let body = responseCode != "" ? JSON.stringify(Object.assign(submission, {responseCode: responseCode})) : JSON.stringify(submission);

const command = new PutObjectCommand({
Bucket: S3_BUCKET_NAME,
Key: `${S3_BASE_NAME}/${submissionKey}.json`,
Body: JSON.stringify(submission),
Key: key,
Body: body,
});

try {
Expand All @@ -73,4 +77,7 @@ export async function recordJoinFormSubmissionToS3(submission: JoinFormValues) {
recordJoinFormSubmissionToCSV(submission);
throw err;
}

// Return the key later so we can update it.
return key;
}

0 comments on commit e46e7e0

Please sign in to comment.