Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
kdid committed Oct 5, 2023
1 parent 81fa40d commit 93eeca1
Show file tree
Hide file tree
Showing 11 changed files with 303 additions and 27 deletions.
184 changes: 184 additions & 0 deletions lambdas/assets/email.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
<title>NUL Meadow Download</title>
<meta content='IE=edge' http-equiv='X-UA-Compatible' />
<style>
p {
margin-top: 0;
line-height: 1.4em;
}
a {
color: #4e2a84;
}
@media only screen and (max-width: 599px) {
table[class='body-table'] {
width: 100%;
}
img {
max-width: 100%;
height: auto !important;
}
}
@media only screen and (max-width: 510px) {
table[class='inside-table'] {
width: 100%;
padding: 0 10px 0 10px !important;
}
table[class='quote-table'] {
width: 100%;
}
table[class='quote-image-table'] {
width: 100%;
}
}
</style>
</head>

<body
style='
background-color: #f1f0f0;
padding: 0;
margin: 0;
font-family: Arial, Helvetica Neue, Helvetica, sans-serif;
font-size: 17px;
color: #342f2e;
'
>
<!--[if gte mso 15]><table border='0' cellpadding='0' cellspacing='0' width='100%' align='left'><tr><td><![endif]-->
<table
align='center'
border='0'
cellpadding='0'
cellspacing='0'
class='body-table'
style='border: 1px solid #d8d6d6; background-color: #ffffff'
width='600'
>
<!-- header -->
<tbody>
<tr>
<td>
<table
border='0'
cellpadding='0'
cellspacing='0'
style='margin-bottom: 40px'
width='100%'
>
<tbody>
<tr>
<td
align='center'
height='110'
style='background-color: #4e2a84; padding: 0 10px 0 10px'
valign='middle'
>
<h1>
<img src="https://nul-public.s3.amazonaws.com/work-archiver/northwestern_logo.png" alt="Northwestern University Logo" />
</h1>
</td>
</tr>
<tr>
<td
align='center'
height='40'
style='
background-color: #401f68;
font-size: 13px;
color: #ffffff;
font-style: italic;
'
valign='middle'
></td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td>
<table
align='center'
border='0'
cellpadding='0'
cellspacing='0'
class='inside-table'
style='margin-bottom: 40px; padding: 0 66px 0 66px'
width='100%'
>
<tbody>
<tr>
<td style='padding-bottom: 5px'>
<h2
style='
margin: 12px 0;
font-size: 32px;
line-height: 1.2em;
'
>
Hello,
</h2>
<p>
Your request for a zipped archive of the work <a href="{{referer}}work/{{workId}}">{{title}}</a> (accession: {{accession}}) has been
fulfilled. Click below to download your zip file:
</p>
<p style='text-align: center'>
<a href='{{downloadKey}}'>
<!-- icon licensed under Creative Commons (Attribution 3.0 Unported): https://www.iconfinder.com/icons/285629/zip_file_icon -->
<img src="https://nul-public.s3.amazonaws.com/work-archiver/email_zip_icon.png" alt="{{downloadKey}}" />
</a>
</p>
<p style='text-align: center; font-style: italic'>
(Your download will be available for 24 hours)
</p>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<!-- footer -->
<tr>
<td>
<table
align='center'
border='0'
cellpadding='0'
cellspacing='0'
style='background-color: #4e2a84; padding: 20px 0 20px 0'
width='100%'
>
<tbody>
<tr>
<td align='center' style='padding-bottom: 10px'>
<p>
<a href='https://www.library.northwestern.edu'
><img
alt='Northwestern University Library'
src='https://nul-public.s3.amazonaws.com/work-archiver/northwestern-university.png'
/></a>
</p>
</td>
</tr>
<tr>
<td align='center' style='padding-bottom: 20px'>
<p style='font-size: 12px; font-weight: bold; margin: 0'>
<a
href='https://meadow.library.northwestern.edu'
style='color: #ffffff'
>VISIT MEADOW NOW</a
>
</p>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<!--[if gte mso 15]></td></tr></table><![endif]-->
</body>
</html>
4 changes: 4 additions & 0 deletions lambdas/assets/email.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Hello,
A zipped archive of {{title}} with accession: {{accession}} has been created. Your download will be available for 24 hours.

The zip file can be downloaded from {{downloadKey}}
2 changes: 1 addition & 1 deletion lambda/presigned-url.js → lambdas/get-download-link.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports.handler = async (event) => {

console.log("url", url)

return {presignedUrl: url}
return {downloadLink: url}

};

Expand Down
File renamed without changes.
File renamed without changes.
68 changes: 68 additions & 0 deletions lambdas/send-email.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
const { SESClient, SendTemplatedEmailCommand } = require("@aws-sdk/client-ses");

