GSI - Employe Self Service Mobile
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.

29 lines
984 B

2 months ago
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.shortenUrl = void 0;
  4. const logger_1 = require("./logger");
  5. const apiv2_1 = require("./apiv2");
  6. const api_1 = require("./api");
  7. const DYNAMIC_LINKS_PREFIX = "https://firebase.tools/l";
  8. const apiClient = new apiv2_1.Client({
  9. urlPrefix: api_1.dynamicLinksOrigin,
  10. auth: false,
  11. apiVersion: "v1",
  12. });
  13. async function shortenUrl(url, guessable = false) {
  14. try {
  15. const response = await apiClient.post(`shortLinks?key=${api_1.dynamicLinksKey}`, {
  16. dynamicLinkInfo: {
  17. link: url,
  18. domainUriPrefix: DYNAMIC_LINKS_PREFIX,
  19. },
  20. suffix: { option: guessable ? "SHORT" : "UNGUESSABLE" },
  21. });
  22. return response.body.shortLink;
  23. }
  24. catch (e) {
  25. logger_1.logger.debug("URL shortening failed, falling back to full URL. Error:", e.original || e);
  26. return url;
  27. }
  28. }
  29. exports.shortenUrl = shortenUrl;