From 2749ffab349f44fa3a38f6d58438412d5b7be135 Mon Sep 17 00:00:00 2001 From: Jordi Valls Date: Mon, 13 Jan 2020 16:02:39 +0100 Subject: [PATCH 1/2] [Images] Avoid adding images in UI or document json representation if Image Detection Module is off --- server/src/output/json/JsonExporter.ts | 4 ++++ .../processing/ImageDetectionModule/ImageDetectionModule.ts | 1 + server/src/types/DocumentRepresentation/Image.ts | 1 + 3 files changed, 6 insertions(+) diff --git a/server/src/output/json/JsonExporter.ts b/server/src/output/json/JsonExporter.ts index 4082d55e..59770757 100644 --- a/server/src/output/json/JsonExporter.ts +++ b/server/src/output/json/JsonExporter.ts @@ -256,6 +256,10 @@ export class JsonExporter extends Exporter { jsonElement.codeType = element.type; jsonElement.codeValue = element.content; } else if (element instanceof Image) { + if (!element.enabled) { + // Image.enabled = false if image detection module is not executed in pipe + return null; + } jsonElement.src = element.src; // TODO replace this with a location based on an API access point jsonElement.refId = element.refId; jsonElement.xObjId = element.xObjId; diff --git a/server/src/processing/ImageDetectionModule/ImageDetectionModule.ts b/server/src/processing/ImageDetectionModule/ImageDetectionModule.ts index 6eae438b..a1df5bb2 100644 --- a/server/src/processing/ImageDetectionModule/ImageDetectionModule.ts +++ b/server/src/processing/ImageDetectionModule/ImageDetectionModule.ts @@ -39,6 +39,7 @@ export class ImageDetectionModule extends Module { } const images = doc.getElementsOfType(Image, true); if (images.length > 0) { + images.forEach(img => (img.enabled = true)); const assets: string[] = fs.readdirSync(doc.assetsFolder); const dumpPdf = await this.getFileMetadata(doc.inputFile); this.linkXObjectToImages(images, dumpPdf); diff --git a/server/src/types/DocumentRepresentation/Image.ts b/server/src/types/DocumentRepresentation/Image.ts index d0b20c44..8ab9abd0 100644 --- a/server/src/types/DocumentRepresentation/Image.ts +++ b/server/src/types/DocumentRepresentation/Image.ts @@ -87,6 +87,7 @@ export class Image extends Element { } public content: null = null; + public enabled: boolean = false; private _src: string; private _refId: string; private _xObjId: string; From 59690f536f0e73b1a05626e7a14f3861155fa993 Mon Sep 17 00:00:00 2001 From: Jordi Valls Date: Mon, 13 Jan 2020 16:13:27 +0100 Subject: [PATCH 2/2] [Images] Commented line --- server/src/output/json/JsonExporter.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/output/json/JsonExporter.ts b/server/src/output/json/JsonExporter.ts index 59770757..fdc27345 100644 --- a/server/src/output/json/JsonExporter.ts +++ b/server/src/output/json/JsonExporter.ts @@ -257,7 +257,7 @@ export class JsonExporter extends Exporter { jsonElement.codeValue = element.content; } else if (element instanceof Image) { if (!element.enabled) { - // Image.enabled = false if image detection module is not executed in pipe + // If image detection module is not executed in pipe all images have enabled = false return null; } jsonElement.src = element.src; // TODO replace this with a location based on an API access point