Skip to content
This repository was archived by the owner on Aug 12, 2025. It is now read-only.

Commit b66c4cc

Browse files
committed
feat(xconsole-service): add the request for oss
1 parent 2179858 commit b66c4cc

File tree

5 files changed

+108
-0
lines changed

5 files changed

+108
-0
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { IOptions } from '../types';
44
import useAsync from './useAsync';
55
import { ApiType } from '../const/index';
66
import globalConfig from '../configuration/config'
7+
import { genOssDownloadSignature, genOssUploadSignature } from '../oss';
8+
import { DownloadSignatureParam, DownloadSignatureResponse, OssSignatureParam, OssSignatureResponse } from '../oss/types';
79

810
interface IParams {
911
[key: string]: any;
@@ -104,4 +106,19 @@ export const useRoaApi = <R = any, P extends IParams = {}>(
104106
return useXconsoleService(code, action, params, opt, ApiType.roa);
105107
};
106108

109+
110+
export const useOssDownloadSignature = (
111+
params: DownloadSignatureParam,
112+
opt: IProps<DownloadSignatureResponse> = {}
113+
) => {
114+
return useService<DownloadSignatureResponse, DownloadSignatureParam>(genOssDownloadSignature, params, opt);
115+
};
116+
117+
export const useOssUploadSignature = (
118+
params: OssSignatureParam,
119+
opt: IProps<OssSignatureResponse> = {}
120+
) => {
121+
return useService<OssSignatureResponse, OssSignatureParam>(genOssUploadSignature, params, opt);
122+
};
123+
107124
export default useService;

packages/console-utils/xconsole-service/src/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export type { ApiType, IOptions as ServiceOptions } from './types';
22

33
export * from './hooks/useService';
4+
export * from './oss/index';
45
export { default as useService } from './hooks/useService';
56
export { default as createService, request as defaultAxiosRequest } from './service';
67
export { setGetRegionIdFn } from './utils/index';
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import createRequest from '../request';
2+
import { IOptions, IResponseData } from '../types';
3+
import { DownloadSignatureParam, DownloadSignatureResponse, OssSignatureParam, OssSignatureResponse } from './types';
4+
5+
const SIGNATURE_API_URL = "/tool/oss/generateUploadSignature.json";
6+
const DOWNLOAD_SIGNATURE_API_URL = "/tool/oss/generateDownloadUrl.json";
7+
8+
/**
9+
* OneConsole oss 获取上传签名
10+
*/
11+
export const genOssUploadSignature = async (params: OssSignatureParam, opt: IOptions = {}) => {
12+
const request = createRequest();
13+
const resp = await request.request<IResponseData<OssSignatureResponse>>({
14+
url: SIGNATURE_API_URL,
15+
data: params,
16+
method: 'post',
17+
...opt,
18+
})
19+
return resp.data?.data;
20+
}
21+
22+
23+
/**
24+
* OneConsole oss 获取下载签名
25+
*/
26+
export const genOssDownloadSignature = async (params: DownloadSignatureParam, opt: IOptions = {}) => {
27+
const request = createRequest();
28+
const resp = await request.request<IResponseData<DownloadSignatureResponse>>({
29+
url: DOWNLOAD_SIGNATURE_API_URL,
30+
method: 'post',
31+
data:params,
32+
...opt,
33+
});
34+
return resp.data?.data;
35+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
export interface OssSignatureParam {
2+
bucketName?: string;
3+
region?: string;
4+
objectName: string;
5+
}
6+
7+
export interface OssSignatureResponse {
8+
url: string;
9+
bucketName: string;
10+
key: string;
11+
policy: string;
12+
Signature: string;
13+
OSSAccessKeyId: string;
14+
}
15+
16+
export interface OssUploadParam {
17+
bucketName: string;
18+
key: string;
19+
policy: string;
20+
Signature: string;
21+
OSSAccessKeyId: string;
22+
file: File;
23+
}
24+
25+
export interface UploadParam {
26+
bucketName?: string;
27+
objectName: string;
28+
region?: string;
29+
file: File;
30+
}
31+
32+
33+
export interface DownloadSignatureParam {
34+
bucketName?: string;
35+
region?: string;
36+
objectName: string;
37+
timeout?: number;
38+
}
39+
40+
export interface DownloadSignatureResponse {
41+
url: string;
42+
bucketName: string;
43+
key: string;
44+
policy: string;
45+
Signature: string;
46+
OSSAccessKeyId: string;
47+
}

packages/console-utils/xconsole-service/stories/index.stories.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { select, withKnobs } from '@storybook/addon-knobs';
33
// import withAxiosDecorator from 'storybook-axios';
44
import { storiesOf } from '@storybook/react';
55
import { createService, useOpenApi, useRoaApi, defaultAxiosRequest } from '../src/index'
6+
import { genOssDownloadSignature, genOssUploadSignature } from '../src/oss/index'
67
import { ApiType } from '../src/const';
78
import '@alicloud/console-components/dist/wind.css'
89

@@ -45,3 +46,10 @@ storiesOf('XConsole Service', module)
4546

4647
return <div></div>
4748
})
49+
.add('oss', () => {
50+
useEffect(() => {
51+
genOssDownloadSignature({bucketName: 'xxxx', objectName: 'xxxx'})
52+
});
53+
54+
return <div></div>
55+
})

0 commit comments

Comments
 (0)