mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 22:16:40 +00:00
1 parent
769f5a3d21
commit
97c308f550
3 files changed
+136
-8
No files matched your search
@@ -1,13 +1,36 @@
|
||||
// eslint-disable-next-line
|
||||
export default {
|
||||
async send(event: any, data = {}) {
|
||||
/* eslint-disable no-unreachable */
|
||||
return fetch(`https://new-phone-who-dis/${event}`, {
|
||||
export interface IAbortableFetch {
|
||||
abort: () => void;
|
||||
promise: Promise<Response>;
|
||||
}
|
||||
|
||||
function abortableFetch(request, opts): IAbortableFetch {
|
||||
const controller = new AbortController();
|
||||
const signal = controller.signal;
|
||||
|
||||
return {
|
||||
abort: () => controller.abort(),
|
||||
promise: fetch(request, { ...opts, signal }),
|
||||
};
|
||||
}
|
||||
|
||||
function getParams(event, data): [RequestInfo, RequestInit] {
|
||||
return [
|
||||
`https://new-phone-who-dis/${event}`,
|
||||
{
|
||||
method: 'post',
|
||||
headers: {
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
},
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
export default {
|
||||
async send(event: any, data = {}) {
|
||||
return fetch(...getParams(event, data));
|
||||
},
|
||||
sendAbortable(event: any, data = {}): IAbortableFetch {
|
||||
return abortableFetch(...getParams(event, data));
|
||||
},
|
||||
};
|
||||
Reference in new issue
Block a user