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.

Cache.js 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. "use strict";
  2. var __rest = (this && this.__rest) || function (s, e) {
  3. var t = {};
  4. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
  5. t[p] = s[p];
  6. if (s != null && typeof Object.getOwnPropertySymbols === "function")
  7. for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
  8. if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
  9. t[p[i]] = s[p[i]];
  10. }
  11. return t;
  12. };
  13. Object.defineProperty(exports, "__esModule", { value: true });
  14. const debug_1 = require("debug");
  15. const env_paths_1 = require("env-paths");
  16. const fs = require("fs-extra");
  17. const path = require("path");
  18. const url = require("url");
  19. const crypto = require("crypto");
  20. const d = debug_1.default('@electron/get:cache');
  21. const defaultCacheRoot = env_paths_1.default('electron', {
  22. suffix: '',
  23. }).cache;
  24. class Cache {
  25. constructor(cacheRoot = defaultCacheRoot) {
  26. this.cacheRoot = cacheRoot;
  27. }
  28. static getCacheDirectory(downloadUrl) {
  29. const parsedDownloadUrl = url.parse(downloadUrl);
  30. // eslint-disable-next-line @typescript-eslint/no-unused-vars
  31. const { search, hash, pathname } = parsedDownloadUrl, rest = __rest(parsedDownloadUrl, ["search", "hash", "pathname"]);
  32. const strippedUrl = url.format(Object.assign(Object.assign({}, rest), { pathname: path.dirname(pathname || 'electron') }));
  33. return crypto
  34. .createHash('sha256')
  35. .update(strippedUrl)
  36. .digest('hex');
  37. }
  38. getCachePath(downloadUrl, fileName) {
  39. return path.resolve(this.cacheRoot, Cache.getCacheDirectory(downloadUrl), fileName);
  40. }
  41. async getPathForFileInCache(url, fileName) {
  42. const cachePath = this.getCachePath(url, fileName);
  43. if (await fs.pathExists(cachePath)) {
  44. return cachePath;
  45. }
  46. return null;
  47. }
  48. async putFileInCache(url, currentPath, fileName) {
  49. const cachePath = this.getCachePath(url, fileName);
  50. d(`Moving ${currentPath} to ${cachePath}`);
  51. if (await fs.pathExists(cachePath)) {
  52. d('* Replacing existing file');
  53. await fs.remove(cachePath);
  54. }
  55. await fs.move(currentPath, cachePath);
  56. return cachePath;
  57. }
  58. }
  59. exports.Cache = Cache;
  60. //# sourceMappingURL=Cache.js.map