Skip to content

Commit

Permalink
Fall back to JP2 oneshot load on tile part error
Browse files Browse the repository at this point in the history
  • Loading branch information
mbklein committed Nov 2, 2024
1 parent 2f33c09 commit 38b26dc
Show file tree
Hide file tree
Showing 14 changed files with 1,785 additions and 2,077 deletions.
880 changes: 364 additions & 516 deletions dependencies/package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dependencies/package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "serverless-iiif-dependencies",
"version": "5.0.6",
"version": "5.1.0",
"description": "Dependencies for serverless IIIF",
"author": "Michael B. Klein",
"license": "Apache-2.0",
"dependencies": {
"iiif-processor": "^4.0.5"
"sharp": "^0.33.5"
}
}
2 changes: 1 addition & 1 deletion examples/cloudformation/custom_hostname.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Resources:
Properties:
Location:
ApplicationId: arn:aws:serverlessrepo:us-east-1:625046682746:applications/serverless-iiif
SemanticVersion: 5.0.6
SemanticVersion: 5.1.0
Parameters:
ForceHost: !Sub '${CacheHostName}.${CacheDomainName}'
SourceBucket: !Ref IiifSourceBucket
Expand Down
2 changes: 1 addition & 1 deletion examples/sam/customization/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ Resources:
Properties:
Location:
ApplicationId: arn:aws:serverlessrepo:us-east-1:625046682746:applications/serverless-iiif
SemanticVersion: 5.0.6
SemanticVersion: 5.1.0
Parameters:
CorsAllowOrigin: REFLECT_ORIGIN
ForceHost: !Ref CacheDomainName
Expand Down
2 changes: 1 addition & 1 deletion extras/terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ terraform {

locals {
serverless_iiif_app_id = "arn:aws:serverlessrepo:us-east-1:625046682746:applications/serverless-iiif"
serverless_iiif_app_version = "5.0.6"
serverless_iiif_app_version = "5.1.0"
}

resource "aws_serverlessapplicationrepository_cloudformation_stack" "serverless_iiif" {
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "serverless-iiif",
"version": "5.0.6",
"version": "5.1.0",
"description": "Lambda wrapper for iiif-processor",
"author": "Michael B. Klein",
"license": "Apache-2.0",
Expand Down
4 changes: 2 additions & 2 deletions sam/cloudfront/template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Metadata:
ReadmeUrl: ./README.md
Labels: ["iiif", "image-processing"]
HomePageUrl: https://samvera.github.io/serverless-iiif
SemanticVersion: 5.0.6
SemanticVersion: 5.1.0
SourceCodeUrl: https://github.com/samvera/serverless-iiif
AWS::CloudFormation::Interface:
ParameterGroups:
Expand Down Expand Up @@ -324,7 +324,7 @@ Resources:
Properties:
Location:
ApplicationId: arn:aws:serverlessrepo:us-east-1:625046682746:applications/serverless-iiif
SemanticVersion: 5.0.6
SemanticVersion: 5.1.0
Parameters:
CorsAllowCredentials: !Ref CorsAllowCredentials
CorsAllowOrigin: !Ref CorsAllowOrigin
Expand Down
4 changes: 2 additions & 2 deletions sam/standalone/template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Metadata:
ReadmeUrl: ./README.md
Labels: ["iiif", "image-processing"]
HomePageUrl: https://samvera.github.io/serverless-iiif
SemanticVersion: 5.0.6
SemanticVersion: 5.1.0
SourceCodeUrl: https://github.com/samvera/serverless-iiif
AWS::CloudFormation::Interface:
ParameterGroups:
Expand Down Expand Up @@ -118,7 +118,7 @@ Resources:
Properties:
Location:
ApplicationId: arn:aws:serverlessrepo:us-east-1:625046682746:applications/serverless-iiif
SemanticVersion: 5.0.6
SemanticVersion: 5.1.0
Parameters:
CorsAllowCredentials: !Ref CorsAllowCredentials
CorsAllowHeaders: !Ref CorsAllowHeaders
Expand Down
12 changes: 7 additions & 5 deletions sam/template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Metadata:
ReadmeUrl: ../README.md
Labels: ["iiif", "image-processing"]
HomePageUrl: https://samvera.github.io/serverless-iiif
SemanticVersion: 5.0.6
SemanticVersion: 5.1.0
SourceCodeUrl: https://github.com/samvera/serverless-iiif
AWS::CloudFormation::Interface:
ParameterGroups:
Expand Down Expand Up @@ -136,13 +136,14 @@ Resources:
ContentUri: ../dependencies
CompatibleRuntimes:
- nodejs18.x
- nodejs20.x
LicenseInfo: "Apache-2.0"
Metadata:
BuildMethod: nodejs18.x
BuildMethod: nodejs20.x
IiifFunction:
Type: "AWS::Serverless::Function"
Properties:
Runtime: nodejs18.x
Runtime: nodejs20.x
Handler: index.handler
MemorySize:
Ref: IiifLambdaMemory
Expand All @@ -153,10 +154,9 @@ Resources:
Ref: IiifLambdaTimeout
CodeUri: ../src
Layers:
- Ref: Dependencies
- Fn::If:
- UseBuiltInDependencies
- !Ref AWS::NoValue
- Ref: Dependencies
- Fn::If:
- UseJP2SharpLayer
- !Sub "arn:aws:lambda:${AWS::Region}:625046682746:layer:libvips-sharp-jp2:4"
Expand Down Expand Up @@ -208,6 +208,8 @@ Resources:
- !Ref AWS::NoValue
resolverTemplate: !Ref ResolverTemplate
tiffBucket: !Ref SourceBucket
Metadata:
BuildMethod: makefile
Outputs:
EndpointV2:
Description: IIIF Image API v2 Endpoint
Expand Down
3 changes: 3 additions & 0 deletions src/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build-IiifFunction:
rsync -ar --exclude node_modules . $(ARTIFACTS_DIR)
npm ci --omit=optional --omit=dev --prefix $(ARTIFACTS_DIR)
19 changes: 16 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,25 @@ const handleServiceDiscoveryRequestFunc = () => {
href: '/iiif/3/{:id}',
name: 'IIIF Image API v3 endpoint'
}
]
],
versions: { ...require('sharp').versions }
})
};
};

const executeResource = async (uri, streamResolver, dimensionFunction, density, sharpOptions = {}) => {
try {
const resource = new IIIF.Processor(uri, streamResolver, { dimensionFunction, density, sharpOptions });
return await resource.execute();
} catch (err) {
if (/Invalid tile part index/.test(err.message) && !sharpOptions.jp2Oneshot) {
console.log('Encountered JP2 tile part index error. Trying oneshot load.');
return await executeResource(uri, streamResolver, dimensionFunction, density, { ...sharpOptions, jp2Oneshot: true });
}
throw err;
}
};

const handleResourceRequestFunc = async (event, context) => {
const density = helpers.parseDensity(process.env.density);
const { getUri } = helpers;
Expand All @@ -66,8 +80,7 @@ const handleResourceRequestFunc = async (event, context) => {
let resource;
try {
const uri = getUri(event);
resource = new IIIF.Processor(uri, streamResolver, { dimensionFunction: dimensionResolver, density: density });
const result = await resource.execute();
const result = await executeResource(uri, streamResolver, dimensionResolver, density);
return makeResponse(result);
} catch (err) {
return errorHandler(err, event, context, resource);
Expand Down
Loading

0 comments on commit 38b26dc

Please sign in to comment.