@genoacms/adapter-gcp 0.4.1 → 0.5.2-fix.1
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.
- package/dist/config.d.ts +1 -1
- package/dist/services/authorization/index.d.ts +2 -2
- package/dist/services/authorization/index.js +1 -1
- package/dist/services/database/index.d.ts +6 -6
- package/dist/services/database/index.js +1 -1
- package/dist/services/deployment/deploy.d.ts +1 -0
- package/dist/services/deployment/deploy.js +67 -0
- package/dist/services/deployment/index.d.ts +4 -0
- package/dist/services/deployment/index.js +6 -0
- package/dist/services/storage/index.d.ts +7 -7
- package/dist/services/storage/index.js +3 -13
- package/dist/services/storage/storage.d.ts +3 -0
- package/dist/services/storage/storage.js +12 -0
- package/package.json +14 -5
- package/src/genoa.config.d.ts +1 -1
- package/src/services/authorization/index.ts +3 -3
- package/src/services/database/index.ts +23 -16
- package/src/services/deployment/cloudFunction.js +8 -0
- package/src/services/deployment/deploy.ts +74 -0
- package/src/services/deployment/index.ts +13 -0
- package/src/services/storage/index.ts +12 -22
- package/src/services/storage/storage.ts +16 -0
package/dist/config.d.ts
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
declare const _default:
|
1
|
+
declare const _default: any;
|
2
2
|
export default _default;
|
@@ -1,3 +1,3 @@
|
|
1
|
-
import type {
|
2
|
-
declare const isEmailAdmins:
|
1
|
+
import type { Adapter } from '@genoacms/cloudabstraction/authorization';
|
2
|
+
declare const isEmailAdmins: Adapter.isEmailAdmins;
|
3
3
|
export { isEmailAdmins };
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import { ProjectsClient } from '@google-cloud/resource-manager';
|
2
1
|
import config from '../../config.js';
|
2
|
+
import { ProjectsClient } from '@google-cloud/resource-manager';
|
3
3
|
const resourceManager = new ProjectsClient({
|
4
4
|
projectId: config.authorization.projectId,
|
5
5
|
credentials: config.authorization.credentials
|
@@ -1,7 +1,7 @@
|
|
1
|
-
import type {
|
2
|
-
declare const createDocument:
|
3
|
-
declare const getCollection:
|
4
|
-
declare const getDocument:
|
5
|
-
declare const updateDocument:
|
6
|
-
declare const deleteDocument:
|
1
|
+
import type { Adapter } from '@genoacms/cloudabstraction/database';
|
2
|
+
declare const createDocument: Adapter.createDocument;
|
3
|
+
declare const getCollection: Adapter.getCollection;
|
4
|
+
declare const getDocument: Adapter.getDocument;
|
5
|
+
declare const updateDocument: Adapter.updateDocument;
|
6
|
+
declare const deleteDocument: Adapter.deleteDocument;
|
7
7
|
export { createDocument, getDocument, getCollection, updateDocument, deleteDocument };
|
@@ -0,0 +1 @@
|
|
1
|
+
export default function (): Promise<void>;
|
@@ -0,0 +1,67 @@
|
|
1
|
+
import config from '../../config.js';
|
2
|
+
import { getBucket } from '../storage/storage.js';
|
3
|
+
import { readdir, lstat } from 'node:fs/promises';
|
4
|
+
import { createReadStream } from 'node:fs';
|
5
|
+
import { join } from 'node:path';
|
6
|
+
import { CloudFunctionsServiceClient } from '@google-cloud/functions';
|
7
|
+
const functionsClient = new CloudFunctionsServiceClient({
|
8
|
+
credentials: config.deployment.credentials
|
9
|
+
});
|
10
|
+
const projectId = config.deployment.projectId;
|
11
|
+
const region = config.deployment.region;
|
12
|
+
async function uploadDirectory(bucketName, directoryPath, prefix = '') {
|
13
|
+
const bucket = getBucket(bucketName);
|
14
|
+
const files = await readdir(directoryPath);
|
15
|
+
for (const file of files) {
|
16
|
+
const filePath = join(directoryPath, file);
|
17
|
+
const destination = join(prefix, file);
|
18
|
+
const isFileDirectory = (await lstat(filePath)).isDirectory();
|
19
|
+
if (isFileDirectory) {
|
20
|
+
await uploadDirectory(bucketName, filePath, destination);
|
21
|
+
}
|
22
|
+
else {
|
23
|
+
const fileStream = createReadStream(filePath);
|
24
|
+
const gcsFile = bucket.file(destination);
|
25
|
+
await new Promise((resolve, reject) => {
|
26
|
+
fileStream
|
27
|
+
.pipe(gcsFile.createWriteStream())
|
28
|
+
.on('error', reject)
|
29
|
+
.on('finish', resolve);
|
30
|
+
});
|
31
|
+
}
|
32
|
+
}
|
33
|
+
}
|
34
|
+
async function uploadSourceCode(bucketName, source, dest) {
|
35
|
+
const bucket = getBucket(bucketName);
|
36
|
+
const uploadResponse = await bucket.upload(source, {
|
37
|
+
gzip: true,
|
38
|
+
destination: dest
|
39
|
+
});
|
40
|
+
const file = uploadResponse[0];
|
41
|
+
return file.cloudStorageURI.toString();
|
42
|
+
}
|
43
|
+
async function deployFunction(name, source) {
|
44
|
+
const location = functionsClient.locationPath(projectId, region);
|
45
|
+
const [response] = await functionsClient.createFunction({
|
46
|
+
location,
|
47
|
+
function: {
|
48
|
+
name,
|
49
|
+
sourceUploadUrl: source,
|
50
|
+
entryPoint: 'handler',
|
51
|
+
runtime: 'nodejs20',
|
52
|
+
httpsTrigger: {},
|
53
|
+
environmentVariables: {
|
54
|
+
NODE_ENV: 'production'
|
55
|
+
}
|
56
|
+
}
|
57
|
+
}, {});
|
58
|
+
console.log(response);
|
59
|
+
}
|
60
|
+
export default async function () {
|
61
|
+
const bucketName = config.storage.defaultBucket;
|
62
|
+
const assetsPath = '.genoacms/deployment/static';
|
63
|
+
const buildArchivePath = '.genoacms/deployment/build.zip';
|
64
|
+
await uploadDirectory(bucketName, './static', assetsPath);
|
65
|
+
const buildArchiveURI = await uploadSourceCode(bucketName, './build', buildArchivePath);
|
66
|
+
await deployFunction('genoacms', buildArchiveURI);
|
67
|
+
}
|
@@ -1,9 +1,9 @@
|
|
1
1
|
import type { Adapter } from '@genoacms/cloudabstraction/storage';
|
2
|
-
declare const getObject: Adapter
|
3
|
-
declare const getPublicURL: Adapter
|
4
|
-
declare const getSignedURL: Adapter
|
5
|
-
declare const uploadObject: Adapter
|
6
|
-
declare const deleteObject: Adapter
|
7
|
-
declare const listDirectory: Adapter
|
8
|
-
declare const createDirectory: Adapter
|
2
|
+
declare const getObject: Adapter.getObject;
|
3
|
+
declare const getPublicURL: Adapter.getPublicURL;
|
4
|
+
declare const getSignedURL: Adapter.getSignedURL;
|
5
|
+
declare const uploadObject: Adapter.uploadObject;
|
6
|
+
declare const deleteObject: Adapter.deleteObject;
|
7
|
+
declare const listDirectory: Adapter.listDirectory;
|
8
|
+
declare const createDirectory: Adapter.createDirectory;
|
9
9
|
export { getObject, getPublicURL, getSignedURL, uploadObject, deleteObject, listDirectory, createDirectory };
|
@@ -1,14 +1,4 @@
|
|
1
|
-
import {
|
2
|
-
import config from '../../config.js';
|
3
|
-
const storage = new Storage({
|
4
|
-
credentials: config.storage.credentials
|
5
|
-
});
|
6
|
-
const getBucket = (name) => {
|
7
|
-
if (!config.storage.buckets.includes(name))
|
8
|
-
throw new Error('bucket-unregistered');
|
9
|
-
const bucket = storage.bucket(name);
|
10
|
-
return bucket;
|
11
|
-
};
|
1
|
+
import { getBucket } from './storage.js';
|
12
2
|
const getObject = async ({ bucket, name }) => {
|
13
3
|
const bucketInstance = getBucket(bucket);
|
14
4
|
const file = bucketInstance.file(name);
|
@@ -32,10 +22,10 @@ const getSignedURL = async ({ bucket, name }) => {
|
|
32
22
|
});
|
33
23
|
return url;
|
34
24
|
};
|
35
|
-
const uploadObject = async ({ bucket, name }, stream) => {
|
25
|
+
const uploadObject = async ({ bucket, name }, stream, options) => {
|
36
26
|
const bucketInstance = getBucket(bucket);
|
37
27
|
const file = bucketInstance.file(name);
|
38
|
-
await file.save(stream);
|
28
|
+
await file.save(stream, options);
|
39
29
|
};
|
40
30
|
const deleteObject = async ({ bucket, name }) => {
|
41
31
|
const bucketInstance = getBucket(bucket);
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import config from '../../config.js';
|
2
|
+
import { Storage } from '@google-cloud/storage';
|
3
|
+
const storage = new Storage({
|
4
|
+
credentials: config.storage.credentials
|
5
|
+
});
|
6
|
+
const getBucket = (name) => {
|
7
|
+
if (!config.storage.buckets.includes(name))
|
8
|
+
throw new Error('bucket-unregistered');
|
9
|
+
const bucket = storage.bucket(name);
|
10
|
+
return bucket;
|
11
|
+
};
|
12
|
+
export { getBucket };
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@genoacms/adapter-gcp",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.5.2-fix.1",
|
4
4
|
"description": "Implementation of abstraction layer of GenoaCMS for GCP",
|
5
5
|
"repository": {
|
6
6
|
"type": "git",
|
@@ -17,8 +17,9 @@
|
|
17
17
|
"homepage": "https://github.com/GenoaCMS/adapter-gcp#readme",
|
18
18
|
"type": "module",
|
19
19
|
"dependencies": {
|
20
|
-
"@genoacms/cloudabstraction": "^0.
|
20
|
+
"@genoacms/cloudabstraction": "^0.5.2",
|
21
21
|
"@google-cloud/firestore": "^7.1.0",
|
22
|
+
"@google-cloud/functions": "^3.2.0",
|
22
23
|
"@google-cloud/resource-manager": "^5.1.0",
|
23
24
|
"@google-cloud/storage": "^7.7.0"
|
24
25
|
},
|
@@ -33,19 +34,27 @@
|
|
33
34
|
"typescript": "^5.2.2",
|
34
35
|
"vitest": "^1.0.4"
|
35
36
|
},
|
37
|
+
"peerDependencies": {
|
38
|
+
"@sveltejs/adapter-node": "^4.0.1",
|
39
|
+
"@google-cloud/functions-framework": "^3.3.0"
|
40
|
+
},
|
36
41
|
"files": [
|
37
42
|
"src",
|
38
43
|
"dist"
|
39
44
|
],
|
40
45
|
"exports": {
|
41
|
-
"./
|
42
|
-
"import": "./dist/services/
|
43
|
-
"types": "./dist/services/
|
46
|
+
"./authorization": {
|
47
|
+
"import": "./dist/services/authorization/index.js",
|
48
|
+
"types": "./dist/services/authorization/index.d.ts"
|
44
49
|
},
|
45
50
|
"./database": {
|
46
51
|
"import": "./dist/services/database/index.js",
|
47
52
|
"types": "./dist/services/database/index.d.ts"
|
48
53
|
},
|
54
|
+
"./deployment": {
|
55
|
+
"import": "./dist/services/deployment/index.js",
|
56
|
+
"types": "./dist/services/deployment/index.d.ts"
|
57
|
+
},
|
49
58
|
"./storage": {
|
50
59
|
"import": "./dist/services/storage/index.js",
|
51
60
|
"types": "./dist/services/storage/index.d.ts"
|
package/src/genoa.config.d.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
import {
|
1
|
+
import type { Adapter } from '@genoacms/cloudabstraction/authorization'
|
2
2
|
import config from '../../config.js'
|
3
|
-
import
|
3
|
+
import { ProjectsClient } from '@google-cloud/resource-manager'
|
4
4
|
|
5
5
|
const resourceManager = new ProjectsClient({
|
6
6
|
projectId: config.authorization.projectId,
|
@@ -8,7 +8,7 @@ const resourceManager = new ProjectsClient({
|
|
8
8
|
})
|
9
9
|
const projectId = config.authorization.projectId
|
10
10
|
|
11
|
-
const isEmailAdmins:
|
11
|
+
const isEmailAdmins: Adapter.isEmailAdmins = async (email: string) => {
|
12
12
|
const resource = `projects/${projectId}`
|
13
13
|
const role = resource + '/roles/genoacms'
|
14
14
|
const data = await resourceManager.getIamPolicy({ resource })
|
@@ -1,6 +1,13 @@
|
|
1
|
-
import {
|
1
|
+
import type {
|
2
|
+
Adapter,
|
3
|
+
CollectionSnapshot,
|
4
|
+
Document,
|
5
|
+
DocumentReference,
|
6
|
+
DocumentSnapshot,
|
7
|
+
UpdateSnapshot
|
8
|
+
} from '@genoacms/cloudabstraction/database'
|
2
9
|
import config from '../../config.js'
|
3
|
-
import
|
10
|
+
import { Firestore } from '@google-cloud/firestore'
|
4
11
|
|
5
12
|
const firestore = new Firestore({
|
6
13
|
credentials: config.database.credentials,
|
@@ -8,24 +15,24 @@ const firestore = new Firestore({
|
|
8
15
|
projectId: config.database.projectId
|
9
16
|
})
|
10
17
|
|
11
|
-
const createDocument:
|
18
|
+
const createDocument: Adapter.createDocument = async (reference, data) => {
|
12
19
|
const document = await firestore.collection(reference.name).add(data)
|
13
|
-
const documentReference:
|
20
|
+
const documentReference: DocumentReference<typeof reference> = {
|
14
21
|
collection: reference,
|
15
22
|
id: document.id
|
16
23
|
}
|
17
24
|
return {
|
18
25
|
reference: documentReference,
|
19
26
|
data
|
20
|
-
} satisfies
|
27
|
+
} satisfies DocumentSnapshot<typeof reference>
|
21
28
|
}
|
22
29
|
|
23
|
-
const getCollection:
|
30
|
+
const getCollection: Adapter.getCollection = async (reference) => {
|
24
31
|
const collection = await firestore.collection(reference.name).get()
|
25
|
-
const documents:
|
32
|
+
const documents: CollectionSnapshot<typeof reference> = []
|
26
33
|
|
27
34
|
collection.forEach(document => {
|
28
|
-
const documentData:
|
35
|
+
const documentData: Document<typeof reference.schema> = {}
|
29
36
|
Object.keys(reference.schema.properties).forEach(key => {
|
30
37
|
documentData[key] = document.get(key)
|
31
38
|
})
|
@@ -35,35 +42,35 @@ const getCollection: databaseT.getCollection = async (reference) => {
|
|
35
42
|
collection: reference,
|
36
43
|
id: document.id
|
37
44
|
},
|
38
|
-
data: document.data() as
|
45
|
+
data: document.data() as Document<typeof reference.schema>
|
39
46
|
})
|
40
47
|
})
|
41
48
|
return documents
|
42
49
|
}
|
43
50
|
|
44
|
-
const getDocument:
|
51
|
+
const getDocument: Adapter.getDocument = async ({ collection, id }) => {
|
45
52
|
const document = await firestore.collection(collection.name).doc(id).get()
|
46
53
|
if (!document.exists) return undefined
|
47
|
-
const documentReference:
|
54
|
+
const documentReference: DocumentReference<typeof collection> = {
|
48
55
|
collection,
|
49
56
|
id
|
50
57
|
}
|
51
|
-
const documentSnapshot:
|
58
|
+
const documentSnapshot: DocumentSnapshot<typeof collection> = {
|
52
59
|
reference: documentReference,
|
53
|
-
data: document.data() as
|
60
|
+
data: document.data() as Document<typeof collection>
|
54
61
|
}
|
55
62
|
return documentSnapshot
|
56
63
|
}
|
57
64
|
|
58
|
-
const updateDocument:
|
65
|
+
const updateDocument: Adapter.updateDocument = async (reference, document) => {
|
59
66
|
await firestore.collection(reference.collection.name).doc(reference.id).update(document)
|
60
67
|
return {
|
61
68
|
reference,
|
62
69
|
data: document
|
63
|
-
} satisfies
|
70
|
+
} satisfies UpdateSnapshot<typeof reference.collection>
|
64
71
|
}
|
65
72
|
|
66
|
-
const deleteDocument:
|
73
|
+
const deleteDocument: Adapter.deleteDocument = async (reference) => {
|
67
74
|
await firestore.collection(reference.collection.name).doc(reference.id).delete()
|
68
75
|
}
|
69
76
|
|
@@ -0,0 +1,74 @@
|
|
1
|
+
import config from '../../config.js'
|
2
|
+
import { getBucket } from '../storage/storage.js'
|
3
|
+
import { readdir, lstat } from 'node:fs/promises'
|
4
|
+
import { createReadStream } from 'node:fs'
|
5
|
+
import { join } from 'node:path'
|
6
|
+
import { CloudFunctionsServiceClient } from '@google-cloud/functions'
|
7
|
+
|
8
|
+
const functionsClient = new CloudFunctionsServiceClient({
|
9
|
+
credentials: config.deployment.credentials
|
10
|
+
})
|
11
|
+
const projectId = config.deployment.projectId
|
12
|
+
const region = config.deployment.region
|
13
|
+
|
14
|
+
async function uploadDirectory (bucketName: string, directoryPath: string, prefix = ''): Promise<void> {
|
15
|
+
const bucket = getBucket(bucketName)
|
16
|
+
const files = await readdir(directoryPath)
|
17
|
+
|
18
|
+
for (const file of files) {
|
19
|
+
const filePath = join(directoryPath, file)
|
20
|
+
const destination = join(prefix, file)
|
21
|
+
|
22
|
+
const isFileDirectory = (await lstat(filePath)).isDirectory()
|
23
|
+
if (isFileDirectory) {
|
24
|
+
await uploadDirectory(bucketName, filePath, destination)
|
25
|
+
} else {
|
26
|
+
const fileStream = createReadStream(filePath)
|
27
|
+
const gcsFile = bucket.file(destination)
|
28
|
+
|
29
|
+
await new Promise((resolve, reject) => {
|
30
|
+
fileStream
|
31
|
+
.pipe(gcsFile.createWriteStream())
|
32
|
+
.on('error', reject)
|
33
|
+
.on('finish', resolve)
|
34
|
+
})
|
35
|
+
}
|
36
|
+
}
|
37
|
+
}
|
38
|
+
|
39
|
+
async function uploadSourceCode (bucketName: string, source: string, dest: string): Promise<string> {
|
40
|
+
const bucket = getBucket(bucketName)
|
41
|
+
const uploadResponse = await bucket.upload(source, {
|
42
|
+
gzip: true,
|
43
|
+
destination: dest
|
44
|
+
})
|
45
|
+
const file = uploadResponse[0]
|
46
|
+
return file.cloudStorageURI.toString()
|
47
|
+
}
|
48
|
+
|
49
|
+
async function deployFunction (name: string, source: string): Promise<void> {
|
50
|
+
const location = functionsClient.locationPath(projectId, region)
|
51
|
+
const [response] = await functionsClient.createFunction({
|
52
|
+
location,
|
53
|
+
function: {
|
54
|
+
name,
|
55
|
+
sourceUploadUrl: source,
|
56
|
+
entryPoint: 'handler',
|
57
|
+
runtime: 'nodejs20',
|
58
|
+
httpsTrigger: {},
|
59
|
+
environmentVariables: {
|
60
|
+
NODE_ENV: 'production'
|
61
|
+
}
|
62
|
+
}
|
63
|
+
}, {})
|
64
|
+
console.log(response)
|
65
|
+
}
|
66
|
+
|
67
|
+
export default async function (): Promise<void> {
|
68
|
+
const bucketName = config.storage.defaultBucket
|
69
|
+
const assetsPath = '.genoacms/deployment/static'
|
70
|
+
const buildArchivePath = '.genoacms/deployment/build.zip'
|
71
|
+
await uploadDirectory(bucketName, './static', assetsPath)
|
72
|
+
const buildArchiveURI = await uploadSourceCode(bucketName, './build', buildArchivePath)
|
73
|
+
await deployFunction('genoacms', buildArchiveURI)
|
74
|
+
}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import type { Adapter } from '@genoacms/cloudabstraction/deployment'
|
2
|
+
|
3
|
+
const svelteKitAdapter: Adapter.svelteKitAdapter = '@sveltejs/adapter-node'
|
4
|
+
|
5
|
+
const deployProcedure: Adapter.deployProcedure = async () => {
|
6
|
+
const deploy = (await import('./deploy.js')).default
|
7
|
+
await deploy()
|
8
|
+
}
|
9
|
+
|
10
|
+
export {
|
11
|
+
svelteKitAdapter,
|
12
|
+
deployProcedure
|
13
|
+
}
|
@@ -1,21 +1,11 @@
|
|
1
1
|
import type {
|
2
|
-
|
3
|
-
|
2
|
+
Adapter,
|
3
|
+
StorageObject
|
4
4
|
} from '@genoacms/cloudabstraction/storage'
|
5
|
-
import { type
|
6
|
-
import
|
5
|
+
import { type File } from '@google-cloud/storage'
|
6
|
+
import { getBucket } from './storage.js'
|
7
7
|
|
8
|
-
const
|
9
|
-
credentials: config.storage.credentials
|
10
|
-
})
|
11
|
-
|
12
|
-
const getBucket = (name: string): Bucket => {
|
13
|
-
if (!config.storage.buckets.includes(name)) throw new Error('bucket-unregistered')
|
14
|
-
const bucket = storage.bucket(name)
|
15
|
-
return bucket
|
16
|
-
}
|
17
|
-
|
18
|
-
const getObject: Adapter['getObject'] = async ({ bucket, name }) => {
|
8
|
+
const getObject: Adapter.getObject = async ({ bucket, name }) => {
|
19
9
|
const bucketInstance = getBucket(bucket)
|
20
10
|
const file = bucketInstance.file(name)
|
21
11
|
|
@@ -24,13 +14,13 @@ const getObject: Adapter['getObject'] = async ({ bucket, name }) => {
|
|
24
14
|
}
|
25
15
|
}
|
26
16
|
|
27
|
-
const getPublicURL: Adapter
|
17
|
+
const getPublicURL: Adapter.getPublicURL = async ({ bucket, name }) => {
|
28
18
|
const bucketInstance = getBucket(bucket)
|
29
19
|
const file = bucketInstance.file(name)
|
30
20
|
return file.publicUrl()
|
31
21
|
}
|
32
22
|
|
33
|
-
const getSignedURL: Adapter
|
23
|
+
const getSignedURL: Adapter.getSignedURL = async ({ bucket, name }) => {
|
34
24
|
const bucketInstance = getBucket(bucket)
|
35
25
|
const file = bucketInstance.file(name)
|
36
26
|
const expires = new Date()
|
@@ -42,19 +32,19 @@ const getSignedURL: Adapter['getSignedURL'] = async ({ bucket, name }) => {
|
|
42
32
|
return url
|
43
33
|
}
|
44
34
|
|
45
|
-
const uploadObject: Adapter
|
35
|
+
const uploadObject: Adapter.uploadObject = async ({ bucket, name }, stream, options) => {
|
46
36
|
const bucketInstance = getBucket(bucket)
|
47
37
|
const file = bucketInstance.file(name)
|
48
|
-
await file.save(stream)
|
38
|
+
await file.save(stream, options)
|
49
39
|
}
|
50
40
|
|
51
|
-
const deleteObject: Adapter
|
41
|
+
const deleteObject: Adapter.deleteObject = async ({ bucket, name }) => {
|
52
42
|
const bucketInstance = getBucket(bucket)
|
53
43
|
const file = bucketInstance.file(name)
|
54
44
|
await file.delete()
|
55
45
|
}
|
56
46
|
|
57
|
-
const listDirectory: Adapter
|
47
|
+
const listDirectory: Adapter.listDirectory = async ({ bucket, name }, listingParams = {}) => {
|
58
48
|
const bucketInstance = getBucket(bucket)
|
59
49
|
const options = {
|
60
50
|
autoPaginate: false,
|
@@ -81,7 +71,7 @@ const listDirectory: Adapter['listDirectory'] = async ({ bucket, name }, listing
|
|
81
71
|
}
|
82
72
|
}
|
83
73
|
|
84
|
-
const createDirectory: Adapter
|
74
|
+
const createDirectory: Adapter.createDirectory = async ({ bucket, name }) => {
|
85
75
|
const bucketInstance = getBucket(bucket)
|
86
76
|
const file = bucketInstance.file(`${name}/.folderPlaceholder`)
|
87
77
|
await file.save('')
|
@@ -0,0 +1,16 @@
|
|
1
|
+
import config from '../../config.js'
|
2
|
+
import { type Bucket, Storage } from '@google-cloud/storage'
|
3
|
+
|
4
|
+
const storage = new Storage({
|
5
|
+
credentials: config.storage.credentials
|
6
|
+
})
|
7
|
+
|
8
|
+
const getBucket = (name: string): Bucket => {
|
9
|
+
if (!config.storage.buckets.includes(name)) throw new Error('bucket-unregistered')
|
10
|
+
const bucket = storage.bucket(name)
|
11
|
+
return bucket
|
12
|
+
}
|
13
|
+
|
14
|
+
export {
|
15
|
+
getBucket
|
16
|
+
}
|