import files to git

This commit is contained in:
2023-02-11 17:35:35 +00:00
parent a2273e4899
commit 9e9b1556d8
4 changed files with 388 additions and 0 deletions

45
src/httpClient.ts Normal file
View File

@@ -0,0 +1,45 @@
const isNode = typeof process === "object";
const $get = (url: string, cb: Function): void => {
const req = new XMLHttpRequest();
req.onreadystatechange = () => {
if (req.readyState === 4 && req.status === 200) {
cb(req.responseText);
}
};
req.open("GET", url, true);
req.send(null);
};
const $post = (
url: string,
path: string,
data: any,
cb: (...args: any[]) => void
): void => {
const req = new XMLHttpRequest();
req.onreadystatechange = () => {
if (req.readyState === 4 && req.status === 200) {
cb(JSON.parse(req.responseText));
}
};
req.open("POST", url + path);
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
req.setRequestHeader("X-Requested-With", "XMLHttpRequest");
req.send(JSON.stringify(data));
};
export default {
get: (url: string): Promise<any> => {
return new Promise((resolve) => {
$get(url, (response) => resolve(response));
});
},
post: (url: string, path: string, data: Object): Promise<any> => {
return new Promise((resolve) => {
$post(url, path, data, (response) => resolve(response));
});
},
};