From c09ae3ddeb2d545b50460e868353c4a392fe8387 Mon Sep 17 00:00:00 2001 From: Karen Shaw Date: Wed, 11 Oct 2023 14:19:45 +0000 Subject: [PATCH] Add commented superUser check --- lambdas/package.json | 7 +++---- src/handlers/get-file-set-download.js | 27 +++++++++++++-------------- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/lambdas/package.json b/lambdas/package.json index 30e4a204..36adb36d 100644 --- a/lambdas/package.json +++ b/lambdas/package.json @@ -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", diff --git a/src/handlers/get-file-set-download.js b/src/handlers/get-file-set-download.js index 02d55d15..ab75d65d 100644 --- a/src/handlers/get-file-set-download.js +++ b/src/handlers/get-file-set-download.js @@ -7,7 +7,7 @@ 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; @@ -15,6 +15,13 @@ exports.handler = wrap(async (event) => { 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(); @@ -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", @@ -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.`, }), }; }