1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.downloadCertificate = void 0;
|
4 | const fs_extra_1 = require("fs-extra");
|
5 | const os_1 = require("os");
|
6 | const path = require("path");
|
7 | const builder_util_1 = require("builder-util");
|
8 | const fs_1 = require("builder-util/out/fs");
|
9 | const binDownload_1 = require("../binDownload");
|
10 |
|
11 | async function downloadCertificate(urlOrBase64, tmpDir, currentDir) {
|
12 | urlOrBase64 = urlOrBase64.trim();
|
13 | let file = null;
|
14 | if ((urlOrBase64.length > 3 && urlOrBase64[1] === ":") || urlOrBase64.startsWith("/") || urlOrBase64.startsWith(".")) {
|
15 | file = urlOrBase64;
|
16 | }
|
17 | else if (urlOrBase64.startsWith("file://")) {
|
18 | file = urlOrBase64.substring("file://".length);
|
19 | }
|
20 | else if (urlOrBase64.startsWith("~/")) {
|
21 | file = path.join(os_1.homedir(), urlOrBase64.substring("~/".length));
|
22 | }
|
23 | else {
|
24 | const isUrl = urlOrBase64.startsWith("https://");
|
25 | if (isUrl || urlOrBase64.length > 2048 || urlOrBase64.endsWith("=")) {
|
26 | const tempFile = await tmpDir.getTempFile({ suffix: ".p12" });
|
27 | if (isUrl) {
|
28 | await binDownload_1.download(urlOrBase64, tempFile);
|
29 | }
|
30 | else {
|
31 | await fs_extra_1.outputFile(tempFile, Buffer.from(urlOrBase64, "base64"));
|
32 | }
|
33 | return tempFile;
|
34 | }
|
35 | else {
|
36 | file = urlOrBase64;
|
37 | }
|
38 | }
|
39 | file = path.resolve(currentDir, file);
|
40 | const stat = await fs_1.statOrNull(file);
|
41 | if (stat == null) {
|
42 | throw new builder_util_1.InvalidConfigurationError(`${file} doesn't exist`);
|
43 | }
|
44 | else if (!stat.isFile()) {
|
45 | throw new builder_util_1.InvalidConfigurationError(`${file} not a file`);
|
46 | }
|
47 | else {
|
48 | return file;
|
49 | }
|
50 | }
|
51 | exports.downloadCertificate = downloadCertificate;
|
52 |
|
\ | No newline at end of file |