@genoacms/adapter-gcp 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1 @@
|
|
1
|
+
"use strict";
|
@@ -0,0 +1 @@
|
|
1
|
+
"use strict";
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import { Storage } from '@google-cloud/storage';
|
2
|
+
import config from '@genoacms/cloudabstraction/src/config';
|
3
|
+
const storage = new Storage({
|
4
|
+
// @ts-expect-error: TODO: type this adapter
|
5
|
+
credentials: config.adapter.gcp.credentials
|
6
|
+
});
|
7
|
+
// @ts-expect-error: TODO: type this adapter
|
8
|
+
const bucket = storage.bucket(config.adapter.gcp.storage.bucket);
|
9
|
+
const listDirectory = async ({ limit, prefix }) => {
|
10
|
+
const [files] = await bucket.getFiles({
|
11
|
+
prefix,
|
12
|
+
maxResults: limit
|
13
|
+
});
|
14
|
+
return files.map((file) => {
|
15
|
+
return {
|
16
|
+
name: file.name,
|
17
|
+
size: file.metadata.size,
|
18
|
+
// @ts-expect-error: Handle this
|
19
|
+
lastModified: new Date(file.metadata.updated)
|
20
|
+
};
|
21
|
+
});
|
22
|
+
};
|
23
|
+
export { listDirectory };
|
package/package.json
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
{
|
2
|
+
"name": "@genoacms/adapter-gcp",
|
3
|
+
"version": "0.1.0",
|
4
|
+
"description": "Implementation of abstraction layer of GenoaCMS for GCP",
|
5
|
+
"main": "index.js",
|
6
|
+
"repository": {
|
7
|
+
"type": "git",
|
8
|
+
"url": "git+https://github.com/GenoaCMS/adapter-gcp.git"
|
9
|
+
},
|
10
|
+
"author": {
|
11
|
+
"name": "Filip Holčík",
|
12
|
+
"email": "filip.holcik.official@gmail.com"
|
13
|
+
},
|
14
|
+
"license": "ISC",
|
15
|
+
"bugs": {
|
16
|
+
"url": "https://github.com/GenoaCMS/adapter-gcp/issues"
|
17
|
+
},
|
18
|
+
"homepage": "https://github.com/GenoaCMS/adapter-gcp#readme",
|
19
|
+
"type": "module",
|
20
|
+
"dependencies": {
|
21
|
+
"@genoacms/cloudabstraction": "^0.1.7",
|
22
|
+
"@google-cloud/firestore": "^7.1.0",
|
23
|
+
"@google-cloud/storage": "^7.4.0"
|
24
|
+
},
|
25
|
+
"devDependencies": {
|
26
|
+
"@typescript-eslint/eslint-plugin": "^6.9.0",
|
27
|
+
"eslint": "^8.52.0",
|
28
|
+
"eslint-config-standard-with-typescript": "^39.1.1",
|
29
|
+
"eslint-plugin-import": "^2.29.0",
|
30
|
+
"eslint-plugin-n": "^16.2.0",
|
31
|
+
"eslint-plugin-promise": "^6.1.1",
|
32
|
+
"typescript": "^5.2.2"
|
33
|
+
},
|
34
|
+
"files": [
|
35
|
+
"src",
|
36
|
+
"dist"
|
37
|
+
],
|
38
|
+
"exports": {
|
39
|
+
"./auth": {
|
40
|
+
"import": "./dist/auth/index.js"
|
41
|
+
},
|
42
|
+
"./database": {
|
43
|
+
"import": "./dist/database/index.js"
|
44
|
+
},
|
45
|
+
"./storage": {
|
46
|
+
"import": "./dist/storage/index.js"
|
47
|
+
}
|
48
|
+
},
|
49
|
+
"scripts": {
|
50
|
+
"build": "tsc"
|
51
|
+
}
|
52
|
+
}
|
File without changes
|
File without changes
|
@@ -0,0 +1,32 @@
|
|
1
|
+
import type {
|
2
|
+
listDirectory as listDirectoryT,
|
3
|
+
StorageObject
|
4
|
+
} from '@genoacms/cloudabstraction/src/services/storage'
|
5
|
+
import { Storage } from '@google-cloud/storage'
|
6
|
+
import config from '@genoacms/cloudabstraction/src/config'
|
7
|
+
|
8
|
+
const storage = new Storage({
|
9
|
+
// @ts-expect-error: TODO: type this adapter
|
10
|
+
credentials: config.adapter.gcp.credentials
|
11
|
+
})
|
12
|
+
// @ts-expect-error: TODO: type this adapter
|
13
|
+
const bucket = storage.bucket(config.adapter.gcp.storage.bucket)
|
14
|
+
|
15
|
+
const listDirectory: listDirectoryT = async ({ limit, prefix }) => {
|
16
|
+
const [files] = await bucket.getFiles({
|
17
|
+
prefix,
|
18
|
+
maxResults: limit
|
19
|
+
})
|
20
|
+
return files.map((file) => {
|
21
|
+
return {
|
22
|
+
name: file.name,
|
23
|
+
size: file.metadata.size,
|
24
|
+
// @ts-expect-error: Handle this
|
25
|
+
lastModified: new Date(file.metadata.updated)
|
26
|
+
} as StorageObject
|
27
|
+
})
|
28
|
+
}
|
29
|
+
|
30
|
+
export {
|
31
|
+
listDirectory
|
32
|
+
}
|