refactor(background): inline `fetch` and use `URLSearchParams`

This commit is contained in:
Thomas Rupprecht 2023-09-06 21:29:10 +02:00
parent b0a2a4321e
commit 3f1300543d
2 changed files with 15 additions and 15 deletions

View File

@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
## \[unreleased]
### 🚜 Refactor
- Inline `fetch` and use `URLSearchParams`
## \[[0.9.3](https://gitea.usrspace.at/XimeX/usrspace-browser-addon/releases/tag/v0.9.3)] - 2023-09-06
### ⛰️ Features
- Add commitlint to enforce commit message format

View File

@ -15,32 +15,26 @@ browser.alarms.onAlarm.addListener((alarm) => {
}
});
/**
* @param {string} url
* @returns {Promise<any>}
*/
async function fetchJson(url) {
const response = await fetch(url);
return response.json();
}
/**
* @param {number} days
* @returns {Promise<import("../types").Calendar>}
*/
function fetchCalendar(days = 28) {
let url = `${API_URLS.calender}?o=json`;
async function fetchCalendar(days = 28) {
const params = new URLSearchParams();
params.set('o', 'json');
if (days) {
url += `&r=${days}`;
params.set('r', `${days}`);
}
return fetchJson(url);
const response = await fetch(`${API_URLS.calender}?${params.toString()}`);
return response.json();
}
/**
* @returns {Promise<import("../types").SpaceApi>}
*/
function fetchSpaceApi() {
return fetchJson(API_URLS.spaceApi);
async function fetchSpaceApi() {
const response = await fetch(API_URLS.spaceApi);
return response.json();
}
async function fetchNewData() {