返回 AiToEarn
request.ts
根目录 / project / aitoearn-web / src / store / plugin / request.ts
1 /**
2 * 插件通用代理请求封装
3 */
4
5 import type { PluginProxyRequestParams, PluginProxyResponse } from './types/baseTypes'
6
7 const PLUGIN_PROXY_REQUEST_UNAVAILABLE = 'PLUGIN_PROXY_REQUEST_UNAVAILABLE'
8
9 function getPluginProxyMethod() {
10 const plugin = typeof window !== 'undefined' ? window.AIToEarnPlugin : undefined
11
12 if (!plugin?.proxyRequest) {
13 throw new Error(PLUGIN_PROXY_REQUEST_UNAVAILABLE)
14 }
15
16 return plugin.proxyRequest.bind(plugin)
17 }
18
19 export async function proxyRequest(params: PluginProxyRequestParams): Promise<PluginProxyResponse> {
20 return getPluginProxyMethod()(params)
21 }
22
22 lines TYPESCRIPT