stormcloud-video-player 0.7.29 → 0.7.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -442,10 +442,10 @@ function TextOverlay(param) {
442
442
  });
443
443
  }
444
444
  function parseRSSXml(xmlText, maxItems) {
445
+ var stripped = xmlText.replace(/^<\?xml[^?]*\?>\s*/, "");
445
446
  var parser = new DOMParser();
446
- var doc = parser.parseFromString(xmlText, "text/xml");
447
- if (doc.querySelector("parsererror")) throw new Error("Invalid RSS XML");
448
- return Array.from(doc.querySelectorAll("item")).map(function(item) {
447
+ var doc = parser.parseFromString(stripped, "text/xml");
448
+ var items = Array.from(doc.querySelectorAll("item")).map(function(item) {
449
449
  var _item_querySelector, _item_querySelector1, _item_querySelector2, _item_querySelector3, _item_querySelector4;
450
450
  return {
451
451
  title: (((_item_querySelector = item.querySelector("title")) === null || _item_querySelector === void 0 ? void 0 : _item_querySelector.textContent) || "").replace(/<[^>]*>/g, "").trim(),
@@ -457,6 +457,26 @@ function parseRSSXml(xmlText, maxItems) {
457
457
  }).filter(function(i) {
458
458
  return i.title;
459
459
  }).slice(0, maxItems);
460
+ if (items.length === 0 && doc.querySelector("parsererror")) {
461
+ throw new Error("Invalid RSS XML");
462
+ }
463
+ return items;
464
+ }
465
+ var RSS_CACHE_TTL_MS = 6e4;
466
+ var rssCache = /* @__PURE__ */ new Map();
467
+ function cachedFetchRSSItems(rssUrl, maxItems) {
468
+ var now = Date.now();
469
+ var cached = rssCache.get(rssUrl);
470
+ if (cached && cached.expiresAt > now) return cached.promise;
471
+ var promise = fetchRSSItems(rssUrl, maxItems).catch(function(err) {
472
+ rssCache.delete(rssUrl);
473
+ throw err;
474
+ });
475
+ rssCache.set(rssUrl, {
476
+ promise: promise,
477
+ expiresAt: now + RSS_CACHE_TTL_MS
478
+ });
479
+ return promise;
460
480
  }
461
481
  function fetchRSSItems(rssUrl, maxItems) {
462
482
  return _async_to_generator(function() {
@@ -610,7 +630,7 @@ function ScrollerOverlay(param) {
610
630
  var cancelled = false;
611
631
  setRssLoading(true);
612
632
  setRssError(false);
613
- fetchRSSItems(rssUrl, maxItems).then(function(items) {
633
+ cachedFetchRSSItems(rssUrl, maxItems).then(function(items) {
614
634
  if (!cancelled) {
615
635
  setRssItems(items);
616
636
  setRssError(false);
@@ -632,7 +652,8 @@ function ScrollerOverlay(param) {
632
652
  (0, import_react.useEffect)(function() {
633
653
  if (!rssUrl || !autoRefresh || (cfg === null || cfg === void 0 ? void 0 : cfg.use_custom_text) && (cfg === null || cfg === void 0 ? void 0 : cfg.custom_text)) return;
634
654
  var interval = setInterval(function() {
635
- fetchRSSItems(rssUrl, maxItems).then(function(items) {
655
+ rssCache.delete(rssUrl);
656
+ cachedFetchRSSItems(rssUrl, maxItems).then(function(items) {
636
657
  setRssItems(items);
637
658
  setRssError(false);
638
659
  }).catch(function() {});