Substantial refactoring of code structure

This commit is contained in:
2026-03-23 15:20:30 +01:00
parent 4b9b5b737d
commit 012ad62382
23 changed files with 565 additions and 482 deletions

View File

@@ -1,7 +1,5 @@
import Canvas from '../src/Canvas.js';
import Image from '../src/Image.js';
import Manifest from '../src/Manifest.js';
import Common from '../src/common.js';
import { buildCanvas } from '../src/service/ManifestBuilder.js';
/**
* Generate a canvas object to serve
* @todo Use createCanvas from Common?
@@ -10,47 +8,5 @@ import Common from '../src/common.js';
* @param {number|string} name The canvas name
*/
export default async function generateCanvas(manifestId, name) {
const IIIF_API_VERSION = process.env.IIIF_API_VERSION;
const BASE_URL = process.env.BASE_URL;
const canvas = new Canvas(IIIF_API_VERSION, BASE_URL);
const manifest = new Manifest(IIIF_API_VERSION, BASE_URL);
manifest.generateID(manifestId);
canvas.generateID(manifestId, name);
let filename = await Common.getImageName(canvas)
console.log('Filename: ' + filename);
let label = name.replace(
/c(\w{1,2})0+(\d+).*(\.\w{2,3})?$/i,
function (str, c, number) {
return `C${c}. ${number}`;
});
// Add PCA to canvas label for HSI images
if (manifest.technique === 'hsi') {
label += ` ${filename.split('_')[3].replace(/\..*$/,'')}`;
}
canvas.label = label;
const image = new Image(canvas.id, filename);
image.generateID(process.env.IMAGE_SERVER_URL, filename);
const imgSize = await Common.getImageSize(image.id);
image.setSize(imgSize.height, imgSize.width);
canvas.setThumbnail(
imgSize.thumb.height,
imgSize.thumb.width,
image.id
);
canvas.addImage(image);
return canvas.toObject();
/**
const manifest = new Manifest(IIIF_API_VERSION, BASE_URL);
manifest.generateID(manifestId);
return Common.createCanvas(manifest, name, manifestId).toObject();
*/
return buildCanvas(manifestId, name);
}

View File

@@ -1,34 +1,12 @@
'use strict';
import Manifest from '../src/Manifest.js';
import Common from '../src/common.js';
//import Common from '../src/common.js';
import { buildManifest } from '../src/service/ManifestBuilder.js';
/**
* Generate a manifest object to serve
* @param {string} manifestId
*/
export default async function generateManifest(manifestId) {
const IIIF_API_VERSION = process.env.IIIF_API_VERSION;
const BASE_URL = process.env.BASE_URL;
let manifest = new Manifest(IIIF_API_VERSION, BASE_URL);
manifest.generateID(manifestId);
manifest.generateLabel();
const images = await Common.getImageList(manifestId);
manifest = await Common.populateCanvases(
manifest,
images,
manifestId
);
manifest.setMetadata(
Common.createMetadata(
manifest,
images[0],
)
);
return manifest.toObject();
return buildManifest(manifestId);
}

View File

@@ -1,22 +1,20 @@
'use strict';
import Common from '../src/common.js';
import { TECH_NAMES } from "../src/constants.js";
import { getParamsFromFolders } from "../src/service/ImageRepository.js";
/**
* Show all possible parameters for manifest URLs
*/
export default async function exposeParams() {
console.log(process.env.IMAGES_DIR);
let techs = [];
for (let key in Common.TECH_NAMES) {
techs.push({
'acronym': key.toUpperCase(),
'fullname': Common.TECH_NAMES[key]
});
}
const techs = Object.entries(TECH_NAMES).map(([key, fullname]) => ({
acronym: key.toUpperCase(),
fullname,
}));
let papyri = await Common.getParamsFromFolders();
let papyri = await getParamsFromFolders();
return {
'techniques' : techs,