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.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import debug from 'debug';
  2. import * as path from 'path';
  3. import * as semver from 'semver';
  4. import * as sumchecker from 'sumchecker';
  5. import { getArtifactFileName, getArtifactRemoteURL } from './artifact-utils';
  6. import { Cache } from './Cache';
  7. import { getDownloaderForSystem } from './downloader-resolver';
  8. import { initializeProxy } from './proxy';
  9. import { withTempDirectoryIn, normalizeVersion, getHostArch, getNodeArch, ensureIsTruthyString, isOfficialLinuxIA32Download, } from './utils';
  10. export { getHostArch } from './utils';
  11. export { initializeProxy } from './proxy';
  12. const d = debug('@electron/get:index');
  13. if (process.env.ELECTRON_GET_USE_PROXY) {
  14. initializeProxy();
  15. }
  16. /**
  17. * Downloads an artifact from an Electron release and returns an absolute path
  18. * to the downloaded file.
  19. *
  20. * @param artifactDetails - The information required to download the artifact
  21. */
  22. export async function downloadArtifact(_artifactDetails) {
  23. const artifactDetails = Object.assign({}, _artifactDetails);
  24. if (!_artifactDetails.isGeneric) {
  25. const platformArtifactDetails = artifactDetails;
  26. if (!platformArtifactDetails.platform) {
  27. d('No platform found, defaulting to the host platform');
  28. platformArtifactDetails.platform = process.platform;
  29. }
  30. if (platformArtifactDetails.arch) {
  31. platformArtifactDetails.arch = getNodeArch(platformArtifactDetails.arch);
  32. }
  33. else {
  34. d('No arch found, defaulting to the host arch');
  35. platformArtifactDetails.arch = getHostArch();
  36. }
  37. }
  38. ensureIsTruthyString(artifactDetails, 'version');
  39. artifactDetails.version = normalizeVersion(process.env.ELECTRON_CUSTOM_VERSION || artifactDetails.version);
  40. const fileName = getArtifactFileName(artifactDetails);
  41. const url = await getArtifactRemoteURL(artifactDetails);
  42. const cache = new Cache(artifactDetails.cacheRoot);
  43. // Do not check if the file exists in the cache when force === true
  44. if (!artifactDetails.force) {
  45. d(`Checking the cache (${artifactDetails.cacheRoot}) for ${fileName} (${url})`);
  46. const cachedPath = await cache.getPathForFileInCache(url, fileName);
  47. if (cachedPath === null) {
  48. d('Cache miss');
  49. }
  50. else {
  51. d('Cache hit');
  52. return cachedPath;
  53. }
  54. }
  55. if (!artifactDetails.isGeneric &&
  56. isOfficialLinuxIA32Download(artifactDetails.platform, artifactDetails.arch, artifactDetails.version, artifactDetails.mirrorOptions)) {
  57. console.warn('Official Linux/ia32 support is deprecated.');
  58. console.warn('For more info: https://electronjs.org/blog/linux-32bit-support');
  59. }
  60. return await withTempDirectoryIn(artifactDetails.tempDirectory, async (tempFolder) => {
  61. const tempDownloadPath = path.resolve(tempFolder, getArtifactFileName(artifactDetails));
  62. const downloader = artifactDetails.downloader || (await getDownloaderForSystem());
  63. d(`Downloading ${url} to ${tempDownloadPath} with options: ${JSON.stringify(artifactDetails.downloadOptions)}`);
  64. await downloader.download(url, tempDownloadPath, artifactDetails.downloadOptions);
  65. // Don't try to verify the hash of the hash file itself
  66. // and for older versions that don't have a SHASUMS256.txt
  67. if (!artifactDetails.artifactName.startsWith('SHASUMS256') &&
  68. !artifactDetails.unsafelyDisableChecksums &&
  69. semver.gte(artifactDetails.version, '1.3.2')) {
  70. const shasumPath = await downloadArtifact({
  71. isGeneric: true,
  72. version: artifactDetails.version,
  73. artifactName: 'SHASUMS256.txt',
  74. force: artifactDetails.force,
  75. downloadOptions: artifactDetails.downloadOptions,
  76. cacheRoot: artifactDetails.cacheRoot,
  77. downloader: artifactDetails.downloader,
  78. mirrorOptions: artifactDetails.mirrorOptions,
  79. });
  80. // For versions 1.3.2 - 1.3.4, need to overwrite the `defaultTextEncoding` option:
  81. // https://github.com/electron/electron/pull/6676#discussion_r75332120
  82. if (semver.satisfies(artifactDetails.version, '1.3.2 - 1.3.4')) {
  83. const validatorOptions = {};
  84. validatorOptions.defaultTextEncoding = 'binary';
  85. const checker = new sumchecker.ChecksumValidator('sha256', shasumPath, validatorOptions);
  86. await checker.validate(path.dirname(tempDownloadPath), path.basename(tempDownloadPath));
  87. }
  88. else {
  89. await sumchecker('sha256', shasumPath, path.dirname(tempDownloadPath), [
  90. path.basename(tempDownloadPath),
  91. ]);
  92. }
  93. }
  94. return await cache.putFileInCache(url, tempDownloadPath, fileName);
  95. });
  96. }
  97. /**
  98. * Downloads a specific version of Electron and returns an absolute path to a
  99. * ZIP file.
  100. *
  101. * @param version - The version of Electron you want to download
  102. */
  103. export function download(version, options) {
  104. return downloadArtifact(Object.assign(Object.assign({}, options), { version, platform: process.platform, arch: process.arch, artifactName: 'electron' }));
  105. }
  106. //# sourceMappingURL=index.js.map