From b9590664b381e48523ddc607b9123e65d0b57f1a Mon Sep 17 00:00:00 2001 From: Martim Passos <49573683+martimpassos@users.noreply.github.com> Date: Tue, 3 Oct 2023 14:49:39 -0300 Subject: [PATCH] Make file ops synchronous, unlink vips xml #13 #9 #12 --- src/plugin.js | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/src/plugin.js b/src/plugin.js index 7399d34..2b99f21 100644 --- a/src/plugin.js +++ b/src/plugin.js @@ -2,7 +2,7 @@ const { IIIFBuilder } = require('iiif-builder'); const collectionBuilder = new IIIFBuilder(); -const { writeFile, copyFile } = require('fs/promises') +const { writeFile, copyFile } = require('fs') const { Resource } = require('./resource') const path = require('path'); const fs = require('fs'); @@ -52,9 +52,8 @@ class TropiiifyPlugin { // // ) } } - // Create collection from same source data and write file - const collectionPath = path.join(this.options.output, 'collection', 'collection.json') + const collectionPath = path.join(this.options.output, 'index.json') this.writeJson(collectionPath, this.createCollection(items)) //console.log('Collection:', await collection) } @@ -96,24 +95,23 @@ class TropiiifyPlugin { return null } - async createDirectory(path) { - if (!fs.existsSync(path)) { - await fs.mkdir(path, { recursive: true }, (err) => { - if (err) { - console.error(`Error creating directory: ${err}`); - } else { - console.log(`Directory "${path}" created successfully.`); - } - }); + createDirectory(path) { + try { + if (!fs.existsSync(path)) { + fs.mkdirSync(path, { recursive: true }); + console.log(`Directory "${path}" created successfully.`); + } + } catch (err) { + console.error(`Error creating directory: ${err}`); } } copyImages(item) { - item.photo.map(async (photo) => { - const dest = path.join(item.path, photo.checksum, 'full', 'max', '0', `default${path.extname(photo.path)}`) - await this.createDirectory(path.dirname(dest)) - await copyFile(photo.path, dest) - }) + item.photo.forEach((photo) => { + const dest = path.join(item.path, photo.checksum, 'full', 'max', '0', `default${path.extname(photo.path)}`); + this.createDirectory(path.dirname(dest)); + fs.copyFileSync(photo.path, dest); + }); } tileImages(item) { @@ -129,6 +127,13 @@ class TropiiifyPlugin { id: item.baseId }) .toFile(tilesPath) + fs.unlink(path.join(item.path,'vips-properties.xml'), (err) => { + if (err) { + console.error(`Error deleting file: ${err}`); + } else { + console.log(`Deleted vips-properties successfully.`); + } + }); }) } catch { this.context.logger.trace(`Failed image tile ${item.id}`) @@ -147,7 +152,6 @@ class TropiiifyPlugin { TropiiifyPlugin.defaults = { itemTemplate: 'Export IIIF 2', - photoTemplate: 'Tropy Photo', collectionName: 'My IIIF Collection', homepageLabel: 'Object homepage', requiredStatementLabel: 'Attribution',