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.cjs CHANGED
@@ -5956,10 +5956,10 @@ function TextOverlay(param) {
5956
5956
  });
5957
5957
  }
5958
5958
  function parseRSSXml(xmlText, maxItems) {
5959
+ var stripped = xmlText.replace(/^<\?xml[^?]*\?>\s*/, "");
5959
5960
  var parser = new DOMParser();
5960
- var doc = parser.parseFromString(xmlText, "text/xml");
5961
- if (doc.querySelector("parsererror")) throw new Error("Invalid RSS XML");
5962
- return Array.from(doc.querySelectorAll("item")).map(function(item) {
5961
+ var doc = parser.parseFromString(stripped, "text/xml");
5962
+ var items = Array.from(doc.querySelectorAll("item")).map(function(item) {
5963
5963
  var _item_querySelector, _item_querySelector1, _item_querySelector2, _item_querySelector3, _item_querySelector4;
5964
5964
  return {
5965
5965
  title: (((_item_querySelector = item.querySelector("title")) === null || _item_querySelector === void 0 ? void 0 : _item_querySelector.textContent) || "").replace(/<[^>]*>/g, "").trim(),
@@ -5971,6 +5971,26 @@ function parseRSSXml(xmlText, maxItems) {
5971
5971
  }).filter(function(i) {
5972
5972
  return i.title;
5973
5973
  }).slice(0, maxItems);
5974
+ if (items.length === 0 && doc.querySelector("parsererror")) {
5975
+ throw new Error("Invalid RSS XML");
5976
+ }
5977
+ return items;
5978
+ }
5979
+ var RSS_CACHE_TTL_MS = 6e4;
5980
+ var rssCache = /* @__PURE__ */ new Map();
5981
+ function cachedFetchRSSItems(rssUrl, maxItems) {
5982
+ var now = Date.now();
5983
+ var cached = rssCache.get(rssUrl);
5984
+ if (cached && cached.expiresAt > now) return cached.promise;
5985
+ var promise = fetchRSSItems(rssUrl, maxItems).catch(function(err) {
5986
+ rssCache.delete(rssUrl);
5987
+ throw err;
5988
+ });
5989
+ rssCache.set(rssUrl, {
5990
+ promise: promise,
5991
+ expiresAt: now + RSS_CACHE_TTL_MS
5992
+ });
5993
+ return promise;
5974
5994
  }
5975
5995
  function fetchRSSItems(rssUrl, maxItems) {
5976
5996
  return _async_to_generator(function() {
@@ -6124,7 +6144,7 @@ function ScrollerOverlay(param) {
6124
6144
  var cancelled = false;
6125
6145
  setRssLoading(true);
6126
6146
  setRssError(false);
6127
- fetchRSSItems(rssUrl, maxItems).then(function(items) {
6147
+ cachedFetchRSSItems(rssUrl, maxItems).then(function(items) {
6128
6148
  if (!cancelled) {
6129
6149
  setRssItems(items);
6130
6150
  setRssError(false);
@@ -6146,7 +6166,8 @@ function ScrollerOverlay(param) {
6146
6166
  (0, import_react.useEffect)(function() {
6147
6167
  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;
6148
6168
  var interval = setInterval(function() {
6149
- fetchRSSItems(rssUrl, maxItems).then(function(items) {
6169
+ rssCache.delete(rssUrl);
6170
+ cachedFetchRSSItems(rssUrl, maxItems).then(function(items) {
6150
6171
  setRssItems(items);
6151
6172
  setRssError(false);
6152
6173
  }).catch(function() {});