Skip to content

Commit

Permalink
Deal with mime-type and email template params - wip
Browse files Browse the repository at this point in the history
  • Loading branch information
kdid committed Oct 9, 2023
1 parent 93eeca1 commit 708f99d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 13 deletions.
8 changes: 4 additions & 4 deletions lambdas/assets/email.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<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>
<title>Meadow AV Download</title>
<meta content='IE=edge' http-equiv='X-UA-Compatible' />
<style>
p {
Expand Down Expand Up @@ -121,13 +121,13 @@ <h1>
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:
Your request for AV Download of <a href="{{referer}}work/{{workId}}">{{title}}</a> (accession: {{accession}}) has been
fulfilled. Click below to download your 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}}" />
<img src="https://iiif.dc.library.northwestern.edu/iiif/2/00000000-0000-0000-0000-000000000002/square/100,100/0/default.jpg" alt="{{downloadKey}}" />
</a>
</p>
<p style='text-align: center; font-style: italic'>
Expand Down
2 changes: 1 addition & 1 deletion 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 {downloadLink: url}
return {downloadLink: url, params: {downloadlink: url}

};

Expand Down
35 changes: 27 additions & 8 deletions src/handlers/get-file-set-download.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ exports.handler = wrap(async (event) => {
if (esResponse.statusCode == "200") {
const doc = JSON.parse(esResponse.body);
if (downloadAvailable(doc)) {
return processDownload(doc._source.streaming_url, email);
return processDownload(doc, email);
} else {
return invalidRequest(
405,
Expand All @@ -43,23 +43,29 @@ function downloadAvailable(doc) {
return (
doc.found &&
doc._source.role === "Access" &&
doc._source.mime_type != null &&
["audio", "video"].includes(doc._source.mime_type.split("/")[0]) &&
doc._source.streaming_url != null
);
}

function processDownload(streaming_url, email) {
function processDownload(doc, email) {
console.log("PROCESS DOWNLOAD");
// move endpoint to var? or ??
var stepfunctions = new AWS.StepFunctions({
endpoint: "http://172.17.0.1:8083",
});
const url = new URL(streaming_url);
const fileSet = doc._source
const url = new URL(fileSet.streaming_url);

// does the role at least belong in the Media convert lambda

const sourceLocation = s3Location(streaming_url); // camelCase streaming url?
const sourceLocation = s3Location(fileSet.streaming_url); // camelCase streaming url?
const destinationBucket = process.env.MEDIA_CONVERT_DESTINATION_BUCKET;
const fileSetId = path.parse(url.pathname).name
const label = fileSet.label
const workId = fileSet.work_id
const fileType = fileSet.mime_type.split("/")[0]
const destinationKey = `downloads/${fileSetId}.mp4`;
const destinationLocation = `s3://${destinationBucket}/downloads/${fileSetId}`;
const settings = transcodeSettings(sourceLocation, destinationLocation);
Expand Down Expand Up @@ -87,18 +93,31 @@ function processDownload(streaming_url, email) {
to: email,
downloadLink: "",
template: "work-archiver-template",
sender: process.env.REPOSITORY_EMAIL
sender: process.env.REPOSITORY_EMAIL,
fileSetId,
fileSetLabel: label,
workId,
fileType,
// params: {
// to: email,
// downloadLink: "",
// sender: process.env.REPOSITORY_EMAIL,
// fileSetId,
// fileSetLabel: label,
// workId,
// fileType,
// }
},
}),
};

console.log(params);

stepfunctions.startExecution(params, function(err, data) {
stepfunctions.startExecution(params, function (err, data) {
if (err) {
console.log(err, err.stack);

}else {
} else {
console.log(data);

}
Expand All @@ -107,7 +126,7 @@ function processDownload(streaming_url, email) {
statusCode: 200,
headers: { "content-type": "text/plain" },
body: JSON.stringify({
message: `Creating download for ${streaming_url}. Check your email for a link.`,
message: `Creating download for ${fileSet.streaming_url}. Check your email for a link.`,
}),
};
}
Expand Down

0 comments on commit 708f99d

Please sign in to comment.