Skip to content

Commit 72c8e8f

Browse files
committed
fix(service): pass correct params to roaApi
1 parent e3b8372 commit 72c8e8f

File tree

4 files changed

+26
-21
lines changed

4 files changed

+26
-21
lines changed

.eslintrc

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
{
2-
"extends": "eslint-config-ali/typescript/react"
2+
"extends": "eslint-config-ali/typescript/react",
3+
"rules": {
4+
"max-len": ["warn", { "code": 180 }]
5+
}
36
}

packages/console-utils/xconsole-service/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@alicloud/xconsole-service",
3-
"version": "2.6.3",
3+
"version": "2.6.4",
44
"main": "lib/index.js",
55
"module": "es/index.js",
66
"types": "lib/index.d.ts",

packages/console-utils/xconsole-service/src/hooks/useService.ts

+20-18
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import createService from '../service';
66
import { IOptions } from '../types';
77
import useAsync from './useAsync';
88
import { ApiType } from '../const/index';
9-
import globalConfig from '../configuration/config'
9+
import globalConfig from '../configuration/config';
1010
import { getOssDownloadUrl, genOssUploadSignature } from '../oss';
1111
import { DownloadSignatureParam, DownloadSignatureResponse, OssSignatureParam, OssSignatureResponse } from '../oss/types';
1212
import createError from '../utils/createError';
@@ -33,7 +33,7 @@ export const useService = <R = any, P extends IParams = {}>(
3333
service: (p: P) => Promise<R>,
3434
params?: P,
3535
opt: IProps<R> = {},
36-
deps: DependencyList = []
36+
deps: DependencyList = [],
3737
) => {
3838
return useAsync<P, R>(
3939
async (runParams: P) => {
@@ -49,7 +49,7 @@ export const useService = <R = any, P extends IParams = {}>(
4949
opt.onError && opt.onError(error);
5050
},
5151
onSuccess: opt.onSuccess,
52-
}
52+
},
5353
);
5454
};
5555

@@ -61,6 +61,8 @@ const useXconsoleService = <R = any, P extends IParams = {}>(
6161
apiType = ApiType.open,
6262
useFetcher = false,
6363
) => {
64+
let requestService;
65+
6466
if (useFetcher) {
6567
const { region: userRegion, useNewRisk, useFetcherProxy, ignoreError, disableThrowResponseError } = opt || {};
6668
const fetcher = useFetcherProxy ? createFetcherProxy({}, {}, useNewRisk) : createFetcher({}, {}, useNewRisk);
@@ -80,32 +82,32 @@ const useXconsoleService = <R = any, P extends IParams = {}>(
8082
return json.data;
8183
};
8284

83-
const requestInstance = (params: P) => {
84-
const { RegionId } = params;
85+
// eslint-disable-next-line @typescript-eslint/no-shadow
86+
requestService = (params: P) => {
87+
const { RegionId, content } = params;
8588
const region = userRegion || RegionId || getActiveRegionId();
8689

87-
8890
switch (apiType) {
8991
case ApiType.open:
9092
return fetcher.callOpenApi<R, P>(code, action, params, { region, getData }).catch(handleError);
9193
case ApiType.inner:
9294
return fetcher.callInnerApi<R, P>(code, action, params, { region, getData }).catch(handleError);
9395
case ApiType.roa:
94-
return fetcher.callOpenApi<R, P>(code, action, params, { region, roa: params.content, getData }).catch(handleError);
96+
// roa 的参数格式特殊
97+
return fetcher.callOpenApi<R, P>(code, action, params.params || params, { region, roa: content, getData }).catch(handleError);
9598
case ApiType.app:
9699
return fetcher.callContainerApi<R, P>(code, action, params, { getData }).catch(handleError);
100+
default:
101+
return fetcher.callOpenApi<R, P>(code, action, params, { region, getData }).catch(handleError);
97102
}
98-
99-
return fetcher.callOpenApi<R, P>(code, action, params, { region, getData }).catch(handleError);
100-
}
101-
102-
return useService<R, P>(requestInstance, params, opt, [code, action]);
103+
};
104+
} else {
105+
requestService = createService<R, P>(code, action, {
106+
...opt,
107+
apiType,
108+
});
103109
}
104110

105-
const requestService = createService<R, P>(code, action, {
106-
...opt,
107-
apiType,
108-
});
109111
return useService<R, P>(requestService, params, opt, [code, action]);
110112
};
111113

@@ -170,14 +172,14 @@ export const useHttpApi = <R = any, P extends IParams = {}>(
170172

171173
export const useOssDownloadUrl = (
172174
params: DownloadSignatureParam,
173-
opt: IProps<DownloadSignatureResponse> = {}
175+
opt: IProps<DownloadSignatureResponse> = {},
174176
) => {
175177
return useService<DownloadSignatureResponse, DownloadSignatureParam>(getOssDownloadUrl, params, opt);
176178
};
177179

178180
export const useOssUploadSignature = (
179181
params: OssSignatureParam,
180-
opt: IProps<OssSignatureResponse> = {}
182+
opt: IProps<OssSignatureResponse> = {},
181183
) => {
182184
return useService<OssSignatureResponse, OssSignatureParam>(genOssUploadSignature, params, opt);
183185
};

packages/console-utils/xconsole-service/src/interceptors/consoleInterceptor/roa.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function consoleRequestInterceptor(config: IOptions): IOptions {
1818
...config.data,
1919
params: config?.data?.params?.params,
2020
content: JSON.stringify(config?.data?.params?.content),
21-
}
21+
};
2222
return config;
2323
}
2424

0 commit comments

Comments
 (0)