From b91f14055a0b99e195a63afe7eb75c6e6934e164 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20P?= Date: Fri, 27 Oct 2023 12:50:49 +0200 Subject: [PATCH] Use private properties in classes --- controllers/canvas.mjs | 2 +- src/Canvas.js | 12 ++++++------ src/Image.js | 22 +++++++++++----------- src/Manifest.js | 14 +++++++++----- src/Sequence.js | 4 ++-- src/common.js | 2 +- 6 files changed, 30 insertions(+), 26 deletions(-) diff --git a/controllers/canvas.mjs b/controllers/canvas.mjs index d15286e..edbf742 100644 --- a/controllers/canvas.mjs +++ b/controllers/canvas.mjs @@ -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)); diff --git a/src/Canvas.js b/src/Canvas.js index 952d6e9..a6a2e90 100644 --- a/src/Canvas.js +++ b/src/Canvas.js @@ -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 } diff --git a/src/Image.js b/src/Image.js index 9115dc7..0b92d9c 100644 --- a/src/Image.js +++ b/src/Image.js @@ -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, diff --git a/src/Manifest.js b/src/Manifest.js index c80e482..d269da1 100644 --- a/src/Manifest.js +++ b/src/Manifest.js @@ -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, } } diff --git a/src/Sequence.js b/src/Sequence.js index 3e49b80..05ee787 100644 --- a/src/Sequence.js +++ b/src/Sequence.js @@ -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 } } diff --git a/src/common.js b/src/common.js index 7e58adc..5cc2842 100644 --- a/src/common.js +++ b/src/common.js @@ -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);