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.
package/lib/index.js CHANGED
@@ -5790,10 +5790,10 @@ function TextOverlay(param) {
5790
5790
  });
5791
5791
  }
5792
5792
  function parseRSSXml(xmlText, maxItems) {
5793
+ var stripped = xmlText.replace(/^<\?xml[^?]*\?>\s*/, "");
5793
5794
  var parser = new DOMParser();
5794
- var doc = parser.parseFromString(xmlText, "text/xml");
5795
- if (doc.querySelector("parsererror")) throw new Error("Invalid RSS XML");
5796
- return Array.from(doc.querySelectorAll("item")).map(function(item) {
5795
+ var doc = parser.parseFromString(stripped, "text/xml");
5796
+ var items = Array.from(doc.querySelectorAll("item")).map(function(item) {
5797
5797
  var _item_querySelector, _item_querySelector1, _item_querySelector2, _item_querySelector3, _item_querySelector4;
5798
5798
  return {
5799
5799
  title: (((_item_querySelector = item.querySelector("title")) === null || _item_querySelector === void 0 ? void 0 : _item_querySelector.textContent) || "").replace(/<[^>]*>/g, "").trim(),
@@ -5805,6 +5805,26 @@ function parseRSSXml(xmlText, maxItems) {
5805
5805
  }).filter(function(i) {
5806
5806
  return i.title;
5807
5807
  }).slice(0, maxItems);
5808
+ if (items.length === 0 && doc.querySelector("parsererror")) {
5809
+ throw new Error("Invalid RSS XML");
5810
+ }
5811
+ return items;
5812
+ }
5813
+ var RSS_CACHE_TTL_MS = 6e4;
5814
+ var rssCache = /* @__PURE__ */ new Map();
5815
+ function cachedFetchRSSItems(rssUrl, maxItems) {
5816
+ var now = Date.now();
5817
+ var cached = rssCache.get(rssUrl);
5818
+ if (cached && cached.expiresAt > now) return cached.promise;
5819
+ var promise = fetchRSSItems(rssUrl, maxItems).catch(function(err) {
5820
+ rssCache.delete(rssUrl);
5821
+ throw err;
5822
+ });
5823
+ rssCache.set(rssUrl, {
5824
+ promise: promise,
5825
+ expiresAt: now + RSS_CACHE_TTL_MS
5826
+ });
5827
+ return promise;
5808
5828
  }
5809
5829
  function fetchRSSItems(rssUrl, maxItems) {
5810
5830
  return _async_to_generator(function() {
@@ -5958,7 +5978,7 @@ function ScrollerOverlay(param) {
5958
5978
  var cancelled = false;
5959
5979
  setRssLoading(true);
5960
5980
  setRssError(false);
5961
- fetchRSSItems(rssUrl, maxItems).then(function(items) {
5981
+ cachedFetchRSSItems(rssUrl, maxItems).then(function(items) {
5962
5982
  if (!cancelled) {
5963
5983
  setRssItems(items);
5964
5984
  setRssError(false);
@@ -5980,7 +6000,8 @@ function ScrollerOverlay(param) {
5980
6000
  useEffect(function() {
5981
6001
  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;
5982
6002
  var interval = setInterval(function() {
5983
- fetchRSSItems(rssUrl, maxItems).then(function(items) {
6003
+ rssCache.delete(rssUrl);
6004
+ cachedFetchRSSItems(rssUrl, maxItems).then(function(items) {
5984
6005
  setRssItems(items);
5985
6006
  setRssError(false);
5986
6007
  }).catch(function() {});