8.0.0 #3

Merged
wanhose merged 30 commits from v8.0.0 into main 2024-10-15 15:01:19 +00:00
Showing only changes of commit e4b0cfd817 - Show all commits

View File

@ -21,7 +21,7 @@ if (typeof browser === 'undefined') {
*/ */
class RequestManager { class RequestManager {
constructor() { constructor() {
this.requests = new Map(); // Store ongoing requests this.requests = new Map();
} }
/** /**
@ -30,7 +30,7 @@ class RequestManager {
* @param {RequestInit} [init] * @param {RequestInit} [init]
* @returns {Promise<any>} * @returns {Promise<any>}
*/ */
fetchData(input, init) { fetch(input, init) {
if (this.requests.has(input)) { if (this.requests.has(input)) {
return this.requests.get(input); return this.requests.get(input);
} }
@ -206,7 +206,7 @@ function matchToPattern(match) {
*/ */
async function refreshData() { async function refreshData() {
try { try {
const { data } = await requestManager.fetchData(`${apiUrl}/data/`); const { data } = await requestManager.fetch(`${apiUrl}/data/`);
await updateStore('data', data); await updateStore('data', data);
@ -224,7 +224,7 @@ async function refreshData() {
*/ */
async function refreshIssue(hostname) { async function refreshIssue(hostname) {
try { try {
const { data } = await requestManager.fetchData(`${apiUrl}/issues/${hostname}/`); const { data } = await requestManager.fetch(`${apiUrl}/issues/${hostname}/`);
if (Object.keys(data).length === 0) { if (Object.keys(data).length === 0) {
await updateStore(hostname, { issue: { expiresIn: Date.now() + 8 * 60 * 60 * 1000 } }); await updateStore(hostname, { issue: { expiresIn: Date.now() + 8 * 60 * 60 * 1000 } });
@ -260,7 +260,7 @@ async function report(message) {
const headers = { 'Cache-Control': 'no-cache', 'Content-type': 'application/json' }; const headers = { 'Cache-Control': 'no-cache', 'Content-type': 'application/json' };
const requestInit = { body, headers, method: 'POST' }; const requestInit = { body, headers, method: 'POST' };
return await requestManager.fetchData(`${apiUrl}/report/`, requestInit); return await requestManager.fetch(`${apiUrl}/report/`, requestInit);
} catch { } catch {
console.error("Can't send report"); console.error("Can't send report");
} }