@riocrypto/common-server 1.0.1230 → 1.0.1233
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/clients/cloud-vision-api-client.d.ts +9 -0
- package/build/clients/cloud-vision-api-client.js +59 -0
- package/build/clients/gcloud-storage-client.d.ts +1 -0
- package/build/clients/gcloud-storage-client.js +25 -0
- package/build/index.d.ts +1 -0
- package/build/index.js +1 -0
- package/package.json +2 -1
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { RioEnv } from "@riocrypto/common";
|
|
2
|
+
declare class cloudVisionAPIClient {
|
|
3
|
+
private env;
|
|
4
|
+
googleAuth: any;
|
|
5
|
+
constructor(env: RioEnv);
|
|
6
|
+
getDataFromPDF(bucketName: string, fileName: string, outputPrefix: string): Promise<any>;
|
|
7
|
+
}
|
|
8
|
+
export declare const googleVisionAPIClient: cloudVisionAPIClient;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.googleVisionAPIClient = void 0;
|
|
13
|
+
const googleapis_1 = require("googleapis");
|
|
14
|
+
const vision_1 = require("@google-cloud/vision");
|
|
15
|
+
class cloudVisionAPIClient {
|
|
16
|
+
constructor(env) {
|
|
17
|
+
this.env = env;
|
|
18
|
+
this.googleAuth = new googleapis_1.google.auth.GoogleAuth({
|
|
19
|
+
keyFile: "/etc/secrets/cloud-vision/cloud-vision-service-account-key.json",
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
getDataFromPDF(bucketName, fileName, outputPrefix) {
|
|
23
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
const client = new vision_1.v1.ImageAnnotatorClient({
|
|
25
|
+
auth: this.googleAuth,
|
|
26
|
+
});
|
|
27
|
+
const gcsSourceUri = `gs://${bucketName}/${fileName}`;
|
|
28
|
+
const gcsDestinationUri = `gs://${bucketName}/${outputPrefix}/`;
|
|
29
|
+
const inputConfig = {
|
|
30
|
+
// Supported mime_types are: 'application/pdf' and 'image/tiff'
|
|
31
|
+
mimeType: "application/pdf",
|
|
32
|
+
gcsSource: {
|
|
33
|
+
uri: gcsSourceUri,
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
const outputConfig = {
|
|
37
|
+
gcsDestination: {
|
|
38
|
+
uri: gcsDestinationUri,
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
const features = [{ type: "DOCUMENT_TEXT_DETECTION" }];
|
|
42
|
+
const request = {
|
|
43
|
+
requests: [
|
|
44
|
+
{
|
|
45
|
+
inputConfig: inputConfig,
|
|
46
|
+
features: features,
|
|
47
|
+
outputConfig: outputConfig,
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
};
|
|
51
|
+
//@ts-ignore
|
|
52
|
+
const [operation] = yield client.asyncBatchAnnotateFiles(request);
|
|
53
|
+
const [filesResponse] = yield operation.promise();
|
|
54
|
+
const destinationUri = filesResponse.responses[0].outputConfig.gcsDestination;
|
|
55
|
+
return destinationUri;
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.googleVisionAPIClient = new cloudVisionAPIClient(process.env.RIO_ENV || process.env.NEXT_PUBLIC_RIO_ENV);
|
|
@@ -22,6 +22,31 @@ class GCloudStorageClient {
|
|
|
22
22
|
get bucket() {
|
|
23
23
|
return this._bucket;
|
|
24
24
|
}
|
|
25
|
+
downloadJsonFile(filename) {
|
|
26
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
const file = this._bucket.file(filename);
|
|
28
|
+
return new Promise((resolve, reject) => {
|
|
29
|
+
let data = "";
|
|
30
|
+
file
|
|
31
|
+
.createReadStream()
|
|
32
|
+
.on("data", (chunk) => {
|
|
33
|
+
data += chunk.toString();
|
|
34
|
+
})
|
|
35
|
+
.on("end", () => {
|
|
36
|
+
try {
|
|
37
|
+
const jsonData = JSON.parse(data);
|
|
38
|
+
resolve(jsonData);
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
reject(new Error(`Error parsing JSON file: ${error}`));
|
|
42
|
+
}
|
|
43
|
+
})
|
|
44
|
+
.on("error", (err) => {
|
|
45
|
+
reject(new Error(`Error reading file: ${err.message}`));
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
}
|
|
25
50
|
}
|
|
26
51
|
exports.GCloudStorageClient = GCloudStorageClient;
|
|
27
52
|
const buildGCloudStorageClient = () => __awaiter(void 0, void 0, void 0, function* () {
|
package/build/index.d.ts
CHANGED
|
@@ -50,6 +50,7 @@ export * from "./clients/kapstar-client";
|
|
|
50
50
|
export * from "./clients/etherscan-client";
|
|
51
51
|
export * from "./clients/secret-manager-client";
|
|
52
52
|
export * from "./clients/gcloud-storage-client";
|
|
53
|
+
export * from "./clients/cloud-vision-api-client";
|
|
53
54
|
export * from "./clients/currency-api-client";
|
|
54
55
|
export * from "./clients/aiprise-client";
|
|
55
56
|
export * from "./clients/bridge-client";
|
package/build/index.js
CHANGED
|
@@ -66,6 +66,7 @@ __exportStar(require("./clients/kapstar-client"), exports);
|
|
|
66
66
|
__exportStar(require("./clients/etherscan-client"), exports);
|
|
67
67
|
__exportStar(require("./clients/secret-manager-client"), exports);
|
|
68
68
|
__exportStar(require("./clients/gcloud-storage-client"), exports);
|
|
69
|
+
__exportStar(require("./clients/cloud-vision-api-client"), exports);
|
|
69
70
|
__exportStar(require("./clients/currency-api-client"), exports);
|
|
70
71
|
__exportStar(require("./clients/aiprise-client"), exports);
|
|
71
72
|
__exportStar(require("./clients/bridge-client"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@riocrypto/common-server",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1233",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./build/index.js",
|
|
6
6
|
"types": "./build/index.d.ts",
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
"@aws-sdk/client-s3": "^3.297.0",
|
|
27
27
|
"@everapi/currencyapi-js": "^1.0.6",
|
|
28
28
|
"@google-cloud/storage": "^6.9.5",
|
|
29
|
+
"@google-cloud/vision": "^4.0.2",
|
|
29
30
|
"@riocrypto/common": "^1.0.1123",
|
|
30
31
|
"@types/express": "^4.17.13",
|
|
31
32
|
"axios": "^0.27.2",
|