-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add feature - generate manifests for micrographs
- Loading branch information
1 parent
aeb74e0
commit f1a9e83
Showing
4 changed files
with
189 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import fetch from 'node-fetch'; | ||
import { promises as fsPromises } from 'fs'; | ||
import config from './config.js'; | ||
|
||
const { apiBase } = config; | ||
|
||
export async function fetchMiniatureAll() { | ||
const response = await fetch(apiBase + "items/miniatures"); | ||
return (await response.json()).data; | ||
} | ||
|
||
export async function fetchMiniature(id) { | ||
const response = await fetch(apiBase + "items/miniatures/" + id); | ||
return (await response.json()).data; | ||
} | ||
|
||
export async function fetchMicrographAll() { | ||
const response = await fetch(apiBase + "items/micrographs"); | ||
return (await response.json()).data; | ||
} | ||
|
||
export async function fetchMicrograph(id) { | ||
const response = await fetch(apiBase + "items/micrographs/" + id); | ||
return (await response.json()).data; | ||
} | ||
|
||
export async function fetchAllMaXrf() { | ||
const response = await fetch(apiBase + "items/ma_xrf_scans"); | ||
return (await response.json()).data; | ||
} | ||
|
||
export async function downloadImage(id, outputFilePath, imageOptions) { | ||
let path = apiBase + "assets/" + id + "?quality=90"; | ||
if (imageOptions.width != undefined) { | ||
path += "&width=" + imageOptions.width; | ||
} | ||
if (imageOptions.height != undefined) { | ||
path += "&height=" + imageOptions.height; | ||
} | ||
const response = await fetch(path); | ||
return fsPromises.writeFile(outputFilePath, response.body); | ||
} | ||
|
||
export async function fetchFileObject(id) { | ||
const response = await fetch(apiBase + "files/" + id); | ||
return (await response.json()).data; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import { promises as fsPromises } from 'fs'; | ||
import path from 'path'; | ||
import config from './config.js'; | ||
import { fetchFileObject } from './directus.js'; | ||
|
||
export default async function (item, miniatureId, manifestLabel) { | ||
|
||
const basePath = config.basePath + miniatureId + "/"; | ||
|
||
const micrographManifestId = `${config.basePath}${miniatureId}/micrograph/${item.id}/manifest.json`; | ||
|
||
const micrographImageData = await fetchFileObject(item.micrograph); | ||
const micrographImageExtension = micrographImageData.type == "image/tiff" ? "tif" : "jpg"; | ||
const micrographImageAPIBase = config.imageAPI + micrographImageData.filename_disk; | ||
const micrographImageId = micrographImageAPIBase + "/full/max/0/default." + micrographImageExtension; | ||
|
||
const micrographBasePath = basePath + 'micrograph/' + item.id; | ||
const micrographCanvasId = micrographBasePath + '/canvas/0'; | ||
const micrographCanvasHeight = micrographImageData?.height || 1800; | ||
const micrographCanvasWidth = micrographImageData?.width || 1200; | ||
const micrographAnnotationPageId = micrographBasePath + "page/0/0"; | ||
const micrographAnnotationPaintingId = micrographBasePath + "painting/0"; | ||
|
||
const micrographManifest = { | ||
"@context": "http://iiif.io/api/presentation/3/context.json", | ||
"id": micrographManifestId, | ||
"type": "Manifest", | ||
"label": { | ||
"en": [ | ||
manifestLabel | ||
] | ||
}, | ||
"summary": { | ||
"en": [ | ||
item[config.fieldMap.annotation.description] | ||
] | ||
}, | ||
"requiredStatement": { | ||
"label": { | ||
"en": [ | ||
"Collection" | ||
] | ||
}, | ||
"value": { | ||
"en": [ | ||
config.collection | ||
] | ||
} | ||
}, | ||
"rights": config.license, | ||
"items": [ | ||
{ | ||
"id": micrographCanvasId, | ||
"type": "Canvas", | ||
"height": micrographCanvasHeight, | ||
"width": micrographCanvasWidth, | ||
"items": [ | ||
{ | ||
"id": micrographAnnotationPageId, | ||
"type": "AnnotationPage", | ||
"items": [ | ||
{ | ||
"id": micrographAnnotationPaintingId, | ||
"type": "Annotation", | ||
"motivation": "painting", | ||
"body": { | ||
"type": "Choice", | ||
"items": [ | ||
{ | ||
"id": micrographImageId, | ||
"type": "Image", | ||
"format": micrographImageData.type, | ||
"height": micrographImageData.height, | ||
"width": micrographImageData.width, | ||
"label": { | ||
"en": [ | ||
item[config.fieldMap.annotation.description] | ||
] | ||
}, | ||
"service": [ | ||
{ | ||
"id": micrographImageAPIBase, | ||
"type": "ImageService3", | ||
"profile": "level2" | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
"target": micrographCanvasId | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
], | ||
} | ||
|
||
const outputFilePathMicrograph = path.join(config.outputDir, `${miniatureId}/micrograph/${item.id}/manifest.json`); | ||
const outputFilePath = path.join(config.outputDir, miniatureId.toString(), 'micrograph', item.id.toString()); | ||
try { | ||
await fsPromises.mkdir(outputFilePath, { recursive: true }); | ||
} | ||
catch (error) { | ||
|
||
} | ||
await fsPromises.writeFile(outputFilePathMicrograph, JSON.stringify(micrographManifest, null, " ")); | ||
} |