Нема описа
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.

123456789101112131415161718192021222324252627282930313233
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.calculateChannelExpireTTL = exports.DEFAULT_DURATION = exports.MAX_DURATION = exports.Duration = exports.DURATION_REGEX = void 0;
  4. const error_1 = require("../error");
  5. exports.DURATION_REGEX = /^(\d+)([hdm])$/;
  6. var Duration;
  7. (function (Duration) {
  8. Duration[Duration["MINUTE"] = 60000] = "MINUTE";
  9. Duration[Duration["HOUR"] = 3600000] = "HOUR";
  10. Duration[Duration["DAY"] = 86400000] = "DAY";
  11. })(Duration = exports.Duration || (exports.Duration = {}));
  12. const DURATIONS = {
  13. m: Duration.MINUTE,
  14. h: Duration.HOUR,
  15. d: Duration.DAY,
  16. };
  17. exports.MAX_DURATION = 30 * Duration.DAY;
  18. exports.DEFAULT_DURATION = 7 * Duration.DAY;
  19. function calculateChannelExpireTTL(flag) {
  20. const match = exports.DURATION_REGEX.exec(flag);
  21. if (!match) {
  22. throw new error_1.FirebaseError(`"expires" flag must be a duration string (e.g. 24h or 7d) at most 30d`);
  23. }
  24. const d = parseInt(match[1], 10) * DURATIONS[match[2]];
  25. if (isNaN(d)) {
  26. throw new error_1.FirebaseError(`Failed to parse provided expire time "${flag}"`);
  27. }
  28. if (d > exports.MAX_DURATION) {
  29. throw new error_1.FirebaseError(`"expires" flag may not be longer than 30d`);
  30. }
  31. return d;
  32. }
  33. exports.calculateChannelExpireTTL = calculateChannelExpireTTL;