Skip to content

Commit

Permalink
@archival-iiif/presentation-builder added
Browse files Browse the repository at this point in the history
  • Loading branch information
Sozialarchiv committed Sep 25, 2021
1 parent cdcd587 commit a42a3ea
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 36 deletions.
2 changes: 1 addition & 1 deletion data/manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"label": "Amsterdam",
"label": {"none": ["Amsterdam"]},
"description": {
"en": ["A fictitious package with <a href=\"https://commons.wikimedia.org/wiki/Category:Amsterdam\">commons</a> of the city of <a href=\"https://en.wikipedia.org/wiki/Amsterdam\">Amsterdam</a>"],
"de": ["Ein fiktives Paket mit <a href=\"https://commons.wikimedia.org/wiki/Category:Amsterdam\">commons</a> der Stadt <a href=\"https://de.wikipedia.org/wiki/Amsterdam\">Amsterdam</a>"]
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"dependencies": {
"@archival-iiif/presentation-builder": "^1.3.2",
"@archival-iiif/image-server-core": "^1.0.7",
"@archival-iiif/viewer": "^1.0.12",
"archiver": "^5.3.0",
Expand Down
64 changes: 29 additions & 35 deletions src/api/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import fs from 'fs';
import path from 'path';
import common from './common';
import getBaseUrl from "../lib/BaseUrl";
import {Collection, Manifest, Resource} from "@archival-iiif/presentation-builder";

const router: Router = new Router();

Expand All @@ -17,16 +18,17 @@ router.get('/iiif/collection/:id', ctx => {
ctx.throw(404)
}

let output: any = {
id: common.getUriByObjectPath(objectPath, ctx, 'collection'),
type: 'Collection',
label: path.basename(objectPath),
'@context': 'http://iiif.io/api/presentation/3/context.json'
};
let collection = new Collection(
common.getUriByObjectPath(objectPath, ctx, 'collection'),
path.basename(objectPath)
);
collection.setContext();

if (!isRoot) {
const parentPath = path.resolve(objectPath, '..');
output.partOf = [{id: common.getUriByObjectPath(parentPath, ctx, 'collection'), type: 'Collection'}];
collection.setParent(
common.getUriByObjectPath(parentPath, ctx, 'collection')
);
}

fs.readdirSync(objectPath).map((name: string) => {
Expand All @@ -39,47 +41,39 @@ router.get('/iiif/collection/:id', ctx => {

if (fs.lstatSync(subObjectPath).isDirectory()) {

if (!output.hasOwnProperty('items')) {
output.items = [];
}

output.items.push(
{
id: common.getUriByObjectPath(subObjectPath, ctx, 'collection'),
type: 'Collection',
label: name,
}
const subCollection = new Collection(
common.getUriByObjectPath(subObjectPath, ctx, 'collection'),
name
);

collection.setItems(subCollection)
} else {
if (!output.hasOwnProperty('items')) {
output.items = [];
}

const mediaTypeAndFormat = common.getMediaTypeAndFormat(subObjectPath, ctx);

let manifest = {
'id': common.getUriByObjectPath(subObjectPath, ctx, 'manifest'),
'type': 'Manifest',
label: name,
thumbnail: mediaTypeAndFormat.thumbnail,
};
let manifest = new Manifest(
common.getUriByObjectPath(subObjectPath, ctx, 'manifest'),
name
);
manifest.setThumbnail(new Resource(
mediaTypeAndFormat.thumbnail.id,
'image',
undefined,
mediaTypeAndFormat.thumbnail.format,
));

manifest = common.addMetadata(manifest, subObjectPath);

output.items.push(manifest);
collection.setItems(manifest);
}
});

output = common.addMetadata(output, objectPath);

output.rendering = {
collection.setRendering({
id: getBaseUrl(ctx) + '/zip/' + ctx.params.id,
label: {en: ['Download folder'], de: ['Ordner herunterladen']},
format: 'application/zip'
}
});

collection = common.addMetadata(collection, objectPath);

ctx.body = output;
ctx.body = collection;

});

Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
"@types/sharp" "0.28.5"
sharp "0.28.3"

"@archival-iiif/presentation-builder@^1.3.2":
version "1.3.2"
resolved "https://registry.yarnpkg.com/@archival-iiif/presentation-builder/-/presentation-builder-1.3.2.tgz#1dbbcb51b1ad6b63926d4869b1df796ac10d708f"
integrity sha512-m1o2ALsya0fcilg+xgK5b98086LQTFvUxepMbxuqWuvah47yohhFcniv8janOuxKAQ9Eb9dQCXqrI+FD6Gzqrg==

"@archival-iiif/viewer@^1.0.12":
version "1.0.12"
resolved "https://registry.yarnpkg.com/@archival-iiif/viewer/-/viewer-1.0.12.tgz#03fce82cd5f0e63a66aac40897ce93a98964396a"
Expand Down

0 comments on commit a42a3ea

Please sign in to comment.