mirror of
https://github.com/dnote/dnote
synced 2026-03-14 22:45:50 +01:00
* Allow to add and edit notes * Implement search * Implement settings * Implement checkout page * Implement paywall * Fix inconsistent margin * Render mobile menu * Allow to logout * emails * Implement user migration * Always build standalone * Embed digest in email * Move browser extension * Fix test * Use system font * Add favicon and app icons * Make tabbar smaller * Initialize focus on editor * Fix various UI audit issues * Simplify asset serving * Register sw * Upgrade deps
48 lines
922 B
JavaScript
48 lines
922 B
JavaScript
import qs from 'qs';
|
|
|
|
function checkStatus(response) {
|
|
if (response.status >= 200 && response.status < 300) {
|
|
return response;
|
|
}
|
|
return response.text().then((body) => {
|
|
const error = new Error(body);
|
|
error.response = response;
|
|
|
|
throw error;
|
|
});
|
|
}
|
|
|
|
function parseJSON(response) {
|
|
if (response.headers.get('Content-Type') === 'application/json') {
|
|
return response.json();
|
|
}
|
|
|
|
return Promise.resolve();
|
|
}
|
|
|
|
function request(url, options) {
|
|
return fetch(url, options)
|
|
.then(checkStatus)
|
|
.then(parseJSON);
|
|
}
|
|
|
|
export function post(url, data, options = {}) {
|
|
return request(url, {
|
|
method: 'POST',
|
|
body: JSON.stringify(data),
|
|
...options,
|
|
});
|
|
}
|
|
|
|
export function get(url, options = {}) {
|
|
let endpoint = url;
|
|
|
|
if (options.params) {
|
|
endpoint = `${endpoint}?${qs.stringify(options.params)}`;
|
|
}
|
|
|
|
return request(endpoint, {
|
|
method: 'GET',
|
|
...options,
|
|
});
|
|
}
|