Comparing version 0.1.3 to 0.1.4
{ | ||
"canvasAnnotationTypes": { | ||
".pdf": { | ||
"type": "PDF", | ||
"format": "application/pdf" | ||
}, | ||
".mp4": { | ||
"type": "Video", | ||
"format": "video/mp4" | ||
}, | ||
".jpg": { | ||
"type": "Image", | ||
"format": "image/jpeg" | ||
}, | ||
".obj": { | ||
".crt": { | ||
"type": "PhysicalObject", | ||
"format": "text/plain" | ||
"format": "application/corto" | ||
}, | ||
".ply": { | ||
".drc": { | ||
"type": "PhysicalObject", | ||
"format": "application/ply" | ||
"format": "application/draco" | ||
}, | ||
@@ -27,2 +15,6 @@ ".gltf": { | ||
}, | ||
".jpg": { | ||
"type": "Image", | ||
"format": "image/jpeg" | ||
}, | ||
".json": { | ||
@@ -32,11 +24,19 @@ "type": "PhysicalObject", | ||
}, | ||
".crt": { | ||
".mp4": { | ||
"type": "Video", | ||
"format": "video/mp4" | ||
}, | ||
".obj": { | ||
"type": "PhysicalObject", | ||
"format": "application/corto" | ||
"format": "text/plain" | ||
}, | ||
".drc": { | ||
".pdf": { | ||
"type": "PDF", | ||
"format": "application/pdf" | ||
}, | ||
".ply": { | ||
"type": "PhysicalObject", | ||
"format": "application/draco" | ||
"format": "application/ply" | ||
} | ||
} | ||
} |
@@ -96,2 +96,3 @@ "use strict"; | ||
memberJson.label = directory.infoYml.label; | ||
Utils_1.Utils.getThumbnail(memberJson, directory.url, directory.filePath); | ||
this.indexJson.members.push(memberJson); | ||
@@ -98,0 +99,0 @@ }); |
{ | ||
"name": "biiif", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"description": "A CLI to build IIIF collections", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
41
Utils.js
@@ -5,3 +5,2 @@ "use strict"; | ||
const thumbnailBoilerplate = require('./boilerplate/thumbnail'); | ||
const urljoin = require('url-join'); | ||
class Utils { | ||
@@ -32,10 +31,44 @@ static timeout(ms) { | ||
let thumbnail = thumbnails[0]; | ||
// get the part after and inclusive of the canvas | ||
thumbnail = thumbnail.substr(thumbnail.lastIndexOf('_')); | ||
const thumbnailJson = Utils.cloneJson(thumbnailBoilerplate); | ||
thumbnailJson[0].id = urljoin(url.href, thumbnail); | ||
thumbnailJson[0].id = Utils.mergePaths(url, thumbnail); | ||
json.thumbnail = thumbnailJson; | ||
} | ||
} | ||
/* | ||
merge these two example paths: | ||
url: http://test.com/collection/manifest | ||
filePath: c:/user/documents/collection/manifest/_canvas/thumb.png | ||
into: http://test.com/collection/manifest/_canvas/thumb.png | ||
*/ | ||
static mergePaths(url, filePath) { | ||
// split the url (minus origin) and filePath into arrays | ||
// ['collection', 'manifest'] | ||
// ['c:', 'user', 'documents', 'collection', 'manifest', '_canvas', 'thumb.jpg'] | ||
// walk backwards through the filePath array adding to the newPath array until the last item of the url array is found. | ||
// then while the next url item matches the next filePath item, add it to newPath. | ||
// the final path is the url origin plus a reversed newPath joined with a '/' | ||
const urlParts = url.href.replace(url.origin, '').split('/'); | ||
filePath = filePath.replace(/\\/g, '/'); | ||
const fileParts = filePath.split('/'); | ||
const newPath = []; | ||
for (let f = fileParts.length - 1; f >= 0; f--) { | ||
const filePart = fileParts[f]; | ||
newPath.push(filePart); | ||
if (filePart === urlParts[urlParts.length - 1]) { | ||
if (urlParts.length > 1) { | ||
for (let u = urlParts.length - 2; u >= 0; u--) { | ||
f--; | ||
if (fileParts[f] === urlParts[u]) { | ||
newPath.push(fileParts[f]); | ||
} | ||
} | ||
} | ||
break; | ||
} | ||
} | ||
let id = [url.origin, ...newPath.reverse()].join('/'); | ||
return id; | ||
} | ||
} | ||
exports.Utils = Utils; |
22294
440