Skip to content

Commit

Permalink
Convert IIIF viewer request function from CommonJS to ESM and upgrade @…
Browse files Browse the repository at this point in the history
  • Loading branch information
mbklein committed Nov 22, 2024
1 parent 443c2a9 commit d3f83c6
Show file tree
Hide file tree
Showing 5 changed files with 3,712 additions and 617 deletions.
8 changes: 3 additions & 5 deletions iiif-server/src/authorize.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const isString = require("lodash.isstring");
const fetch = require("node-fetch");
import isString from "lodash.isstring";
import fetch from "node-fetch";

let allowFrom, dcApiEndpoint;
function reconfigure(config) {
Expand Down Expand Up @@ -28,7 +28,7 @@ function isBlurred({ region, size }) {
return false;
}

async function authorize(params, referer, cookie, clientIp, config) {
export async function authorize(params, referer, cookie, clientIp, config) {
reconfigure(config);
const allowedFrom = allowedFromRegexes(allowFrom);

Expand Down Expand Up @@ -58,5 +58,3 @@ async function getImageAuthorization(id, cookieHeader, clientIp) {
);
return response.status == 204;
}

module.exports = authorize;
32 changes: 15 additions & 17 deletions iiif-server/src/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
const authorize = require("./authorize");
const validateJwtClaims = require("./validate-jwt");
const jwt = require("jsonwebtoken");
const middy = require("@middy/core");
const secretsManager = require("@middy/secrets-manager");

import { authorize } from './authorize.js';
import { validateJwtClaims } from "./validate-jwt.js";
import jwt from "jsonwebtoken";
import middy from "@middy/core";
import secretsManager from "@middy/secrets-manager";

function getEventHeader(request, name) {
if (
Expand Down Expand Up @@ -176,6 +175,7 @@ async function processViewerRequest(event, context) {
// }

async function processRequest(event, context) {
console.log(context);
const { eventType } = event.Records[0].cf.config;
let result;

Expand Down Expand Up @@ -205,14 +205,12 @@ function functionNameAndRegion() {
const { functionName, functionRegion } = functionNameAndRegion();
console.log("Initializing", functionName, 'in', functionRegion);

module.exports = {
handler:
middy(processRequest)
.use(
secretsManager({
fetchData: { config: functionName },
awsClientOptions: { region: functionRegion },
setToContext: true
})
)
};
export const handler =
middy(processRequest)
.use(
secretsManager({
fetchData: { config: functionName },
awsClientOptions: { region: functionRegion },
setToContext: true
})
);
Loading

0 comments on commit d3f83c6

Please sign in to comment.