Use private properties in classes

This commit is contained in:
Nicolò P 2023-10-27 12:50:49 +02:00
parent e9e299d845
commit b91f14055a
6 changed files with 30 additions and 26 deletions

View File

@ -12,7 +12,7 @@ export default async function generateCanvas(manifestId, name) {
const canvas = new Canvas(IIIF_API_VERSION, BASE_URL);
canvas.generateID(manifestId, name);
canvas.setLabel(`${manifestId}-${name.toLowerCase()}`);
canvas.label = `${manifestId}-${name.toLowerCase()}`;
const image = new Image(canvas.id);
image.generateID(process.env.IMAGE_SERVER_URL, await Common.getImageName(canvas));

View File

@ -5,8 +5,8 @@ import Image from './Image.js';
*/
class Canvas {
id = '';
type = 'sc:Canvas';
label = '';
#type = 'sc:Canvas';
#label = '';
resourceId = '';
name = '';
images = [];
@ -28,8 +28,8 @@ class Canvas {
/**
* @param {string} label A label for this canvas
*/
setLabel(label) {
this.label = label;
set label(label) {
this.#label = label;
}
/**
* @param {Image} image Add an image to the canvas
@ -59,8 +59,8 @@ class Canvas {
return {
"@context" : this.context,
"@id" : this.id,
"@type" : this.type,
"label" : this.label,
"@type" : this.#type,
"label" : this.#label,
"images" : this.images,
"thumbnail" : this.thumbnail
}

View File

@ -4,15 +4,15 @@ import IIIFResource from './IIIFResource.js';
*/
class Image {
id = '';
context = `https://iiif.io/api/presentation/${process.env.IIIF_API_VERSION}/context.json`;
type = 'oa:Annotation';
motivation = 'sc:painting';
__type = 'dctypes:Image';
__format = 'image/jpeg';
#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,
"@context" : this.#context,
"@id" : '',
profile : 'https://iiif.io/api/image/2/level2.json',
};
@ -53,13 +53,13 @@ class Image {
*/
toObject() {
return {
"@context" : this.context,
"@type" : this.type,
motivation : this.motivation,
"@context" : this.#context,
"@type" : this.#type,
motivation : this.#motivation,
resource : {
"@id" : this.id,
"@type" : this.__type,
format: this.__format,
"@type" : this.#resType,
format: this.#format,
service : this.service,
height: this.height,
width: this.width,

View File

@ -1,12 +1,16 @@
import IIIFResource from './IIIFResource.js';
import Sequence from "./Sequence.js";
const TECH = {
nir: "Technical Photography, Near Infrared Imaging 1000nm",
}
/**
* @implements IIIFResource
*/
class Manifest {
id = '';
_type = 'sc:Manifest';
_label = '';
#type = 'sc:Manifest';
#label = '';
resourceId = '';
/**
* @var {Sequence[]}
@ -34,7 +38,7 @@ class Manifest {
* Create IIIF label for this manifest
*/
generateLabel() {
this._label = `P.Herc. ${this.resourceId.split('-')[1]}`;
this.#label = `P.Herc. ${this.resourceId.split('-')[1]}`;
}
/**
* Object representation of this
@ -47,8 +51,8 @@ class Manifest {
return {
"@context" : this.context,
"@id" : this.id,
"@type" : this._type,
label : this._label,
"@type" : this.#type,
label : this.#label,
sequences: this.sequences,
}
}

View File

@ -8,7 +8,7 @@ import Canvas from './Canvas.js';
class Sequence {
canvases = [];
id = '';
type = 'sc:Sequence';
#type = 'sc:Sequence';
resourceId = '';
constructor(baseUrl) {
@ -34,7 +34,7 @@ class Sequence {
toObject() {
return {
"@id" : this.id,
"@type" : this.type,
"@type" : this.#type,
canvases : this.canvases
}
}

View File

@ -75,7 +75,7 @@ Common.populateCanvases = async function (manifest, images) {
const canvasName = img.split('_')[3].replace(/\.[\w\d]{2,3}$/,'');
canvas.generateID(manifest.resourceId, canvasName);
canvas.setLabel(`${manifest.resourceId}-${canvasName.toLowerCase()}`);
canvas.label = `${manifest.resourceId}-${canvasName.toLowerCase()}`;
let image = new Image(canvas.id);
image.generateID(process.env.IMAGE_SERVER_URL, img);