ToolJet/marketplace/plugins/textract/lib/query_operations.ts

42 lines
994 B
TypeScript
Raw Normal View History

2023-04-19 15:42:57 +00:00
import { AnalyzeDocumentCommand, TextractClient } from '@aws-sdk/client-textract';
2023-04-21 10:05:51 +00:00
export const analyzeDocument = async (base64Data: string, featureTypes: string[], client: TextractClient) => {
2023-04-19 15:42:57 +00:00
const buffer = Buffer.from(JSON.stringify(base64Data), 'base64');
const params = {
Document: {
Bytes: new Uint8Array(buffer),
},
2023-04-21 10:05:51 +00:00
FeatureTypes: featureTypes.length > 0 ? featureTypes : ['TABLES'],
2023-04-19 15:42:57 +00:00
};
const command = new AnalyzeDocumentCommand(params);
const result = await client.send(command);
return result;
};
2023-04-21 10:05:51 +00:00
export const analyzeS3Document = async (
bucket: string,
fileName: string,
featureTypes: string[],
client: TextractClient
) => {
2023-04-19 15:42:57 +00:00
const params = {
Document: {
S3Object: {
Bucket: bucket,
Name: fileName,
},
},
2023-04-21 10:05:51 +00:00
FeatureTypes: featureTypes.length > 0 ? featureTypes : ['TABLES'],
2023-04-19 15:42:57 +00:00
};
const command = new AnalyzeDocumentCommand(params);
const result = await client.send(command);
return result;
};