111 lines
2.9 KiB
JavaScript
111 lines
2.9 KiB
JavaScript
import IIIFResource from './IIIFResource.js';
|
|
|
|
/**
|
|
* @todo Move to common.js?!
|
|
*/
|
|
const splitter = {
|
|
NIR: splitNIR,
|
|
DN: splitDNO,
|
|
DO: splitDNO,
|
|
HSI: splitHSI
|
|
};
|
|
|
|
function splitNIR(filename) {
|
|
let splitFilename = filename.split('_');
|
|
const papyrusNumb = splitFilename[0].split('-')[2];
|
|
const baseFolder = `PHerc_${papyrusNumb}`;
|
|
const subfolder = `PHerc_${papyrusNumb}_${splitFilename[2].split('-')[0]}`;
|
|
|
|
return {baseFolder, subfolder};
|
|
}
|
|
/**
|
|
* @todo Redundant...
|
|
*/
|
|
function splitHSI(filename) {
|
|
let splitFilename = filename.split('_');
|
|
const papyrusNumb = splitFilename[0].split('-')[2];
|
|
const baseFolder = `PHerc_${papyrusNumb}`;
|
|
const subfolder = `PHerc_${papyrusNumb}_${splitFilename[2]}`;
|
|
|
|
return {baseFolder, subfolder};
|
|
}
|
|
|
|
function splitDNO(filename) {
|
|
let splitFilename = filename.split('_');
|
|
const baseFolder = splitFilename.slice(0,2).join('_');
|
|
const subfolder = splitFilename.slice(0,3).join('_');
|
|
|
|
return {baseFolder, subfolder};
|
|
}
|
|
|
|
/**
|
|
* @implements IIIFResource
|
|
*/
|
|
class Image {
|
|
id = '';
|
|
#context = `https://iiif.io/api/presentation/${process.env.IIIF_API_VERSION}/context.json`;
|
|
#type = 'oa:Annotation';
|
|
#motivation = 'sc:painting';
|
|
#resType = 'dctypes:Image';
|
|
#format = 'image/jpeg';
|
|
height = 0;
|
|
width = 0;
|
|
service = {
|
|
"@context" : this.#context,
|
|
"@id" : '',
|
|
profile : 'https://iiif.io/api/image/2/level2.json',
|
|
};
|
|
canvasId = '';
|
|
/**
|
|
*
|
|
* @param {string} canvasId The canvas IIIF id
|
|
*/
|
|
constructor(canvasId) {
|
|
this.canvasId = canvasId;
|
|
}
|
|
/**
|
|
* @param {number} height
|
|
* @param {number} width
|
|
*/
|
|
setSize(height, width) {
|
|
this.height = height;
|
|
this.width = width;
|
|
}
|
|
/**
|
|
* Generate IIIF id pointing to image
|
|
* server endpoint for this image
|
|
* @param {string} serviceURL The image server base URL
|
|
* @param {string} filename The image's complete filename
|
|
*/
|
|
generateID(serviceURL, filename) {
|
|
let splitFn = splitter[/(NIR|DO|DN|HSI)/.exec(filename)[0]];
|
|
|
|
const {baseFolder, subfolder} = splitFn(filename);
|
|
|
|
this.id = `${serviceURL}/2/${baseFolder}%2F${subfolder}%2F${filename}/full/full/0/default.jpg`;
|
|
this.service['@id'] = this.id.replace(/\/full.*$/,'');
|
|
}
|
|
/**
|
|
* Object representation of this image
|
|
*
|
|
* @returns {Object}
|
|
*/
|
|
toObject() {
|
|
return {
|
|
"@context" : this.#context,
|
|
"@type" : this.#type,
|
|
motivation : this.#motivation,
|
|
resource : {
|
|
"@id" : this.id,
|
|
"@type" : this.#resType,
|
|
format: this.#format,
|
|
service : this.service,
|
|
height: this.height,
|
|
width: this.width,
|
|
},
|
|
on : this.canvasId
|
|
}
|
|
}
|
|
}
|
|
|
|
export default Image; |