From 05c0effa05eb046bb1220507f71553edb886d72d Mon Sep 17 00:00:00 2001 From: MCKero6423 Date: Wed, 13 Aug 2025 11:04:56 +0800 Subject: [PATCH] Delete public/js directory --- public/js/umami-share.js | 47 ---------------------------------------- 1 file changed, 47 deletions(-) delete mode 100644 public/js/umami-share.js diff --git a/public/js/umami-share.js b/public/js/umami-share.js deleted file mode 100644 index 4e090c9..0000000 --- a/public/js/umami-share.js +++ /dev/null @@ -1,47 +0,0 @@ -(function (global) { - const cacheKey = 'umami-share-cache'; - const cacheTTL = 3600_000; // 1h - - async function fetchShareData(baseUrl, shareId) { - const cached = localStorage.getItem(cacheKey); - if (cached) { - try { - const parsed = JSON.parse(cached); - if (Date.now() - parsed.timestamp < cacheTTL) { - return parsed.value; - } - } catch { - localStorage.removeItem(cacheKey); - } - } - const res = await fetch(`${baseUrl}/api/share/${shareId}`); - if (!res.ok) { - throw new Error('获取 Umami 分享信息失败'); - } - const data = await res.json(); - localStorage.setItem(cacheKey, JSON.stringify({ timestamp: Date.now(), value: data })); - return data; - } - - /** - * 获取 Umami 分享数据(websiteId、token)。 - * 在缓存 TTL 内复用;并用全局 Promise 避免并发请求。 - * @param {string} baseUrl - * @param {string} shareId - * @returns {Promise<{websiteId: string, token: string}>} - */ - global.getUmamiShareData = function (baseUrl, shareId) { - if (!global.__umamiSharePromise) { - global.__umamiSharePromise = fetchShareData(baseUrl, shareId).catch((err) => { - delete global.__umamiSharePromise; - throw err; - }); - } - return global.__umamiSharePromise; - }; - - global.clearUmamiShareCache = function () { - localStorage.removeItem(cacheKey); - delete global.__umamiSharePromise; - }; -})(window); \ No newline at end of file