Skip to content

Commit

Permalink
Add commented superUser check
Browse files Browse the repository at this point in the history
  • Loading branch information
kdid committed Oct 11, 2023
1 parent 4435378 commit c09ae3d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
7 changes: 3 additions & 4 deletions lambdas/package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
{
"name": "lambda",
"name": "lambdas",
"version": "1.0.0",
"description": "",
"main": "check-transcode-job.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"author": "nulib",
"license": "Apache-2.0",
"devDependencies": {
"@aws-sdk/client-mediaconvert": "^3.410.0",
"@aws-sdk/client-s3": "^3.410.0",
Expand Down
27 changes: 13 additions & 14 deletions src/handlers/get-file-set-download.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,21 @@ const opensearchResponse = require("../api/response/opensearch");
const path = require("path");

/**
* Handler for download file set endpoint
* Handler for download file set endpoint (currently only handles AV)
*/
exports.handler = wrap(async (event) => {
const id = event.pathParameters.id;
const email = event.queryStringParameters?.email;
if (!email) {
return invalidRequest(400, "Query string must include email address");
}

// TODO uncomment superUser check and always allowPrivate+allowUnpublished below
// if(!event.userToken.isSuperUser()) {
// return invalidRequest(401, "Unauthorized");
// }
// const esResponse = await getFileSet(id, { true, true });

const allowPrivate =
event.userToken.isSuperUser() || event.userToken.isReadingRoom();
const allowUnpublished = event.userToken.isSuperUser();
Expand Down Expand Up @@ -58,26 +65,18 @@ function processDownload(doc, email) {
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(fileSet.streaming_url); // camelCase streaming url?
const sourceLocation = s3Location(fileSet.streaming_url);
const destinationBucket = process.env.MEDIA_CONVERT_DESTINATION_BUCKET;
const fileSetId = path.parse(url.pathname).name
const fileSetLabel = 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 destinationKey = `downloads/${fileSetId}.mp4`; //TODO - here?
const destinationLocation = `s3://${destinationBucket}/downloads/${fileSetId}`; // TODO - here?
const settings = transcodeSettings(sourceLocation, destinationLocation);

// console.log("url", url);
// console.log("streaming_url", streaming_url);
// console.log("sourceLocation", sourceLocation);
// console.log("destinationBucket", destinationBucket);
// console.log("destinationKey", destinationKey);
// console.log("destinationLocation", destinationLocation);

// move the state machine arn to variable
// TODO move the state machine arn to variable
var params = {
stateMachineArn:
"arn:aws:states:us-east-1:123456789012:stateMachine:hlsStitcherStepFunction",
Expand Down Expand Up @@ -119,7 +118,7 @@ function processDownload(doc, email) {
statusCode: 200,
headers: { "content-type": "text/plain" },
body: JSON.stringify({
message: `Creating download for ${fileSet.streaming_url}. Check your email for a link.`,
message: `Creating download for file set (id: ${fileSet.id}. Check your email for a link.`,
}),
};
}
Expand Down

0 comments on commit c09ae3d

Please sign in to comment.