@riocrypto/common-server 1.0.1231 → 1.0.1235

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.
@@ -3,7 +3,7 @@ declare class cloudVisionAPIClient {
3
3
  private env;
4
4
  googleAuth: any;
5
5
  constructor(env: RioEnv);
6
- getDataFromPDF(bucketName: string, fileName: string, outputPrefix: string): Promise<void>;
6
+ getDataFromPDF(bucketName: string, fileName: string, outputPrefix: string): Promise<any>;
7
7
  }
8
8
  export declare const googleVisionAPIClient: cloudVisionAPIClient;
9
9
  export {};
@@ -52,7 +52,7 @@ class cloudVisionAPIClient {
52
52
  const [operation] = yield client.asyncBatchAnnotateFiles(request);
53
53
  const [filesResponse] = yield operation.promise();
54
54
  const destinationUri = filesResponse.responses[0].outputConfig.gcsDestination.uri;
55
- console.log("Json saved to: " + destinationUri);
55
+ return destinationUri;
56
56
  });
57
57
  }
58
58
  }
@@ -3,5 +3,6 @@ export declare class GCloudStorageClient {
3
3
  _bucket: Bucket;
4
4
  constructor(bucket: string);
5
5
  get bucket(): Bucket;
6
+ downloadJsonFileFromFolder(folderPath: string): Promise<any>;
6
7
  }
7
8
  export declare const buildGCloudStorageClient: () => Promise<GCloudStorageClient>;
@@ -22,6 +22,35 @@ class GCloudStorageClient {
22
22
  get bucket() {
23
23
  return this._bucket;
24
24
  }
25
+ downloadJsonFileFromFolder(folderPath) {
26
+ return __awaiter(this, void 0, void 0, function* () {
27
+ const [files] = yield this._bucket.getFiles({ prefix: folderPath });
28
+ if (files.length === 0) {
29
+ throw new Error("No files found in the specified folder");
30
+ }
31
+ const firstFile = files[0];
32
+ return new Promise((resolve, reject) => {
33
+ let data = "";
34
+ firstFile
35
+ .createReadStream()
36
+ .on("data", (chunk) => {
37
+ data += chunk.toString();
38
+ })
39
+ .on("end", () => {
40
+ try {
41
+ const jsonData = JSON.parse(data);
42
+ resolve(jsonData);
43
+ }
44
+ catch (error) {
45
+ reject(new Error(`Error parsing JSON file: ${error}`));
46
+ }
47
+ })
48
+ .on("error", (err) => {
49
+ reject(new Error(`Error reading file: ${err.message}`));
50
+ });
51
+ });
52
+ });
53
+ }
25
54
  }
26
55
  exports.GCloudStorageClient = GCloudStorageClient;
27
56
  const buildGCloudStorageClient = () => __awaiter(void 0, void 0, void 0, function* () {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riocrypto/common-server",
3
- "version": "1.0.1231",
3
+ "version": "1.0.1235",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",