1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | Object.defineProperty(exports, "__esModule", { value: true });
|
18 | const fs = require("fs-extra");
|
19 | const os = require("os");
|
20 | const path = require("path");
|
21 | const util_1 = require("./util");
|
22 | function createStorageProvider() {
|
23 | return new GoogleCloudStorageProvider(bucketName());
|
24 | }
|
25 | exports.createStorageProvider = createStorageProvider;
|
26 | class GoogleCloudStorageProvider {
|
27 | constructor(bucket) {
|
28 | this.bucket = bucket;
|
29 | }
|
30 | async retrieve(key, filePath) {
|
31 | const targetFilePath = filePath || path.join(os.tmpdir() || "/tmp", util_1.guid());
|
32 | await fs.ensureDir(path.dirname(targetFilePath));
|
33 | const storage = new (await Promise.resolve().then(() => require("@google-cloud/storage"))).Storage();
|
34 | await storage.bucket(this.bucket).file(key).download({ destination: targetFilePath });
|
35 | return targetFilePath;
|
36 | }
|
37 | async store(key, filePath) {
|
38 | const storage = new (await Promise.resolve().then(() => require("@google-cloud/storage"))).Storage();
|
39 | await storage.bucket(this.bucket).upload(filePath, {
|
40 | destination: key,
|
41 | resumable: false,
|
42 | });
|
43 | }
|
44 | }
|
45 | exports.GoogleCloudStorageProvider = GoogleCloudStorageProvider;
|
46 | function bucketName() {
|
47 | const bucket = process.env.ATOMIST_STORAGE || process.env.STORAGE;
|
48 | return bucket.replace(/gs:\/\//, "");
|
49 | }
|
50 |
|
\ | No newline at end of file |