MCPcopy
hub / github.com/yinxin630/fiora / fetch

Function fetch

packages/web/src/utils/fetch.ts:9–41  ·  view source on GitHub ↗
(
    event: string,
    data = {},
    { toast = true } = {},
)

Source from the content-addressed store, hash-verified

7let isSeal = false;
8
9export default function fetch<T = any>(
10 event: string,
11 data = {},
12 { toast = true } = {},
13): Promise<[string | null, T | null]> {
14 if (isSeal) {
15 Message.error(SEAL_TEXT);
16 return Promise.resolve([SEAL_TEXT, null]);
17 }
18 return new Promise((resolve) => {
19 socket.emit(event, data, (res: any) => {
20 if (typeof res === 'string') {
21 if (toast) {
22 Message.error(res);
23 }
24 /**
25 * 服务端返回封禁状态后, 本地存储该状态
26 * 用户再触发接口请求时, 直接拒绝
27 */
28 if (res === SEAL_TEXT) {
29 isSeal = true;
30 // 用户封禁和ip封禁时效不同, 这里用的短时间
31 setTimeout(() => {
32 isSeal = false;
33 }, SEAL_USER_TIMEOUT);
34 }
35 resolve([res, null]);
36 } else {
37 resolve([null, res]);
38 }
39 });
40 });
41}

Callers 15

initOSSFunction · 0.70
uploadFileFunction · 0.70
readFunction · 0.70
registerFunction · 0.50
loginFunction · 0.50
loginByTokenFunction · 0.50
guestFunction · 0.50
changeAvatarFunction · 0.50
changePasswordFunction · 0.50
changeUsernameFunction · 0.50
changeGroupNameFunction · 0.50
changeGroupAvatarFunction · 0.50

Calls

no outgoing calls

Tested by

no test coverage detected