@genoacms/adapter-gcp 0.3.8-1 → 0.3.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -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-1",
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",
@@ -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 }) => {