@@ -5,7 +5,6 @@ import Layer from "../Layer/Layer.js"
55import dbDriver from "../../database/driver.js"
66import vault from "../../utilities/vault.js"
77import { imageSize } from 'image-size' ;
8- import fetch from 'node-fetch' ;
98
109const database = new dbDriver ( "mongo" )
1110
@@ -163,14 +162,21 @@ export default class ProjectFactory {
163162 try {
164163 const response = await fetch ( imgUrl )
165164 if ( ! response . ok ) {
166- throw new Error ( `Failed to fetch image: ${ response . status } ${ response . statusText } ` )
165+ throw {
166+ status : response . status ,
167+ message : `Failed to fetch image: ${ response . statusText } `
168+ }
167169 }
168- const buffer = await response . buffer ( )
170+ const arrayBuffer = await response . arrayBuffer ( )
171+ const buffer = Buffer . from ( arrayBuffer )
169172 const dimensions = imageSize ( buffer )
170- return { width : dimensions . width , height : dimensions . height }
171- } catch ( error ) {
172- console . error ( 'Error getting image dimensions:' , error )
173- return null
173+ return {
174+ width : dimensions . width ,
175+ height : dimensions . height
176+ }
177+ } catch ( err ) {
178+ console . error ( "Error fetching image dimensions:" , err . message )
179+ return
174180 }
175181 }
176182
@@ -214,45 +220,7 @@ export default class ProjectFactory {
214220 const label = projectLabel ?? now
215221 const dimensions = await this . getImageDimensions ( imageURL )
216222
217- const projectManifest = {
218- "@context" : "http://iiif.io/api/presentation/3/context.json" ,
219- id : `${ process . env . TPENSTATIC } /${ _id } /manifest.json` ,
220- type : "Manifest" ,
221- label : { "none" : [ label ] } ,
222- items : [
223- {
224- id : `${ process . env . TPENSTATIC } /${ _id } /canvas-1.json` ,
225- type : "Canvas" ,
226- label : { "none" : [ `${ label } Page 1` ] } ,
227- width : dimensions . width ,
228- height : dimensions . height ,
229- items : [
230- {
231- id : `${ process . env . TPENSTATIC } /${ _id } /contentPage.json` ,
232- type : "AnnotationPage" ,
233- items : [
234- {
235- id : `${ process . env . TPENSTATIC } /${ _id } /content.json` ,
236- type : "Annotation" ,
237- motivation : "painting" ,
238- body : {
239- id : imageURL ,
240- type : "Image" ,
241- format : `image/${ imageURL . split ( '.' ) . pop ( ) } ` ,
242- width : dimensions . width ,
243- height : dimensions . height
244- } ,
245- target : `${ process . env . TPENSTATIC } /${ _id } /canvas-1.json`
246- }
247- ]
248- }
249- ]
250- }
251- ]
252- }
253-
254- const projectCanvas = {
255- "@context" : "http://iiif.io/api/presentation/3/context.json" ,
223+ const canvasLayout = {
256224 id : `${ process . env . TPENSTATIC } /${ _id } /canvas-1.json` ,
257225 type : "Canvas" ,
258226 label : { "none" : [ `${ label } Page 1` ] } ,
@@ -281,6 +249,19 @@ export default class ProjectFactory {
281249 ]
282250 }
283251
252+ const projectManifest = {
253+ "@context" : "http://iiif.io/api/presentation/3/context.json" ,
254+ id : `${ process . env . TPENSTATIC } /${ _id } /manifest.json` ,
255+ type : "Manifest" ,
256+ label : { "none" : [ label ] } ,
257+ items : [ ...canvasLayout ]
258+ }
259+
260+ const projectCanvas = {
261+ "@context" : "http://iiif.io/api/presentation/3/context.json" ,
262+ ...canvasLayout
263+ }
264+
284265 await this . uploadFileToGitHub ( projectManifest , _id )
285266 await this . uploadFileToGitHub ( projectCanvas , _id )
286267
0 commit comments