@genoacms/adapter-gcp 0.7.1-fix.1 → 0.7.1-fix.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,13 +1,18 @@
1
1
  import config from '../../config.js';
2
2
  import { Storage } from '@google-cloud/storage';
3
- const storageConfig = config.storage.providers.find((provider) => provider.name === 'gcs');
3
+ const PROVIDER_NAME = '@genoacms/adapter-gcp/storage';
4
+ const storageConfig = config.storage.providers.find((provider) => provider.name === PROVIDER_NAME);
4
5
  if (!storageConfig)
5
6
  throw new Error('storage-provider-not-found');
6
7
  const storage = new Storage({
7
8
  credentials: config.storage.credentials
8
9
  });
10
+ const hasBucket = (name) => {
11
+ const has = config.storage.buckets.find((bucket) => bucket.name === name && bucket.providerName === PROVIDER_NAME);
12
+ return !!has;
13
+ };
9
14
  const getBucket = (name) => {
10
- if (!config.storage.buckets.includes(name))
15
+ if (!hasBucket(name))
11
16
  throw new Error('bucket-unregistered');
12
17
  const bucket = storage.bucket(name);
13
18
  return bucket;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@genoacms/adapter-gcp",
3
- "version": "0.7.1-fix.1",
3
+ "version": "0.7.1-fix.2",
4
4
  "type": "module",
5
5
  "description": "Implementation of abstraction layer of GenoaCMS for GCP",
6
6
  "repository": {
@@ -1,15 +1,21 @@
1
1
  import config from '../../config.js'
2
2
  import { type Bucket, Storage } from '@google-cloud/storage'
3
- import type { StorageProvider } from '@genoacms/cloudabstraction/storage'
3
+ import type { StorageProvider, BucketInit } from '@genoacms/cloudabstraction/storage'
4
4
 
5
- const storageConfig = config.storage.providers.find((provider: StorageProvider) => provider.name === 'gcs')
5
+ const PROVIDER_NAME = '@genoacms/adapter-gcp/storage'
6
+ const storageConfig = config.storage.providers.find((provider: StorageProvider) => provider.name === PROVIDER_NAME)
6
7
  if (!storageConfig) throw new Error('storage-provider-not-found')
7
8
  const storage = new Storage({
8
9
  credentials: config.storage.credentials
9
10
  })
10
11
 
12
+ const hasBucket = (name: string): boolean => {
13
+ const has = config.storage.buckets.find((bucket: BucketInit) => bucket.name === name && bucket.providerName === PROVIDER_NAME)
14
+ return !!has
15
+ }
16
+
11
17
  const getBucket = (name: string): Bucket => {
12
- if (!config.storage.buckets.includes(name)) throw new Error('bucket-unregistered')
18
+ if (!hasBucket(name)) throw new Error('bucket-unregistered')
13
19
  const bucket = storage.bucket(name)
14
20
  return bucket
15
21
  }