1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const debug_1 = require("debug");
|
4 | const path = require("path");
|
5 | const semver = require("semver");
|
6 | const sumchecker = require("sumchecker");
|
7 | const artifact_utils_1 = require("./artifact-utils");
|
8 | const Cache_1 = require("./Cache");
|
9 | const downloader_resolver_1 = require("./downloader-resolver");
|
10 | const proxy_1 = require("./proxy");
|
11 | const utils_1 = require("./utils");
|
12 | var utils_2 = require("./utils");
|
13 | exports.getHostArch = utils_2.getHostArch;
|
14 | var proxy_2 = require("./proxy");
|
15 | exports.initializeProxy = proxy_2.initializeProxy;
|
16 | const d = debug_1.default('@electron/get:index');
|
17 | if (process.env.ELECTRON_GET_USE_PROXY) {
|
18 | proxy_1.initializeProxy();
|
19 | }
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 | async function downloadArtifact(_artifactDetails) {
|
27 | const artifactDetails = Object.assign({}, _artifactDetails);
|
28 | if (!_artifactDetails.isGeneric) {
|
29 | const platformArtifactDetails = artifactDetails;
|
30 | if (!platformArtifactDetails.platform) {
|
31 | d('No platform found, defaulting to the host platform');
|
32 | platformArtifactDetails.platform = process.platform;
|
33 | }
|
34 | if (platformArtifactDetails.arch) {
|
35 | platformArtifactDetails.arch = utils_1.getNodeArch(platformArtifactDetails.arch);
|
36 | }
|
37 | else {
|
38 | d('No arch found, defaulting to the host arch');
|
39 | platformArtifactDetails.arch = utils_1.getHostArch();
|
40 | }
|
41 | }
|
42 | utils_1.ensureIsTruthyString(artifactDetails, 'version');
|
43 | artifactDetails.version = utils_1.normalizeVersion(process.env.ELECTRON_CUSTOM_VERSION || artifactDetails.version);
|
44 | const fileName = artifact_utils_1.getArtifactFileName(artifactDetails);
|
45 | const url = await artifact_utils_1.getArtifactRemoteURL(artifactDetails);
|
46 | const cache = new Cache_1.Cache(artifactDetails.cacheRoot);
|
47 |
|
48 | if (!artifactDetails.force) {
|
49 | d(`Checking the cache (${artifactDetails.cacheRoot}) for ${fileName} (${url})`);
|
50 | const cachedPath = await cache.getPathForFileInCache(url, fileName);
|
51 | if (cachedPath === null) {
|
52 | d('Cache miss');
|
53 | }
|
54 | else {
|
55 | d('Cache hit');
|
56 | return cachedPath;
|
57 | }
|
58 | }
|
59 | if (!artifactDetails.isGeneric &&
|
60 | utils_1.isOfficialLinuxIA32Download(artifactDetails.platform, artifactDetails.arch, artifactDetails.version, artifactDetails.mirrorOptions)) {
|
61 | console.warn('Official Linux/ia32 support is deprecated.');
|
62 | console.warn('For more info: https://electronjs.org/blog/linux-32bit-support');
|
63 | }
|
64 | return await utils_1.withTempDirectoryIn(artifactDetails.tempDirectory, async (tempFolder) => {
|
65 | const tempDownloadPath = path.resolve(tempFolder, artifact_utils_1.getArtifactFileName(artifactDetails));
|
66 | const downloader = artifactDetails.downloader || (await downloader_resolver_1.getDownloaderForSystem());
|
67 | d(`Downloading ${url} to ${tempDownloadPath} with options: ${JSON.stringify(artifactDetails.downloadOptions)}`);
|
68 | await downloader.download(url, tempDownloadPath, artifactDetails.downloadOptions);
|
69 |
|
70 |
|
71 | if (!artifactDetails.artifactName.startsWith('SHASUMS256') &&
|
72 | !artifactDetails.unsafelyDisableChecksums &&
|
73 | semver.gte(artifactDetails.version, '1.3.2')) {
|
74 | const shasumPath = await downloadArtifact({
|
75 | isGeneric: true,
|
76 | version: artifactDetails.version,
|
77 | artifactName: 'SHASUMS256.txt',
|
78 | force: artifactDetails.force,
|
79 | downloadOptions: artifactDetails.downloadOptions,
|
80 | cacheRoot: artifactDetails.cacheRoot,
|
81 | downloader: artifactDetails.downloader,
|
82 | mirrorOptions: artifactDetails.mirrorOptions,
|
83 | });
|
84 |
|
85 |
|
86 | if (semver.satisfies(artifactDetails.version, '1.3.2 - 1.3.4')) {
|
87 | const validatorOptions = {};
|
88 | validatorOptions.defaultTextEncoding = 'binary';
|
89 | const checker = new sumchecker.ChecksumValidator('sha256', shasumPath, validatorOptions);
|
90 | await checker.validate(path.dirname(tempDownloadPath), path.basename(tempDownloadPath));
|
91 | }
|
92 | else {
|
93 | await sumchecker('sha256', shasumPath, path.dirname(tempDownloadPath), [
|
94 | path.basename(tempDownloadPath),
|
95 | ]);
|
96 | }
|
97 | }
|
98 | return await cache.putFileInCache(url, tempDownloadPath, fileName);
|
99 | });
|
100 | }
|
101 | exports.downloadArtifact = downloadArtifact;
|
102 |
|
103 |
|
104 |
|
105 |
|
106 |
|
107 |
|
108 | function download(version, options) {
|
109 | return downloadArtifact(Object.assign(Object.assign({}, options), { version, platform: process.platform, arch: process.arch, artifactName: 'electron' }));
|
110 | }
|
111 | exports.download = download;
|
112 |
|
\ | No newline at end of file |