7fb0bdc9a5
- Binds the 'R' key to trigger a refresh in the background for all feeds. - Updates the locale, using the same description as the link in the feeds page. Co-authored-by: Vitor Pellegrino <pellegrino@linux.com>
48 lines
1.1 KiB
JavaScript
48 lines
1.1 KiB
JavaScript
class RequestBuilder {
|
|
constructor(url) {
|
|
this.callback = null;
|
|
this.url = url;
|
|
this.options = {
|
|
method: "POST",
|
|
cache: "no-cache",
|
|
credentials: "include",
|
|
body: null,
|
|
headers: new Headers({
|
|
"Content-Type": "application/json",
|
|
"X-Csrf-Token": this.getCsrfToken()
|
|
})
|
|
};
|
|
}
|
|
|
|
withHttpMethod(method) {
|
|
this.options.method = method;
|
|
return this;
|
|
}
|
|
|
|
withBody(body) {
|
|
this.options.body = JSON.stringify(body);
|
|
return this;
|
|
}
|
|
|
|
withCallback(callback) {
|
|
this.callback = callback;
|
|
return this;
|
|
}
|
|
|
|
getCsrfToken() {
|
|
let element = document.querySelector("meta[name=X-CSRF-Token]");
|
|
if (element !== null) {
|
|
return element.getAttribute("value");
|
|
}
|
|
|
|
return "";
|
|
}
|
|
|
|
execute() {
|
|
fetch(new Request(this.url, this.options)).then((response) => {
|
|
if (this.callback) {
|
|
this.callback(response);
|
|
}
|
|
});
|
|
}
|
|
}
|