Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
node-version: ${{ matrix['node-version'] }}
cache: 'npm'
- name: Install dependencies
run: npm ci
run: npm ci
- name: JS Tests
run: npm run test
current-runtime:
Expand All @@ -49,25 +49,42 @@ jobs:
node-version: lts/*
cache: 'npm'
- name: Install dependencies
run: npm ci
run: npm ci
- name: JS Tests
run: npm run test:coverage
- name: Send coverage to Coveralls
uses: coverallsapp/github-action@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
iiif-validator:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: lts/*
cache: 'npm'
- name: Setup uv
uses: astral-sh/setup-uv@v7
with:
working-directory: "validator"
- name: Install dependencies
run: npm ci && cd examples/tiny-iiif && npm i
- name: Run IIIF Validator
run: npm run validate
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: lts/*
cache: 'npm'
cache: 'npm'
- name: Install dependencies
run: npm ci
run: npm ci
- name: Type Check
run: npm run typecheck
run: npm run typecheck
- name: Lint
run: npm run lint
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,14 @@ The `pathPrefix` constructor option provides a tremendous amount of flexibility

### Processing

Primary processing is handled through the `Processor` class's `execute()` method. There are three possible return types:

- `ContentResult` (`type: "content"`) - includes a `canonicalLink`, a `profileLink`, a `contentType`, and a `body`
- `RedirectResult` (`type: "redirect"`) - includes a redirect `location` (used when the URL ends with the ID and should redirect to `info.json`)
- `ErrorResult` (`type: "Error"`) - includes an HTTP-compatible `statusCode` (e.g., `400` for bad requests; `500` for unhandled errors) and a `message`

In addition, certain error conditions may result in the throwing of an `IIIFError`, which also includes `statusCode` and `message` properties.

#### Promise
```typescript
import { Processor } from "iiif-processor";
Expand Down
2 changes: 1 addition & 1 deletion examples/tiny-iiif/clover-ui/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "clover-ui",
"private": true,
"version": "6.1.5",
"version": "7.0.0-rc.2",
"type": "module",
"scripts": {
"dev": "vite",
Expand Down
53 changes: 38 additions & 15 deletions examples/tiny-iiif/iiif.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import { App } from '@tinyhttp/app';
import { Processor, IIIFError } from 'iiif-processor';
import {
Processor,
IIIFError,
ContentResult,
ErrorResult,
ProcessorResult,
RedirectResult
} from 'iiif-processor';
import fs from 'fs';
import path from 'path';
import { iiifImagePath, iiifpathPrefix, fileTemplate } from './config';
Expand All @@ -14,21 +21,37 @@ const streamImageFromFile = async ({ id }: { id: string }) => {
};

const render = async (req: any, res: any) => {
if (req.params && req.params.filename == null) {
req.params.filename = 'info.json';
try {
const iiifUrl = `${req.protocol}://${req.get('host')}${req.path}`;
const iiifProcessor = new Processor(iiifUrl, streamImageFromFile, {
pathPrefix: iiifpathPrefix,
debugBorder: !!process.env.DEBUG_IIIF_BORDER
});
const result: ProcessorResult = await iiifProcessor.execute();
switch (result.type) {
case 'content':
return res
.set('Content-Type', result.contentType)
.set('Link', [
`<${result.canonicalLink}>;rel="canonical"`,
`<${result.profileLink}>;rel="profile"`
])
.status(200)
.send(result.body);
case 'redirect':
return res.redirect(result.location, 302);
case 'error':
return res
.set('Content-Type', 'text/plain')
.status(result.statusCode)
.send(result.message);
}
} catch (err) {
return res
.set('Content-Type', 'text/plain')
.status(err.statusCode || 500)
.send(err.message);
}

const iiifUrl = `${req.protocol}://${req.get('host')}${req.path}`;
const iiifProcessor = new Processor(iiifUrl, streamImageFromFile, {
pathPrefix: iiifpathPrefix,
debugBorder: !!process.env.DEBUG_IIIF_BORDER
});
const result = await iiifProcessor.execute();
return res
.set('Content-Type', result.contentType)
.set('Link', [`<${(result as any).canonicalLink}>;rel="canonical"`, `<${(result as any).profileLink}>;rel="profile"`])
.status(200)
.send(result.body);
};

function createRouter (version: number) {
Expand Down
5 changes: 3 additions & 2 deletions examples/tiny-iiif/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tiny-iiif",
"version": "6.1.5",
"version": "7.0.0-rc.2",
"description": "Example server for node-iiif using @tinyhttp",
"type": "module",
"main": "index.ts",
Expand All @@ -9,7 +9,8 @@
"lint": "eslint *.ts",
"lint-fix": "eslint --fix *.ts",
"tiny-iiif": "IIIF_IMAGE_PATH=./tiff tsx index.ts",
"dev:all": "concurrently -n build,server -c blue,green \"npm run --prefix ../.. build:watch\" \"npm run dev\""
"dev:all": "concurrently -n build,server -c blue,green \"npm run --prefix ../.. build:watch\" \"npm run dev\"",
"validator": "IIIF_IMAGE_PATH=../../validator/fixtures nodemon"
},
"repository": {
"type": "git",
Expand Down
3 changes: 3 additions & 0 deletions mise.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[tools]
node = "24.11.1"
uv = "0.9.5"
31 changes: 22 additions & 9 deletions package-lock.json

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

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "iiif-processor",
"version": "6.1.5",
"version": "7.0.0-rc.2",
"description": "IIIF 2.1 & 3.0 Image API modules for NodeJS",
"main": "dist/index.js",
"module": "dist/index.mjs",
Expand Down Expand Up @@ -53,7 +53,8 @@
"lint:fix": "eslint --fix \"{src,tests}/**/*.{js,ts}\"",
"lint:examples": "cd examples/tiny-iiif && npm run lint",
"test": "node scripts/test.js --env=node",
"test:coverage": "node scripts/test.js --env=node --coverage"
"test:coverage": "node scripts/test.js --env=node --coverage",
"validate": "concurrently -s !command-server -k -n server,iiif --hide server -c blue,green \"cd examples/tiny-iiif && npm run validator\" \"cd validator && sleep 2 && uv run ./run-validator.sh\""
},
"keywords": [
"iiif",
Expand Down
Loading