@rowengine/common 1.1.7 → 1.1.9
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/build/utils/gc.d.ts +1 -11
- package/build/utils/gc.js +49 -45
- package/build/utils/index.d.ts +1 -0
- package/build/utils/index.js +6 -0
- package/package.json +1 -1
package/build/utils/gc.d.ts
CHANGED
|
@@ -1,13 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
filePath: string;
|
|
3
|
-
gcsFilePath: string;
|
|
4
|
-
}
|
|
5
|
-
interface UploadFileToGCSResponse {
|
|
6
|
-
filename: string;
|
|
7
|
-
size: number;
|
|
8
|
-
}
|
|
9
|
-
export declare const uploadFileToGCS: ({ filePath, gcsFilePath, }: UploadFileToGCS) => Promise<UploadFileToGCSResponse>;
|
|
10
|
-
export declare const uploadFolderToGCS: (folderPath: string, gcsPath: string) => Promise<void>;
|
|
1
|
+
export declare function uploadFolderToGCS(folderPath: string, gcsPath: string): Promise<void>;
|
|
11
2
|
export declare const getFilesFromGCSFolder: (gcsFolderPath: string) => Promise<string[]>;
|
|
12
3
|
export declare const downloadProjectFileFromGCS: (projectId: string, fileName: string, destinationPath: string) => Promise<string | null>;
|
|
13
|
-
export {};
|
package/build/utils/gc.js
CHANGED
|
@@ -12,54 +12,58 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.downloadProjectFileFromGCS = exports.getFilesFromGCSFolder =
|
|
16
|
-
|
|
17
|
-
const
|
|
15
|
+
exports.downloadProjectFileFromGCS = exports.getFilesFromGCSFolder = void 0;
|
|
16
|
+
exports.uploadFolderToGCS = uploadFolderToGCS;
|
|
17
|
+
const promises_1 = __importDefault(require("fs/promises"));
|
|
18
18
|
const fs_1 = __importDefault(require("fs"));
|
|
19
|
+
const path_1 = __importDefault(require("path"));
|
|
19
20
|
const p_limit_1 = __importDefault(require("p-limit"));
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
21
|
+
const promises_2 = require("stream/promises");
|
|
22
|
+
const gc_storage_1 = __importDefault(require("./gc-storage"));
|
|
23
|
+
// Tune this based on VM size
|
|
24
|
+
const UPLOAD_CONCURRENCY = 24;
|
|
25
|
+
// ---- 1️⃣ Walk directory once (no recursion during upload)
|
|
26
|
+
function walkDir(dir_1) {
|
|
27
|
+
return __awaiter(this, arguments, void 0, function* (dir, baseDir = dir) {
|
|
28
|
+
const entries = yield promises_1.default.readdir(dir, { withFileTypes: true });
|
|
29
|
+
const results = yield Promise.all(entries.map((entry) => __awaiter(this, void 0, void 0, function* () {
|
|
30
|
+
const abs = path_1.default.join(dir, entry.name);
|
|
31
|
+
if (entry.isDirectory()) {
|
|
32
|
+
return walkDir(abs, baseDir);
|
|
33
|
+
}
|
|
34
|
+
const stat = yield promises_1.default.stat(abs);
|
|
35
|
+
return [
|
|
36
|
+
{
|
|
37
|
+
relativePath: path_1.default.relative(baseDir, abs),
|
|
38
|
+
absolutePath: abs,
|
|
39
|
+
size: stat.size,
|
|
40
|
+
},
|
|
41
|
+
];
|
|
42
|
+
})));
|
|
43
|
+
return results.flat();
|
|
40
44
|
});
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
});
|
|
62
|
-
|
|
45
|
+
}
|
|
46
|
+
function uploadFileToGCS(absolutePath, gcsPath, size) {
|
|
47
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
+
const file = gc_storage_1.default.file(gcsPath);
|
|
49
|
+
const resumable = size > 5 * 1024 * 1024; // 5MB threshold
|
|
50
|
+
yield (0, promises_2.pipeline)(fs_1.default.createReadStream(absolutePath), file.createWriteStream({
|
|
51
|
+
resumable,
|
|
52
|
+
validation: false,
|
|
53
|
+
gzip: false,
|
|
54
|
+
metadata: {
|
|
55
|
+
cacheControl: 'public, max-age=31536000',
|
|
56
|
+
},
|
|
57
|
+
}));
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
function uploadFolderToGCS(folderPath, gcsPath) {
|
|
61
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
62
|
+
const limit = (0, p_limit_1.default)(UPLOAD_CONCURRENCY);
|
|
63
|
+
const files = yield walkDir(folderPath);
|
|
64
|
+
yield Promise.all(files.map(({ relativePath, absolutePath, size }) => limit(() => uploadFileToGCS(absolutePath, path_1.default.posix.join(gcsPath, relativePath), size))));
|
|
65
|
+
});
|
|
66
|
+
}
|
|
63
67
|
const getFilesFromGCSFolder = (gcsFolderPath) => __awaiter(void 0, void 0, void 0, function* () {
|
|
64
68
|
const options = {
|
|
65
69
|
prefix: gcsFolderPath.endsWith('/')
|
package/build/utils/index.d.ts
CHANGED
package/build/utils/index.js
CHANGED
|
@@ -13,6 +13,12 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
13
13
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
+
};
|
|
16
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.gcStorage = void 0;
|
|
17
21
|
__exportStar(require("./grades"), exports);
|
|
18
22
|
__exportStar(require("./gc"), exports);
|
|
23
|
+
var gc_storage_1 = require("./gc-storage");
|
|
24
|
+
Object.defineProperty(exports, "gcStorage", { enumerable: true, get: function () { return __importDefault(gc_storage_1).default; } });
|