1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const cloud_bucket_1 = require("cloud-bucket");
|
4 | const utils_1 = require("./utils");
|
5 |
|
6 | async function list(pathInfo) {
|
7 | const bucket = await getBucketFromPathInfo(pathInfo);
|
8 | const result = await bucket.list(pathInfo.path);
|
9 | return result;
|
10 | }
|
11 | exports.list = list;
|
12 | async function copy(from, to) {
|
13 | const files = await list(from);
|
14 | const destBucket = await getBucketFromPathInfo(to);
|
15 |
|
16 | }
|
17 | exports.copy = copy;
|
18 | async function download(from, destDir) {
|
19 | if (from.path == null) {
|
20 | throw new Error(`Cannot download - undefined remote path: ${from.store}:${from.path}`);
|
21 | }
|
22 | const bucket = await getBucketFromPathInfo(from);
|
23 | return bucket.download(from.path, destDir);
|
24 | }
|
25 | exports.download = download;
|
26 | async function upload(localFile, dest) {
|
27 | if (dest.path == null) {
|
28 | throw new Error(`Cannot download - undefined remote path: ${dest.store}:${dest.path}`);
|
29 | }
|
30 | const bucket = await getBucketFromPathInfo(dest);
|
31 | return bucket.upload(localFile, dest.path);
|
32 | }
|
33 | exports.upload = upload;
|
34 |
|
35 |
|
36 | const formatInfo = `'storename:path' or just 'storename'`;
|
37 | function parsePathInfo(storeAndPathStr) {
|
38 | if (storeAndPathStr == null || storeAndPathStr.length == 0) {
|
39 | throw new Error(`gs need to have a path like ${formatInfo}`);
|
40 | }
|
41 | const storeAndPath = storeAndPathStr.split(':');
|
42 | if (storeAndPath.length > 2) {
|
43 | throw new Error(`Path ${storeAndPathStr} is invalid, needs to be of format like ${formatInfo}`);
|
44 | }
|
45 | const [store, path] = storeAndPath;
|
46 | return { store, path };
|
47 | }
|
48 | exports.parsePathInfo = parsePathInfo;
|
49 |
|
50 |
|
51 | async function getBucketFromPathInfo(pathInfo) {
|
52 | const bucketCfgs = await loadRawConfig();
|
53 |
|
54 | const rawCfg = bucketCfgs[pathInfo.store];
|
55 | return cloud_bucket_1.getBucket(rawCfg);
|
56 | }
|
57 | async function loadRawConfig() {
|
58 | let vdevBuckets = await utils_1.loadYaml('vdev-buckets.yaml');
|
59 | const confs = vdevBuckets.buckets;
|
60 |
|
61 | for (let name in confs) {
|
62 | confs[name].name = name;
|
63 | }
|
64 | return confs;
|
65 | }
|
66 |
|