tweedegolf / storage-abstraction

Provides an abstraction layer for interacting with a storage; the storage can be local or in the cloud.
MIT License
106 stars 18 forks source link

fix(gcs): Fix accessing promise index instead of index' result #66

Closed CaporalDead closed 3 months ago

CaporalDead commented 3 months ago

Summary:

There is a priority problem between the promise/await and array access. Fix this by prioritizing the promise result over then array access. It was causing the following error :

/home/XXXXX/project/src/applications/business/XXXX.ts:5
import {useStorage} from "../../storage";
                                                         ^
Error: An error occurred while trying to generate a signed URL
    at /home/XXXXX/project/src/applications/business/XXXX.ts:114:15
    at Generator.next (<anonymous>)
    at fulfilled (/home/XXXXX/project/src/applications/business/XXXX.ts:5:58)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)

The code to reproduce

const storage = new Storage({
  type: StorageType.GCS,
  keyFilename: '/path/key.json',
  bucketName: 'my-bucket',
});

await storage.getFileAsURL(data.file.path, {
  useSignedUrl: true,
  expiresOn: Date.now() + 1000 * 60 * 60, // one hour
});

Tested on

Node 20.12.2 NPM 10.5.0