@genoacms/adapter-gcp 0.3.8 → 0.3.9

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.
@@ -28,18 +28,25 @@ const deleteObject = async ({ bucket, name }) => {
28
28
  };
29
29
  const listDirectory = async ({ bucket, name }, listingParams = {}) => {
30
30
  const bucketInstance = getBucket(bucket);
31
- const [files] = await bucketInstance.getFiles({
31
+ const options = {
32
+ autoPaginate: false,
32
33
  prefix: name,
33
34
  maxResults: listingParams?.limit,
34
- startOffset: listingParams?.startAfter
35
- });
36
- return files.map((file) => {
37
- return {
38
- name: file.name,
39
- size: file.metadata.size ? parseInt(file.metadata.size) : 0,
40
- lastModified: new Date(file.metadata.updated)
41
- };
42
- });
35
+ startOffset: listingParams?.startAfter,
36
+ delimiter: '/'
37
+ };
38
+ const [files, , apiResponse] = (await bucketInstance.getFiles(options));
39
+ return {
40
+ files: files.map((file) => {
41
+ return {
42
+ name: file.name,
43
+ // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
44
+ size: file.metadata.size ? parseInt(file.metadata.size) : 0,
45
+ lastModified: new Date(file.metadata.updated)
46
+ };
47
+ }),
48
+ directories: apiResponse?.prefixes ?? []
49
+ };
43
50
  };
44
51
  const createDirectory = async ({ bucket, name }) => {
45
52
  const bucketInstance = getBucket(bucket);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@genoacms/adapter-gcp",
3
- "version": "0.3.8",
3
+ "version": "0.3.9",
4
4
  "description": "Implementation of abstraction layer of GenoaCMS for GCP",
5
5
  "repository": {
6
6
  "type": "git",
@@ -17,9 +17,9 @@
17
17
  "homepage": "https://github.com/GenoaCMS/adapter-gcp#readme",
18
18
  "type": "module",
19
19
  "dependencies": {
20
- "@genoacms/cloudabstraction": "^0.3.8",
20
+ "@genoacms/cloudabstraction": "^0.3.9",
21
21
  "@google-cloud/firestore": "^7.1.0",
22
- "@google-cloud/storage": "^7.4.0"
22
+ "@google-cloud/storage": "^7.7.0"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@typescript-eslint/eslint-plugin": "^6.9.0",
@@ -38,16 +38,16 @@
38
38
  ],
39
39
  "exports": {
40
40
  "./auth": {
41
- "import": "./dist/auth/index.js",
42
- "types": "./dist/auth/index.d.ts"
41
+ "import": "./dist/services/auth/index.js",
42
+ "types": "./dist/services/auth/index.d.ts"
43
43
  },
44
44
  "./database": {
45
- "import": "./dist/database/index.js",
46
- "types": "./dist/database/index.d.ts"
45
+ "import": "./dist/services/database/index.js",
46
+ "types": "./dist/services/database/index.d.ts"
47
47
  },
48
48
  "./storage": {
49
- "import": "./dist/storage/index.js",
50
- "types": "./dist/storage/index.d.ts"
49
+ "import": "./dist/services/storage/index.js",
50
+ "types": "./dist/services/storage/index.d.ts"
51
51
  }
52
52
  },
53
53
  "scripts": {
@@ -1,7 +1,7 @@
1
1
  import type {
2
2
  storage as storageT
3
3
  } from '@genoacms/cloudabstraction'
4
- import { type Bucket, Storage } from '@google-cloud/storage'
4
+ import { type Bucket, Storage, type File } from '@google-cloud/storage'
5
5
  import config from '../../config.js'
6
6
 
7
7
  const storage = new Storage({
@@ -37,18 +37,26 @@ const deleteObject: storageT.deleteObject = async ({ bucket, name }) => {
37
37
 
38
38
  const listDirectory: storageT.listDirectory = async ({ bucket, name }, listingParams = {}) => {
39
39
  const bucketInstance = getBucket(bucket)
40
- const [files] = await bucketInstance.getFiles({
40
+ const options = {
41
+ autoPaginate: false,
41
42
  prefix: name,
42
43
  maxResults: listingParams?.limit,
43
- startOffset: listingParams?.startAfter
44
- })
45
- return files.map((file) => {
46
- return {
47
- name: file.name,
48
- size: file.metadata.size ? parseInt(file.metadata.size as string) : 0,
49
- lastModified: new Date(file.metadata.updated as string)
50
- } satisfies storageT.StorageObject
51
- })
44
+ startOffset: listingParams?.startAfter,
45
+ delimiter: '/'
46
+ }
47
+ const [files, , apiResponse] =
48
+ (await bucketInstance.getFiles(options)) as [File[], object, { prefixes: string[] } | undefined ]
49
+ return {
50
+ files: files.map((file) => {
51
+ return {
52
+ name: file.name,
53
+ // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
54
+ size: file.metadata.size ? parseInt(file.metadata.size as string) : 0,
55
+ lastModified: new Date(file.metadata.updated as string)
56
+ } satisfies storageT.StorageObject
57
+ }),
58
+ directories: apiResponse?.prefixes ?? []
59
+ }
52
60
  }
53
61
 
54
62
  const createDirectory: storageT.createDirectory = async ({ bucket, name }) => {