UNPKG

@adobe/pdftools-extract-node-sdk

Version:

The Document Services PDF Tools Extract Node.js SDK provides APIs for extracting elements and renditions from PDF

56 lines (47 loc) 2.12 kB
/* * Copyright 2019 Adobe * All Rights Reserved. * * NOTICE: Adobe permits you to use, modify, and distribute this file in * accordance with the terms of the Adobe license agreement accompanying * it. If you have received this file from a source other than Adobe, * then your use, modification, or distribution of it requires the prior * written permission of Adobe. */ const logger = require('./../logger'), CPFApi = require('./cpf-api'), CPFMessage = require('./../cpf/cpf-message'), OperationMessage = require('./../cpf/operation-message'), Engine = require('../cpf/request/engine.js'), ContentAnalyzerRequests = require('../cpf/request/content-analyzer-requests.js'); /** * Operation Service is an abstract class. All the document operation services need to inherit this class and have to * override getCPFMessage. CPFApi class is used for making the CPF Predict and Status API calls. */ class OperationService { constructor() { if (this.constructor === OperationService) { throw new TypeError("Can not construct OperationService class."); } } getCPFMessage(operationMessage) { throw new Error("Method 'getCPFMessage()' must be implemented."); } perform(context, operationMessage) { let cpfMessage = this.getCPFMessage(operationMessage), engine = new Engine(cpfMessage.inputDocuments, cpfMessage.params, cpfMessage.outputDocument), contentAnalyzerRequests = new ContentAnalyzerRequests(cpfMessage.cpfEngineConfig, engine), contentAnalyzerRequestsJsonString = JSON.stringify(contentAnalyzerRequests); let operation = operationMessage.operationName.replace(/\s/g, ''); return CPFApi.cpfPredictApi(context, cpfMessage.files, contentAnalyzerRequestsJsonString, operation) .then(location => { return CPFApi.cpfStatusApi(context, location, operationMessage.targetFileName);}) .then(targetFileRef => { targetFileRef.input.isOperationResult = true; logger.info(operationMessage.operationName + ' successfully completed'); return Promise.resolve(targetFileRef); }) .catch(res => Promise.reject(res)); } } module.exports = OperationService;