@pnt-team/pnt-component-frontend 0.0.91 → 0.0.95
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +149 -54
- package/lib/cjs/api/cos.d.ts +103 -0
- package/lib/cjs/api/cos.js +137 -0
- package/lib/cjs/components/PntCosUploader/index.d.ts +135 -0
- package/lib/cjs/components/PntCosUploader/index.js +209 -0
- package/lib/cjs/components/PntImage/index.d.ts +9 -3
- package/lib/cjs/components/PntImage/index.js +9 -1
- package/lib/cjs/components/PntSecureBox/index.js +8 -5
- package/lib/cjs/components/PntUpload/index.d.ts +149 -0
- package/lib/cjs/components/PntUpload/index.js +228 -0
- package/lib/cjs/components/PntUpload/index.scss +101 -0
- package/lib/cjs/hooks/useHighSecurity.d.ts +55 -15
- package/lib/cjs/hooks/useHighSecurity.js +168 -35
- package/lib/cjs/index.d.ts +6 -0
- package/lib/cjs/index.js +18 -2
- package/lib/esm/api/cos.d.ts +103 -0
- package/lib/esm/api/cos.js +189 -0
- package/lib/esm/components/PntCosUploader/index.d.ts +135 -0
- package/lib/esm/components/PntCosUploader/index.js +289 -0
- package/lib/esm/components/PntImage/index.d.ts +9 -3
- package/lib/esm/components/PntImage/index.js +22 -3
- package/lib/esm/components/PntSecureBox/index.js +9 -3
- package/lib/esm/components/PntUpload/index.d.ts +149 -0
- package/lib/esm/components/PntUpload/index.js +276 -0
- package/lib/esm/components/PntUpload/index.scss +101 -0
- package/lib/esm/hooks/useHighSecurity.d.ts +55 -15
- package/lib/esm/hooks/useHighSecurity.js +174 -32
- package/lib/esm/index.d.ts +6 -0
- package/lib/esm/index.js +9 -1
- package/lib/umd/pnt-component-frontend.min.css +1 -1
- package/lib/umd/pnt-component-frontend.min.js +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import type { AxiosInstance } from 'axios';
|
|
2
|
+
/**
|
|
3
|
+
* 归一化后的 COS 临时凭证
|
|
4
|
+
* @description 各后端接口字段命名不统一(snake/camel),组件库内部统一为 camelCase
|
|
5
|
+
*/
|
|
6
|
+
export interface NormalizedCosCredential {
|
|
7
|
+
/** COS 存储桶 */
|
|
8
|
+
bucket: string;
|
|
9
|
+
/** COS 地域 */
|
|
10
|
+
region: string;
|
|
11
|
+
/** 临时密钥 ID */
|
|
12
|
+
secretId: string;
|
|
13
|
+
/** 临时密钥 Key */
|
|
14
|
+
secretKey: string;
|
|
15
|
+
/** 临时会话令牌 */
|
|
16
|
+
sessionToken: string;
|
|
17
|
+
/** 凭证生效时间(秒) */
|
|
18
|
+
startTime: number;
|
|
19
|
+
/** 凭证过期时间(秒) */
|
|
20
|
+
expiredTime: number;
|
|
21
|
+
/**
|
|
22
|
+
* 业务路径映射
|
|
23
|
+
* @description 后端按业务类型返回的可写路径 map;消费方按 pathKey 选取
|
|
24
|
+
*/
|
|
25
|
+
path?: Record<string, string>;
|
|
26
|
+
/**
|
|
27
|
+
* 受控目录前缀(SDK 定制场景返回)
|
|
28
|
+
* @description 前端在该前缀下自行拼接文件名;可与 pathKey 继续拼接子目录
|
|
29
|
+
*/
|
|
30
|
+
filePath?: string;
|
|
31
|
+
/**
|
|
32
|
+
* CDN 访问域名(不含尾斜杠)
|
|
33
|
+
* @description SDK 定制场景返回 cdn_url;通用场景无此字段时组件按 COS Location 拼接
|
|
34
|
+
*/
|
|
35
|
+
cosHost?: string;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* 通用 COS 凭证响应(snake_case,pnt-tools / account-business)
|
|
39
|
+
*/
|
|
40
|
+
interface SnakeCosCredential {
|
|
41
|
+
bucket: string;
|
|
42
|
+
region: string;
|
|
43
|
+
secret_id: string;
|
|
44
|
+
secret_key: string;
|
|
45
|
+
token: string;
|
|
46
|
+
start_time: number;
|
|
47
|
+
expired_time: number;
|
|
48
|
+
path?: Record<string, string>;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* 内置业务场景
|
|
52
|
+
* @description 决定走哪个后端凭证接口
|
|
53
|
+
* - default: 通用上传(GET /v2/business/operation/get-cos-temp-token)
|
|
54
|
+
* - default_download: 通用下载/上传(POST /v2/business/operation/get-download-cos-temp-token,snake_case)
|
|
55
|
+
* - sdk_customize: SDK 定制服务(POST /internal/sdk_customize/upload_token,含 cdn_url/file_path)
|
|
56
|
+
* - ai_translate: AI 翻译服务(POST /business/aiTranslate/import/cosToken,camelCase)
|
|
57
|
+
*/
|
|
58
|
+
export type CosScene = 'default' | 'default_download' | 'sdk_customize' | 'ai_translate' | (string & Record<never, never>);
|
|
59
|
+
/**
|
|
60
|
+
* 凭证获取参数
|
|
61
|
+
*/
|
|
62
|
+
export interface GetCosCredentialParams {
|
|
63
|
+
/** 业务场景 */
|
|
64
|
+
scene: CosScene;
|
|
65
|
+
/** 业务类型路径 key(透传到后端 path map 选取;sdk_customize 场景作为受控目录下的子目录) */
|
|
66
|
+
pathKey?: string;
|
|
67
|
+
/**
|
|
68
|
+
* 业务上下文参数(gameId/env/updType 等,按 scene 不同传递)
|
|
69
|
+
* @description default/default_download 场景下 gameId 会自动映射到请求头 x-service-type,
|
|
70
|
+
* 其余字段透传到 query/body;ai_translate 场景整体透传到 body
|
|
71
|
+
*/
|
|
72
|
+
context?: Record<string, string | number>;
|
|
73
|
+
/** 文件大小(字节),后端用于校验配额 */
|
|
74
|
+
contentLength?: number;
|
|
75
|
+
/** 已上传文件 URL/Key(下载场景使用) */
|
|
76
|
+
fileUrl?: string;
|
|
77
|
+
/**
|
|
78
|
+
* 网关 audience
|
|
79
|
+
* @default '/player-network'
|
|
80
|
+
* @description 账号管理等子系统需覆盖为对应 audience(如 '/laas-pnt');
|
|
81
|
+
* 消费方注入的 http 实例若已统一追加 audience,URL 上存在该参数时拦截器不会重复追加
|
|
82
|
+
*/
|
|
83
|
+
audience?: string;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* 自定义原始响应归一化函数
|
|
87
|
+
* @description 后端返回字段不符合内置 scene 约定时使用;入参为后端响应的原始 data
|
|
88
|
+
*/
|
|
89
|
+
export type NormalizeCredential = (raw: unknown) => NormalizedCosCredential;
|
|
90
|
+
/**
|
|
91
|
+
* snake_case 凭证归一化(导出供 getCredential 自定义逃生舱复用)
|
|
92
|
+
* @description 消费方自行请求凭证(如项目 http 实例为非标准签名)时,
|
|
93
|
+
* 可在 getCredential 内调用本函数把后端 data 转为组件库统一结构
|
|
94
|
+
*/
|
|
95
|
+
export declare const normalizeSnakeCredential: (raw: SnakeCosCredential) => NormalizedCosCredential;
|
|
96
|
+
/**
|
|
97
|
+
* 获取 COS 临时凭证(按 scene 路由到不同后端接口,内部归一化字段命名)
|
|
98
|
+
* @param http 由 PntProvider 注入的 axios 实例
|
|
99
|
+
* @param params 凭证获取参数
|
|
100
|
+
* @param customNormalize 可选的原始响应自定义归一化
|
|
101
|
+
*/
|
|
102
|
+
export declare const fetchCosCredential: (http: AxiosInstance, params: GetCosCredentialParams, customNormalize?: NormalizeCredential) => Promise<NormalizedCosCredential>;
|
|
103
|
+
export {};
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
// ==========================================
|
|
2
|
+
// COS 临时凭证 - 归一化类型
|
|
3
|
+
// 组件库内部统一为 camelCase;各后端接口的 snake_case / camelCase
|
|
4
|
+
// 在 fetchCosCredential 内部归一化为此结构后返回
|
|
5
|
+
// ==========================================
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 归一化后的 COS 临时凭证
|
|
9
|
+
* @description 各后端接口字段命名不统一(snake/camel),组件库内部统一为 camelCase
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
// ==========================================
|
|
13
|
+
// 各后端接口的原始响应类型
|
|
14
|
+
// ==========================================
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* 通用 COS 凭证响应(snake_case,pnt-tools / account-business)
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* player-network aiTranslate COS 凭证响应(camelCase)
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* SDK 定制服务上传凭证响应(snake_case,含 file_path / cdn_url)
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
// ==========================================
|
|
29
|
+
// Scene 路由表
|
|
30
|
+
// ==========================================
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* 内置业务场景
|
|
34
|
+
* @description 决定走哪个后端凭证接口
|
|
35
|
+
* - default: 通用上传(GET /v2/business/operation/get-cos-temp-token)
|
|
36
|
+
* - default_download: 通用下载/上传(POST /v2/business/operation/get-download-cos-temp-token,snake_case)
|
|
37
|
+
* - sdk_customize: SDK 定制服务(POST /internal/sdk_customize/upload_token,含 cdn_url/file_path)
|
|
38
|
+
* - ai_translate: AI 翻译服务(POST /business/aiTranslate/import/cosToken,camelCase)
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* 凭证获取参数
|
|
43
|
+
*/
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* 自定义原始响应归一化函数
|
|
47
|
+
* @description 后端返回字段不符合内置 scene 约定时使用;入参为后端响应的原始 data
|
|
48
|
+
*/
|
|
49
|
+
|
|
50
|
+
// ==========================================
|
|
51
|
+
// 字段归一化层
|
|
52
|
+
// ==========================================
|
|
53
|
+
|
|
54
|
+
const normalizeSnake = raw => ({
|
|
55
|
+
bucket: raw.bucket,
|
|
56
|
+
region: raw.region,
|
|
57
|
+
secretId: raw.secret_id,
|
|
58
|
+
secretKey: raw.secret_key,
|
|
59
|
+
sessionToken: raw.token,
|
|
60
|
+
startTime: raw.start_time,
|
|
61
|
+
expiredTime: raw.expired_time,
|
|
62
|
+
path: raw.path
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* snake_case 凭证归一化(导出供 getCredential 自定义逃生舱复用)
|
|
67
|
+
* @description 消费方自行请求凭证(如项目 http 实例为非标准签名)时,
|
|
68
|
+
* 可在 getCredential 内调用本函数把后端 data 转为组件库统一结构
|
|
69
|
+
*/
|
|
70
|
+
export const normalizeSnakeCredential = raw => normalizeSnake(raw);
|
|
71
|
+
const normalizeAiTranslate = raw => ({
|
|
72
|
+
bucket: raw.bucket || '',
|
|
73
|
+
region: raw.region || '',
|
|
74
|
+
secretId: raw.secretId || '',
|
|
75
|
+
secretKey: raw.secretKey || '',
|
|
76
|
+
sessionToken: raw.token || '',
|
|
77
|
+
startTime: raw.startTime ?? 0,
|
|
78
|
+
expiredTime: raw.expiredTime ?? 0,
|
|
79
|
+
// aiTranslate path 类型为 Record<string, unknown>,这里收窄为 string
|
|
80
|
+
path: raw.path ? Object.fromEntries(Object.entries(raw.path).filter(v => typeof v[1] === 'string')) : undefined
|
|
81
|
+
});
|
|
82
|
+
const normalizeSdkCustomize = raw => ({
|
|
83
|
+
bucket: raw.bucket,
|
|
84
|
+
region: raw.region,
|
|
85
|
+
secretId: raw.secret_id,
|
|
86
|
+
secretKey: raw.secret_key,
|
|
87
|
+
sessionToken: raw.token,
|
|
88
|
+
startTime: raw.start_time,
|
|
89
|
+
expiredTime: raw.expired_time,
|
|
90
|
+
filePath: raw.file_path,
|
|
91
|
+
cosHost: raw.cdn_url
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
// ==========================================
|
|
95
|
+
// 凭证获取接口封装(按 scene 路由)
|
|
96
|
+
// ==========================================
|
|
97
|
+
|
|
98
|
+
const DEFAULT_AUDIENCE = '/player-network';
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* 统一校验后端响应并执行归一化
|
|
102
|
+
*/
|
|
103
|
+
const resolveCredential = (res, normalize, customNormalize) => {
|
|
104
|
+
// 兼容两套成功标识:新接口 code===0,老接口(账号域 get-cos-temp-token 等)ret===0
|
|
105
|
+
const success = res.code === 0 || res.ret === 0;
|
|
106
|
+
if (!success || res.data === null || typeof res.data === 'undefined') {
|
|
107
|
+
throw new Error(`[PntCosUploader] 获取 COS 凭证失败: code=${res.code ?? 'null'} ret=${res.ret ?? 'null'} ${res.msg || ''}`);
|
|
108
|
+
}
|
|
109
|
+
return customNormalize ? customNormalize(res.data) : normalize(res.data);
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* 获取 COS 临时凭证(按 scene 路由到不同后端接口,内部归一化字段命名)
|
|
114
|
+
* @param http 由 PntProvider 注入的 axios 实例
|
|
115
|
+
* @param params 凭证获取参数
|
|
116
|
+
* @param customNormalize 可选的原始响应自定义归一化
|
|
117
|
+
*/
|
|
118
|
+
export const fetchCosCredential = async (http, params, customNormalize) => {
|
|
119
|
+
const {
|
|
120
|
+
scene,
|
|
121
|
+
context = {},
|
|
122
|
+
contentLength,
|
|
123
|
+
fileUrl,
|
|
124
|
+
audience = DEFAULT_AUDIENCE
|
|
125
|
+
} = params;
|
|
126
|
+
switch (scene) {
|
|
127
|
+
case 'default':
|
|
128
|
+
{
|
|
129
|
+
// 通用上传:GET /v2/business/operation/get-cos-temp-token
|
|
130
|
+
// pnt-tools CosApi 约定:gameId 走请求头 x-service-type
|
|
131
|
+
const {
|
|
132
|
+
gameId,
|
|
133
|
+
...restContext
|
|
134
|
+
} = context;
|
|
135
|
+
// 第二泛型 R 显式指定为解包后的 body(约定消费方 http 响应拦截器返回 response.data)
|
|
136
|
+
const res = await http.get(`/v2/business/operation/get-cos-temp-token?audience=${audience}`, {
|
|
137
|
+
params: {
|
|
138
|
+
content_length: contentLength,
|
|
139
|
+
...restContext
|
|
140
|
+
},
|
|
141
|
+
headers: gameId !== undefined ? {
|
|
142
|
+
'x-service-type': String(gameId)
|
|
143
|
+
} : undefined
|
|
144
|
+
});
|
|
145
|
+
return resolveCredential(res, normalizeSnake, customNormalize);
|
|
146
|
+
}
|
|
147
|
+
case 'default_download':
|
|
148
|
+
{
|
|
149
|
+
// 通用下载/上传:POST /v2/business/operation/get-download-cos-temp-token
|
|
150
|
+
const {
|
|
151
|
+
gameId,
|
|
152
|
+
...restContext
|
|
153
|
+
} = context;
|
|
154
|
+
const res = await http.post(`/v2/business/operation/get-download-cos-temp-token?audience=${audience}`, {
|
|
155
|
+
file_url: fileUrl,
|
|
156
|
+
content_length: contentLength,
|
|
157
|
+
...restContext
|
|
158
|
+
}, {
|
|
159
|
+
headers: gameId !== undefined ? {
|
|
160
|
+
'x-service-type': String(gameId)
|
|
161
|
+
} : undefined
|
|
162
|
+
});
|
|
163
|
+
return resolveCredential(res, normalizeSnake, customNormalize);
|
|
164
|
+
}
|
|
165
|
+
case 'sdk_customize':
|
|
166
|
+
{
|
|
167
|
+
// SDK 定制服务:POST /internal/sdk_customize/upload_token
|
|
168
|
+
// 原项目调用不带 audience(http 拦截器默认补 /player-network)
|
|
169
|
+
const res = await http.post('/internal/sdk_customize/upload_token', {
|
|
170
|
+
content_length: contentLength,
|
|
171
|
+
...context
|
|
172
|
+
});
|
|
173
|
+
return resolveCredential(res, normalizeSdkCustomize, customNormalize);
|
|
174
|
+
}
|
|
175
|
+
case 'ai_translate':
|
|
176
|
+
{
|
|
177
|
+
// AI 翻译服务:POST /business/aiTranslate/import/cosToken(camelCase)
|
|
178
|
+
const res = await http.post('/business/aiTranslate/import/cosToken', {
|
|
179
|
+
contentLength,
|
|
180
|
+
...context
|
|
181
|
+
});
|
|
182
|
+
return resolveCredential(res, normalizeAiTranslate, customNormalize);
|
|
183
|
+
}
|
|
184
|
+
default:
|
|
185
|
+
{
|
|
186
|
+
throw new Error(`[PntCosUploader] 未支持的 scene: ${scene};请通过 getCredential 自定义`);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
};
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { type CosScene, type GetCosCredentialParams, type NormalizeCredential, type NormalizedCosCredential } from "../../api/cos";
|
|
2
|
+
import { usePntConfig } from "../../config";
|
|
3
|
+
import type { AxiosInstance } from 'axios';
|
|
4
|
+
/**
|
|
5
|
+
* 文件名生成策略
|
|
6
|
+
* @description 内置三种策略;如需自定义可传函数
|
|
7
|
+
* - uuid: UUID v4 + 原扩展名(默认,最简单)
|
|
8
|
+
* - md5: 文件内容 MD5 + 原扩展名(与 pnt-tools CosApi 原策略一致)
|
|
9
|
+
* - timestamp: 时间戳(36进制)+自增计数器 + 原扩展名(与 SDK 定制场景原策略一致)
|
|
10
|
+
*/
|
|
11
|
+
export type FileNameStrategy = 'uuid' | 'md5' | 'timestamp' | ((file: File) => string | Promise<string>);
|
|
12
|
+
/**
|
|
13
|
+
* COS 上传配置
|
|
14
|
+
*/
|
|
15
|
+
export interface PntCosUploadOptions {
|
|
16
|
+
/**
|
|
17
|
+
* 业务场景,决定走哪个凭证接口
|
|
18
|
+
* @description 内置 4 个 scene,消费方可传 string 自定义并配合 getCredential 使用
|
|
19
|
+
*/
|
|
20
|
+
scene: CosScene;
|
|
21
|
+
/**
|
|
22
|
+
* 业务类型路径 key
|
|
23
|
+
* @description 通用场景透传给后端 path map 选取对应业务路径;
|
|
24
|
+
* sdk_customize 场景作为受控目录(filePath)下的子目录继续拼接
|
|
25
|
+
*/
|
|
26
|
+
pathKey?: string;
|
|
27
|
+
/**
|
|
28
|
+
* 业务上下文参数(gameId/env/updType 等)
|
|
29
|
+
* @description 按 scene 不同传递给后端;default/default_download 下 gameId 自动映射到 x-service-type 请求头
|
|
30
|
+
*/
|
|
31
|
+
context?: Record<string, string | number>;
|
|
32
|
+
/**
|
|
33
|
+
* 网关 audience
|
|
34
|
+
* @default '/player-network'
|
|
35
|
+
* @description 账号管理等子系统需覆盖为对应 audience(如 '/laas-pnt')
|
|
36
|
+
*/
|
|
37
|
+
audience?: string;
|
|
38
|
+
/**
|
|
39
|
+
* 文件名生成策略
|
|
40
|
+
* @default 'uuid'
|
|
41
|
+
*/
|
|
42
|
+
fileNameStrategy?: FileNameStrategy;
|
|
43
|
+
/**
|
|
44
|
+
* 是否走 CDN 域名拼接
|
|
45
|
+
* @description true 且凭证返回 cosHost 时用 cosHost + cosKey;否则用 COS putObject 返回的 Location
|
|
46
|
+
* @default true
|
|
47
|
+
*/
|
|
48
|
+
useCdn?: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* 自定义凭证获取函数(覆盖内置 scene 路由)
|
|
51
|
+
* @description 后端接口非内置 scene 时使用;返回归一化后的凭证
|
|
52
|
+
*/
|
|
53
|
+
getCredential?: (http: ReturnType<typeof usePntConfig>['http'], params: GetCosCredentialParams) => Promise<NormalizedCosCredential>;
|
|
54
|
+
/**
|
|
55
|
+
* 自定义凭证响应归一化
|
|
56
|
+
* @description 后端字段不标准时使用;入参为内置 scene 接口返回的原始 data,需返回归一化凭证
|
|
57
|
+
*/
|
|
58
|
+
normalizeCredential?: NormalizeCredential;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* COS 上传结果
|
|
62
|
+
*/
|
|
63
|
+
export interface PntCosUploadResult {
|
|
64
|
+
/** 上传后的可访问 URL */
|
|
65
|
+
fileUrl: string;
|
|
66
|
+
/** COS 对象 Key */
|
|
67
|
+
cosKey: string;
|
|
68
|
+
/** 原始文件名 */
|
|
69
|
+
fileName: string;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* 单次请求覆盖参数
|
|
73
|
+
* @description 上传/下载入口的 gameId/task_id/pathKey 常来自表单或表格行数据,
|
|
74
|
+
* 可通过该参数在单次调用覆盖 hook 初始化时的配置
|
|
75
|
+
*/
|
|
76
|
+
export interface PntCosRequestOverrides {
|
|
77
|
+
/** 覆盖业务上下文(与初始化 context 浅合并,如行级 gameId/task_id) */
|
|
78
|
+
context?: Record<string, string | number>;
|
|
79
|
+
/** 覆盖网关 audience */
|
|
80
|
+
audience?: string;
|
|
81
|
+
/** 覆盖凭证场景 */
|
|
82
|
+
scene?: CosScene;
|
|
83
|
+
/** 覆盖业务路径 key */
|
|
84
|
+
pathKey?: string;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* COS 上传器实例
|
|
88
|
+
*/
|
|
89
|
+
export interface PntCosUploader {
|
|
90
|
+
/**
|
|
91
|
+
* 上传文件到 COS
|
|
92
|
+
* @param file 原始文件
|
|
93
|
+
* @param onProgress 上传进度回调(0~100)
|
|
94
|
+
* @param overrides 单次调用覆盖配置(表单/行级 gameId 等)
|
|
95
|
+
*/
|
|
96
|
+
upload: (file: File, onProgress?: (percent: number) => void, overrides?: PntCosRequestOverrides) => Promise<PntCosUploadResult>;
|
|
97
|
+
/**
|
|
98
|
+
* 获取文件预签名下载 URL(临时)
|
|
99
|
+
* @param cosKey COS 对象 Key,或完整 URL(自动剥离域名)
|
|
100
|
+
* @param overrides 单次调用覆盖配置(行级 gameId/task_id 等)
|
|
101
|
+
*/
|
|
102
|
+
getDownloadUrl: (cosKey: string, overrides?: PntCosRequestOverrides) => Promise<string>;
|
|
103
|
+
}
|
|
104
|
+
export type { CosScene, GetCosCredentialParams, NormalizeCredential, NormalizedCosCredential, };
|
|
105
|
+
export { normalizeSnakeCredential } from "../../api/cos";
|
|
106
|
+
/**
|
|
107
|
+
* 创建 COS 直传器实例(不依赖 React)
|
|
108
|
+
* @description 与 usePntCosUploader 共用同一套核心逻辑,适用于 class 兼容层、
|
|
109
|
+
* 工具函数、非 React 入口等场景;React 组件请优先使用 usePntCosUploader
|
|
110
|
+
*
|
|
111
|
+
* @param http 消费方 axios 实例(约定响应拦截器已解包 response.data)
|
|
112
|
+
* @param options 上传配置(固定值),或返回配置的 getter(需要动态配置时使用)
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```ts
|
|
116
|
+
* const uploader = createPntCosUploader(http, { scene: 'default', pathKey: 'marketing_icon' });
|
|
117
|
+
* const { fileUrl } = await uploader.upload(file);
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
export declare const createPntCosUploader: (http: AxiosInstance, options: PntCosUploadOptions | (() => PntCosUploadOptions)) => PntCosUploader;
|
|
121
|
+
/**
|
|
122
|
+
* COS 直传 Service Hook
|
|
123
|
+
* @description 内置凭证获取 + COS SDK 初始化 + 文件名策略 + URL 拼接,
|
|
124
|
+
* 收敛各项目重复的 4 份自实现;http 实例由 PntProvider 注入
|
|
125
|
+
*
|
|
126
|
+
* @param options 上传配置
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```ts
|
|
130
|
+
* const uploader = usePntCosUploader({ scene: 'default', pathKey: 'marketing_icon' });
|
|
131
|
+
* const { fileUrl, cosKey } = await uploader.upload(file, (p) => setProgress(p));
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
134
|
+
export declare const usePntCosUploader: (options: PntCosUploadOptions) => PntCosUploader;
|
|
135
|
+
export default usePntCosUploader;
|