MCPcopy
hub / github.com/QuantumNous/new-api / patchAPIInstance

Function patchAPIInstance

web/src/helpers/api.js:53–79  ·  view source on GitHub ↗
(instance)

Source from the content-addressed store, hash-verified

51
52
53function patchAPIInstance(instance) {
54 const originalGet = instance.get.bind(instance);
55 const inFlightGetRequests = new Map();
56
57 const genKey = (url, config = {}) => {
58 const params = config.params ? JSON.stringify(config.params) : '{}';
59 return `${url}?${params}`;
60 };
61
62 instance.get = (url, config = {}) => {
63 if (config?.disableDuplicate) {
64 return originalGet(url, config);
65 }
66
67 const key = genKey(url, config);
68 if (inFlightGetRequests.has(key)) {
69 return inFlightGetRequests.get(key);
70 }
71
72 const reqPromise = originalGet(url, config).finally(() => {
73 inFlightGetRequests.delete(key);
74 });
75
76 inFlightGetRequests.set(key, reqPromise);
77 return reqPromise;
78 };
79}
80
81patchAPIInstance(API);
82

Callers 2

api.jsFile · 0.85
updateAPIFunction · 0.85

Calls 1

genKeyFunction · 0.85

Tested by

no test coverage detected