Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.js 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. * Downloads an artifact from an Electron release and returns an absolute path
  22. * to the downloaded file.
  23. *
  24. * @param artifactDetails - The information required to download the artifact
  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. // Do not check if the file exists in the cache when force === true
  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. // Don't try to verify the hash of the hash file itself
  70. // and for older versions that don't have a SHASUMS256.txt
  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. // For versions 1.3.2 - 1.3.4, need to overwrite the `defaultTextEncoding` option:
  85. // https://github.com/electron/electron/pull/6676#discussion_r75332120
  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. * Downloads a specific version of Electron and returns an absolute path to a
  104. * ZIP file.
  105. *
  106. * @param version - The version of Electron you want to download
  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. //# sourceMappingURL=index.js.map