refactor(background): inline fetch
and use URLSearchParams
This commit is contained in:
parent
b0a2a4321e
commit
3f1300543d
|
@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
## \[unreleased]
|
## \[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
|
### ⛰️ Features
|
||||||
|
|
||||||
- Add commitlint to enforce commit message format
|
- Add commitlint to enforce commit message format
|
||||||
|
|
|
@ -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
|
* @param {number} days
|
||||||
* @returns {Promise<import("../types").Calendar>}
|
* @returns {Promise<import("../types").Calendar>}
|
||||||
*/
|
*/
|
||||||
function fetchCalendar(days = 28) {
|
async function fetchCalendar(days = 28) {
|
||||||
let url = `${API_URLS.calender}?o=json`;
|
const params = new URLSearchParams();
|
||||||
|
params.set('o', 'json');
|
||||||
if (days) {
|
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>}
|
* @returns {Promise<import("../types").SpaceApi>}
|
||||||
*/
|
*/
|
||||||
function fetchSpaceApi() {
|
async function fetchSpaceApi() {
|
||||||
return fetchJson(API_URLS.spaceApi);
|
const response = await fetch(API_URLS.spaceApi);
|
||||||
|
return response.json();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchNewData() {
|
async function fetchNewData() {
|
||||||
|
|
Loading…
Reference in a new issue