module.exports.handler = async (event) => {
console.log("SEND EMAIL LAMBDA");
console.log(event);

const sesClient = new SESClient();
const templateName = event.template;
const toAddress = event.to || "[email protected]";
const senderAddress = event.sender;
const downloadLink = event.downloadLink;
const today = new Date().toLocaleDateString("en-us", {
weekday: "long",
year: "numeric",
month: "short",
day: "numeric",
});
const params = {
email: toAddress,
downloadKey: downloadLink,
referer: "Meadow",
workId: "foo",
today,
title: "[Untitled]",
accession: "1234",
};

const sendTemplatedEmailCommand = createSendTemplatedEmailCommand(
toAddress,
senderAddress,
templateName,
params
);

try {
const result = await sesClient.send(sendTemplatedEmailCommand);
console.log("sendTemplatedEmailCommand", result)
} catch (err) {
console.log("Failed to send template email", err);
return err;
}
return {success: true}
};

/**
*
* @param { { emailAddress: string, firstName: string } } user
* @param { string } templateName - The name of an existing template in Amazon SES.
* @returns { SendTemplatedEmailCommand }
*/
const createSendTemplatedEmailCommand = (
toAddress,
senderAddress,
templateName,
params
) => {
return new SendTemplatedEmailCommand({
/**
* Here's an example of how a template would be replaced with user data:
* Template: <h1>Hello {{contact.firstName}},</h1><p>Don't forget about the party gifts!</p>
* Destination: <h1>Hello Bilbo,</h1><p>Don't forget about the party gifts!</p>
*/
Destination: { ToAddresses: [toAddress] },
TemplateData: JSON.stringify(params),
Source: `Northwestern University Libraries <${senderAddress}>`,
Template: templateName,
});
};
File renamed without changes.
File renamed without changes.
6 changes: 4 additions & 2 deletions src/handlers/get-file-set-download.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,17 @@ function processDownload(streaming_url, email) {
"arn:aws:states:us-east-1:123456789012:stateMachine:hlsStitcherStepFunction",
input: JSON.stringify({
transcodeInput: {
//source:s3Location(streaming_url)
settings: settings,
},
presignedUrlInput: {
bucket: destinationBucket,
key: destinationKey,
},
sendMailInput: {
sendEmailInput: {
to: email,
downloadLink: "",
template: "work-archiver-template",
sender: process.env.REPOSITORY_EMAIL
},
}),
};
Expand Down
32 changes: 22 additions & 10 deletions state_machines/av_download.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"Comment": "HLS stiching and save as file in s3 and email download link",
"StartAt": "createTranscodeJob",
"StartAt": "startTranscode",
"States": {
"createTranscodeJob": {
"startTranscode": {
"Type": "Task",
"Resource": "arn:aws:lambda:us-east-1:123456789012:function:mediaTranscodeFunction",
"Next": "checkTranscodeJobStatus",
"Resource": "arn:aws:lambda:us-east-1:123456789012:function:startTranscodeFunction",
"Next": "transcodeStatus",
"InputPath": "$.transcodeInput",
"ResultPath": "$.transcodeOutput"
},
"checkTranscodeJobStatus": {
"transcodeStatus": {
"Type": "Task",
"Resource": "arn:aws:lambda:us-east-1:123456789012:function:transcodeCompleteFunction",
"Resource": "arn:aws:lambda:us-east-1:123456789012:function:transcodeStatusFunction",
"InputPath": "$.transcodeOutput",
"ResultPath": "$.transcodeOutput",
"Next": "transcodeCompleted?"
Expand All @@ -22,20 +22,32 @@
{
"Variable": "$.transcodeOutput.status",
"StringEquals": "COMPLETE",
"Next": "generateDownloadLink"
"Next": "getDownloadLink"
}
],
"Default": "Wait 10 seconds"
},
"Wait 10 seconds": {
"Type": "Wait",
"Seconds": 10,
"Next": "checkTranscodeJobStatus"
"Next": "transcodeStatus"
},
"generateDownloadLink": {
"getDownloadLink": {
"Type": "Task",
"Resource": "arn:aws:lambda:us-east-1:123456789012:function:generateDownloadLinkFunction",
"Resource": "arn:aws:lambda:us-east-1:123456789012:function:getDownloadLinkFunction",
"InputPath": "$.presignedUrlInput",
"ResultPath": "$.downloadLinkOutput",
"Next": "sendEmail"
},
"sendEmail": {
"Type": "Task",
"Resource": "arn:aws:lambda:us-east-1:123456789012:function:sendEmailFunction",
"Parameters": {
"to.$": "$.sendEmailInput.to",
"downloadLink.$": "$.downloadLinkOutput.downloadLink",
"sender.$": "$.sendEmailInput.sender",
"template.$": "$.sendEmailInput.template"
},
"End": true
}
}
Expand Down
Loading

0 comments on commit 93eeca1

Please sign in to comment.