@riocrypto/common-server 1.0.1233 → 1.0.1236

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.
@@ -51,7 +51,7 @@ class cloudVisionAPIClient {
51
51
  //@ts-ignore
52
52
  const [operation] = yield client.asyncBatchAnnotateFiles(request);
53
53
  const [filesResponse] = yield operation.promise();
54
- const destinationUri = filesResponse.responses[0].outputConfig.gcsDestination;
54
+ const destinationUri = filesResponse.responses[0].outputConfig.gcsDestination.uri;
55
55
  return destinationUri;
56
56
  });
57
57
  }
@@ -3,6 +3,6 @@ export declare class GCloudStorageClient {
3
3
  _bucket: Bucket;
4
4
  constructor(bucket: string);
5
5
  get bucket(): Bucket;
6
- downloadJsonFile(filename: string): Promise<any>;
6
+ downloadJsonFileFromGcsUri(gcsUri: string): Promise<any>;
7
7
  }
8
8
  export declare const buildGCloudStorageClient: () => Promise<GCloudStorageClient>;
@@ -22,12 +22,23 @@ class GCloudStorageClient {
22
22
  get bucket() {
23
23
  return this._bucket;
24
24
  }
25
- downloadJsonFile(filename) {
25
+ downloadJsonFileFromGcsUri(gcsUri) {
26
26
  return __awaiter(this, void 0, void 0, function* () {
27
- const file = this._bucket.file(filename);
27
+ const bucketName = gcsUri.split("/")[2];
28
+ const folderPath = gcsUri.split("/").slice(4).join("/"); // Extract the folder path from the URI
29
+ const storage = new storage_1.Storage({
30
+ keyFilename: "/etc/secrets/cloud-storage/cloud-storage-service-account-key.json",
31
+ });
32
+ const [files] = yield storage
33
+ .bucket(bucketName)
34
+ .getFiles({ prefix: folderPath });
35
+ if (files.length === 0) {
36
+ throw new Error("No files found in the specified folder");
37
+ }
38
+ const firstFile = files[0];
28
39
  return new Promise((resolve, reject) => {
29
40
  let data = "";
30
- file
41
+ firstFile
31
42
  .createReadStream()
32
43
  .on("data", (chunk) => {
33
44
  data += chunk.toString();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riocrypto/common-server",
3
- "version": "1.0.1233",
3
+ "version": "1.0.1236",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",