Skip to content

Commit

Permalink
IIIF V3 fixes, refs #132
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabian authored and Fabian committed Jun 8, 2020
1 parent 5e2379c commit 74d198b
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 30 deletions.
4 changes: 2 additions & 2 deletions src/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ class Item extends React.Component<IProps, {}> {
manifestId,
function(file: any) {
const type = file.resource.type;
if (type === 'audioVideo') {
if (type === 'audio' || type === 'video') {
Cache.ee.emit('play-audio', file.resource.source);
} else if (type === 'file') {
const win = window.open(file.resource.source, '_target');
const win = window.open(file.resource.id, '_target');
if (win) {
win.focus();
}
Expand Down
78 changes: 56 additions & 22 deletions src/lib/Manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ class Manifest {
manifestData.manifests = [];
manifestData.restricted = true;
} else {
const isV3 = this.isV3(manifestoData);
manifestData.metadata = t.getMetadata(manifestoData);
manifestData.description = t.getDescription(manifestoData);
manifestData.license = t.getLicense(manifestoData);
Expand All @@ -160,7 +161,7 @@ class Manifest {
manifestData.manifests = t.getManifests(manifestoData);
manifestData.collections = t.getCollections(manifestoData);
} else if (manifestData.type === 'sc:Manifest') {
manifestData.resource = t.getResource(manifestoData);
manifestData.resource = t.getResource(manifestoData, isV3);
}
manifestData.thumbnail = t.getThumbnail(manifestoData);

Expand Down Expand Up @@ -243,7 +244,7 @@ class Manifest {
return license;
}

static getResource(manifestoData: any) {
static getResource(manifestoData: any, isV3: boolean) {

const resource = {
source: null,
Expand All @@ -262,7 +263,7 @@ class Manifest {
}


if (this.isV3(manifestoData)) {
if (isV3) {
const iiif3Resource = this.getIIF3Resource(sequence0);
if (iiif3Resource !== false) {
return iiif3Resource;
Expand Down Expand Up @@ -369,14 +370,44 @@ class Manifest {
type: 'audio'
};
}
if (source.getFormat().toLowerCase() === 'application/pdf') {
return {
format: 'application/pdf',
id: source.id,
type: 'pdf'
};
}
if (source.getFormat().toLowerCase() === 'text/plain') {
return {
format: 'text/plain',
id: source.id,
type: 'plainText'
};
}

if (source.getType() === 'image') {
const service = source.getService('level2');
if (service) {
images.push(service.id);
const profiles = [
'level2',
'level3',
'http://iiif.io/api/image/2/level2.json',
'http://iiif.io/api/image/2/level2.json'
]
for(const profile of profiles) {
const service = source.getService(profile);
if (service) {
images.push(service.id);
break;
}
}

} else {
return {
format: source.getFormat(),
id: source.id,
type: 'file'
};
}

} catch (e) {
return false;
}
Expand All @@ -393,27 +424,30 @@ class Manifest {


static getFileResource(sequence0: any) {


try {
const source = sequence0.getCanvasByIndex(0).getContent()[0].getBody()[0].id;
return {
source,
type: 'file'
};
} catch (e) {
}

try {
const source = sequence0.getCanvasByIndex(0).id;
const format = sequence0.getCanvasByIndex(0).__jsonld.format;
const element = sequence0.getCanvasByIndex(0)
const id = sequence0.getCanvasByIndex(0).id;
const format = element.__jsonld.format;
if (format === 'application/pdf') {
return {
id,
type: 'pdf',
format
};
}
if (format === 'text/plain') {
return {
id,
type: 'plainText',
format
};
}
return {
source,
id,
type: 'file',
format
};
} catch (e) {
}
} catch (e) {}

return null;
}
Expand Down
1 change: 1 addition & 0 deletions src/viewer/PlainTextViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class PlainTextViewer extends React.Component<IProps, IState> {

componentDidMount() {
const t = this;
console.log(this.props.source)
fetch(this.props.source)
.then(function(response) {
return response.text();
Expand Down
14 changes: 8 additions & 6 deletions src/viewer/Viewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ class Viewer extends React.Component<IProps, {}> {
return this.renderAudioVideo();
}

if (manifestData.resource.format === 'text/plain') {
if (manifestData.resource.type === 'plainText') {
return this.renderPlainText();
}

if (manifestData.resource.format === 'application/pdf') {
if (manifestData.resource.type === 'pdf') {
return this.renderPdf();
}

Expand All @@ -59,16 +59,18 @@ class Viewer extends React.Component<IProps, {}> {
const resource: any = this.props.data.resource;
return (
<div id="viewer">
<PlainTextViewer source={resource.source} key={resource.source}/>
<PlainTextViewer source={resource.id} key={resource.id}/>
</div>
);
}
}

renderPdf() {
if (this.props.data) {
const resource: any = this.props.data.resource;
return <iframe id="viewer" src={resource.source} title={resource.source}/>;

if (this.props.data && this.props.data.resource) {
const id = this.props.data.resource.id

return <iframe id="viewer" src={id} title={id}/>;
}
}

Expand Down

0 comments on commit 74d198b

Please sign in to comment.