Substantial refactoring of code structure
This commit is contained in:
@@ -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);
|
||||
}
|
||||
Reference in New Issue
Block a user