@realnation/builder-shared-sdk 1.0.1 → 1.0.4
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 +24 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/oss.d.ts +48 -0
- package/dist/oss.d.ts.map +1 -0
- package/dist/oss.js +266 -0
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -218,6 +218,30 @@ function UserProfileForm() {
|
|
|
218
218
|
- `clearEvents()`: 移除所有**非系统级**的自定义事件。
|
|
219
219
|
- `emitEvent(type: string, ...args: any[])`: Remote触发一个流程事件。参数会透传给回调,如果最后一个参数是函数,则被视作本地回退`callback`。
|
|
220
220
|
|
|
221
|
+
### OSS
|
|
222
|
+
|
|
223
|
+
- `fetchOssCredential(options: OssCredentialRequestOptions)`: 获取固定接口的OSS临时凭证。
|
|
224
|
+
- `createOssClient(credential: OssCredential, options?)`: 使用临时凭证创建OSS客户端。
|
|
225
|
+
- `uploadOssFile(options: OssUploadOptions)`: 上传文件并返回对象地址与Key,支持进度回调和上传目录配置。
|
|
226
|
+
- `clearOssCache(projectId?)`: 清理OSS凭证与客户端缓存,可按项目或全量清理。
|
|
227
|
+
|
|
228
|
+
说明:SDK会基于接口返回的`expireAtUnix/expireAt/expiration`自动缓存并复用凭证与客户端,默认提前60秒刷新;可通过`cacheSkewMs`调整。`uploadOssFile` 默认在凭证失效时重试1次,可用 `retryTimes` 控制,并支持 `allowedExtensions`、`maxSizeBytes`、`minSizeBytes` 限制上传文件。
|
|
229
|
+
|
|
230
|
+
#### OSS 快速示例
|
|
231
|
+
|
|
232
|
+
```typescript
|
|
233
|
+
import { uploadOssFile } from '@realnation/builder-shared-sdk';
|
|
234
|
+
|
|
235
|
+
const result = await uploadOssFile({
|
|
236
|
+
projectId: 'project-id',
|
|
237
|
+
file,
|
|
238
|
+
directory: 'uploads/images',
|
|
239
|
+
onProgress: (ratio) => console.log('progress:', ratio)
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
console.log(result.url);
|
|
243
|
+
```
|
|
244
|
+
|
|
221
245
|
## 🔧 构建
|
|
222
246
|
|
|
223
247
|
```bash
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,OAAO,CAAC"}
|
package/dist/index.js
CHANGED
package/dist/oss.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import OSS from 'ali-oss';
|
|
2
|
+
export interface OssCredential {
|
|
3
|
+
endpoint: string;
|
|
4
|
+
cdnDomain?: string;
|
|
5
|
+
accessKeyId: string;
|
|
6
|
+
accessKeySecret: string;
|
|
7
|
+
securityToken: string;
|
|
8
|
+
bucket: string;
|
|
9
|
+
dir?: string;
|
|
10
|
+
cname?: boolean;
|
|
11
|
+
expiration?: string;
|
|
12
|
+
expireAt?: string;
|
|
13
|
+
expireAtUnix?: number;
|
|
14
|
+
}
|
|
15
|
+
export interface OssCredentialResponse {
|
|
16
|
+
credential: OssCredential;
|
|
17
|
+
}
|
|
18
|
+
export interface OssCredentialRequestOptions {
|
|
19
|
+
projectId: string;
|
|
20
|
+
responseMapper?: (responseData: unknown) => OssCredentialResponse;
|
|
21
|
+
cacheSkewMs?: number;
|
|
22
|
+
}
|
|
23
|
+
export interface OssUploadOptions extends OssCredentialRequestOptions {
|
|
24
|
+
file: File | Blob;
|
|
25
|
+
directory: string;
|
|
26
|
+
fileName?: string;
|
|
27
|
+
partSize?: number;
|
|
28
|
+
secure?: boolean;
|
|
29
|
+
simulateProgress?: boolean;
|
|
30
|
+
onProgress?: (ratio: number) => void;
|
|
31
|
+
retryTimes?: number;
|
|
32
|
+
timeoutRetryTimes?: number;
|
|
33
|
+
allowedExtensions?: string[];
|
|
34
|
+
maxSizeBytes?: number;
|
|
35
|
+
minSizeBytes?: number;
|
|
36
|
+
}
|
|
37
|
+
export interface OssUploadResult {
|
|
38
|
+
url: string;
|
|
39
|
+
objectKey: string;
|
|
40
|
+
}
|
|
41
|
+
export declare function clearOssCache(projectId?: string): void;
|
|
42
|
+
export declare function fetchOssCredential(options: OssCredentialRequestOptions): Promise<OssCredential>;
|
|
43
|
+
export declare function createOssClient(credential: OssCredential, options?: {
|
|
44
|
+
refresh?: () => Promise<OssCredential>;
|
|
45
|
+
secure?: boolean;
|
|
46
|
+
}): Promise<OSS>;
|
|
47
|
+
export declare function uploadOssFile(options: OssUploadOptions): Promise<OssUploadResult>;
|
|
48
|
+
//# sourceMappingURL=oss.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oss.d.ts","sourceRoot":"","sources":["../src/oss.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,SAAS,CAAC;AAG1B,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,eAAe,EAAE,MAAM,CAAC;IACxB,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,qBAAqB;IACpC,UAAU,EAAE,aAAa,CAAC;CAC3B;AAED,MAAM,WAAW,2BAA2B;IAC1C,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,EAAE,CAAC,YAAY,EAAE,OAAO,KAAK,qBAAqB,CAAC;IAClE,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,gBAAiB,SAAQ,2BAA2B;IACnE,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACrC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC7B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,eAAe;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC;CACnB;AAwKD,wBAAgB,aAAa,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAUtD;AAED,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,2BAA2B,GACnC,OAAO,CAAC,aAAa,CAAC,CAcxB;AAED,wBAAsB,eAAe,CACnC,UAAU,EAAE,aAAa,EACzB,OAAO,GAAE;IAAE,OAAO,CAAC,EAAE,MAAM,OAAO,CAAC,aAAa,CAAC,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,CAAA;CAAO,GACzE,OAAO,CAAC,GAAG,CAAC,CAwBd;AAED,wBAAsB,aAAa,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,eAAe,CAAC,CAiGvF"}
|
package/dist/oss.js
ADDED
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
import OSS from 'ali-oss';
|
|
2
|
+
import { getHttpClient } from './http';
|
|
3
|
+
const DEFAULT_PART_SIZE = 1024 * 1024;
|
|
4
|
+
const DEFAULT_CACHE_SKEW_MS = 60 * 1000;
|
|
5
|
+
const credentialCache = new Map();
|
|
6
|
+
const clientCache = new Map();
|
|
7
|
+
function defaultResponseMapper(responseData) {
|
|
8
|
+
if (!responseData || typeof responseData !== 'object') {
|
|
9
|
+
throw new Error('[builder-shared-sdk] OSS credential response is empty.');
|
|
10
|
+
}
|
|
11
|
+
const dataRecord = responseData;
|
|
12
|
+
if (dataRecord.success === false) {
|
|
13
|
+
const errorRecord = dataRecord.error;
|
|
14
|
+
const errorMessage = errorRecord?.message ??
|
|
15
|
+
'[builder-shared-sdk] OSS credential request failed.';
|
|
16
|
+
throw new Error(errorMessage);
|
|
17
|
+
}
|
|
18
|
+
const directCredential = dataRecord.credential;
|
|
19
|
+
if (directCredential) {
|
|
20
|
+
return { credential: directCredential };
|
|
21
|
+
}
|
|
22
|
+
const nestedData = dataRecord.data;
|
|
23
|
+
const nestedCredential = nestedData?.credential;
|
|
24
|
+
if (nestedCredential) {
|
|
25
|
+
return { credential: nestedCredential };
|
|
26
|
+
}
|
|
27
|
+
throw new Error('[builder-shared-sdk] OSS credential response missing credential.');
|
|
28
|
+
}
|
|
29
|
+
function resolveBrowserSecureFlag(explicitSecure) {
|
|
30
|
+
if (explicitSecure !== undefined)
|
|
31
|
+
return explicitSecure;
|
|
32
|
+
if (typeof window === 'undefined')
|
|
33
|
+
return true;
|
|
34
|
+
return window.location.protocol === 'https:';
|
|
35
|
+
}
|
|
36
|
+
function normalizeDir(dir) {
|
|
37
|
+
if (!dir)
|
|
38
|
+
return '';
|
|
39
|
+
const trimmed = dir.replace(/^\/+/, '');
|
|
40
|
+
return trimmed.endsWith('/') ? trimmed : `${trimmed}/`;
|
|
41
|
+
}
|
|
42
|
+
function joinUrl(baseUrl, path) {
|
|
43
|
+
const trimmedBase = baseUrl.replace(/\/+$/, '');
|
|
44
|
+
const trimmedPath = path.replace(/^\/+/, '');
|
|
45
|
+
return `${trimmedBase}/${trimmedPath}`;
|
|
46
|
+
}
|
|
47
|
+
function resolveAccessBaseUrl(credential) {
|
|
48
|
+
return credential.cdnDomain ?? credential.endpoint;
|
|
49
|
+
}
|
|
50
|
+
function getFileExtension(file) {
|
|
51
|
+
if ('name' in file && typeof file.name === 'string') {
|
|
52
|
+
const segments = file.name.split('.');
|
|
53
|
+
if (segments.length > 1) {
|
|
54
|
+
return segments.pop() ?? null;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
function normalizeExtension(extension) {
|
|
60
|
+
return extension.replace(/^\./, '').trim().toLowerCase();
|
|
61
|
+
}
|
|
62
|
+
function resolveUploadExtension(file, fileName) {
|
|
63
|
+
if (fileName) {
|
|
64
|
+
const segments = fileName.split('.');
|
|
65
|
+
if (segments.length > 1) {
|
|
66
|
+
return segments.pop() ?? null;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return getFileExtension(file);
|
|
70
|
+
}
|
|
71
|
+
function validateUploadOptions(options) {
|
|
72
|
+
const size = options.file.size;
|
|
73
|
+
if (Number.isFinite(options.minSizeBytes) && size < options.minSizeBytes) {
|
|
74
|
+
throw new Error('[builder-shared-sdk] OSS upload file size is below minimum limit.');
|
|
75
|
+
}
|
|
76
|
+
if (Number.isFinite(options.maxSizeBytes) && size > options.maxSizeBytes) {
|
|
77
|
+
throw new Error('[builder-shared-sdk] OSS upload file size exceeds maximum limit.');
|
|
78
|
+
}
|
|
79
|
+
const allowed = options.allowedExtensions?.map(normalizeExtension).filter(Boolean) ?? [];
|
|
80
|
+
if (allowed.length > 0) {
|
|
81
|
+
const extension = resolveUploadExtension(options.file, options.fileName);
|
|
82
|
+
if (!extension) {
|
|
83
|
+
throw new Error('[builder-shared-sdk] OSS upload file extension is missing.');
|
|
84
|
+
}
|
|
85
|
+
const normalized = normalizeExtension(extension);
|
|
86
|
+
if (!allowed.includes(normalized)) {
|
|
87
|
+
throw new Error('[builder-shared-sdk] OSS upload file extension is not allowed.');
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
function buildObjectKey(credential, file, directory, fileName) {
|
|
92
|
+
const prefix = credential.dir + normalizeDir(directory);
|
|
93
|
+
const safeFileName = (fileName ?? '').replace(/^\/+/, '');
|
|
94
|
+
if (safeFileName) {
|
|
95
|
+
return `${prefix}${safeFileName}`;
|
|
96
|
+
}
|
|
97
|
+
const extension = getFileExtension(file);
|
|
98
|
+
const timestamp = Date.now();
|
|
99
|
+
const generatedName = extension ? `${timestamp}.${extension}` : `${timestamp}`;
|
|
100
|
+
return `${prefix}${generatedName}`;
|
|
101
|
+
}
|
|
102
|
+
function resolveCredentialExpiryMs(credential) {
|
|
103
|
+
if (typeof credential.expireAtUnix === 'number' && Number.isFinite(credential.expireAtUnix)) {
|
|
104
|
+
return credential.expireAtUnix * 1000;
|
|
105
|
+
}
|
|
106
|
+
const raw = credential.expireAt ?? credential.expiration;
|
|
107
|
+
if (!raw)
|
|
108
|
+
return null;
|
|
109
|
+
const parsed = Date.parse(raw);
|
|
110
|
+
return Number.isNaN(parsed) ? null : parsed;
|
|
111
|
+
}
|
|
112
|
+
function isCredentialFresh(expiresAtMs, skewMs) {
|
|
113
|
+
if (!expiresAtMs)
|
|
114
|
+
return true;
|
|
115
|
+
return Date.now() + skewMs < expiresAtMs;
|
|
116
|
+
}
|
|
117
|
+
function getCacheKey(projectId, secure) {
|
|
118
|
+
return `${projectId}|${secure ? 'https' : 'http'}`;
|
|
119
|
+
}
|
|
120
|
+
function isAuthError(error) {
|
|
121
|
+
if (!error || typeof error !== 'object')
|
|
122
|
+
return false;
|
|
123
|
+
const record = error;
|
|
124
|
+
const reason = record.reason;
|
|
125
|
+
const cause = reason?.cause;
|
|
126
|
+
const code = (cause?.code ?? record.code);
|
|
127
|
+
return code === 'auth.invalid_token' || code === 'auth.token_expired';
|
|
128
|
+
}
|
|
129
|
+
function isTimeoutError(error) {
|
|
130
|
+
if (!error)
|
|
131
|
+
return false;
|
|
132
|
+
const message = typeof error === 'string'
|
|
133
|
+
? error
|
|
134
|
+
: (error.message ?? '');
|
|
135
|
+
return message.includes('ConnectionTimeoutError') || message.includes('timeout');
|
|
136
|
+
}
|
|
137
|
+
export function clearOssCache(projectId) {
|
|
138
|
+
if (!projectId) {
|
|
139
|
+
credentialCache.clear();
|
|
140
|
+
clientCache.clear();
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
credentialCache.delete(projectId);
|
|
144
|
+
clientCache.delete(getCacheKey(projectId, true));
|
|
145
|
+
clientCache.delete(getCacheKey(projectId, false));
|
|
146
|
+
}
|
|
147
|
+
export async function fetchOssCredential(options) {
|
|
148
|
+
const skewMs = options.cacheSkewMs ?? DEFAULT_CACHE_SKEW_MS;
|
|
149
|
+
const cached = credentialCache.get(options.projectId);
|
|
150
|
+
if (cached && isCredentialFresh(cached.expiresAtMs, skewMs)) {
|
|
151
|
+
return cached.credential;
|
|
152
|
+
}
|
|
153
|
+
const httpClient = getHttpClient();
|
|
154
|
+
const response = await httpClient.post(`/partner/aliyun/oss/credential/${options.projectId}`);
|
|
155
|
+
const mapper = options.responseMapper ?? defaultResponseMapper;
|
|
156
|
+
const mapped = mapper(response.data);
|
|
157
|
+
const expiresAtMs = resolveCredentialExpiryMs(mapped.credential);
|
|
158
|
+
credentialCache.set(options.projectId, { credential: mapped.credential, expiresAtMs });
|
|
159
|
+
return mapped.credential;
|
|
160
|
+
}
|
|
161
|
+
export async function createOssClient(credential, options = {}) {
|
|
162
|
+
const secure = resolveBrowserSecureFlag(options.secure);
|
|
163
|
+
const refresh = options.refresh;
|
|
164
|
+
return new OSS({
|
|
165
|
+
endpoint: credential.endpoint,
|
|
166
|
+
accessKeyId: credential.accessKeyId,
|
|
167
|
+
accessKeySecret: credential.accessKeySecret,
|
|
168
|
+
stsToken: credential.securityToken,
|
|
169
|
+
bucket: credential.bucket,
|
|
170
|
+
cname: credential.cname ?? true,
|
|
171
|
+
secure,
|
|
172
|
+
refreshSTSTokenInterval: 3000000,
|
|
173
|
+
refreshSTSToken: refresh
|
|
174
|
+
? async () => {
|
|
175
|
+
const refreshed = await refresh();
|
|
176
|
+
return {
|
|
177
|
+
accessKeyId: refreshed.accessKeyId,
|
|
178
|
+
accessKeySecret: refreshed.accessKeySecret,
|
|
179
|
+
stsToken: refreshed.securityToken
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
: undefined
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
export async function uploadOssFile(options) {
|
|
186
|
+
validateUploadOptions(options);
|
|
187
|
+
const secure = resolveBrowserSecureFlag(options.secure);
|
|
188
|
+
const cacheKey = getCacheKey(options.projectId, secure);
|
|
189
|
+
const skewMs = options.cacheSkewMs ?? DEFAULT_CACHE_SKEW_MS;
|
|
190
|
+
const retryTimes = Math.max(options.retryTimes ?? 1, 0);
|
|
191
|
+
const timeoutRetryTimes = Math.max(options.timeoutRetryTimes ?? 1, 0);
|
|
192
|
+
const attemptUpload = async (authAttempt, timeoutAttempt) => {
|
|
193
|
+
let cachedClient = clientCache.get(cacheKey);
|
|
194
|
+
if (!cachedClient || !isCredentialFresh(cachedClient.expiresAtMs, skewMs)) {
|
|
195
|
+
const credential = await fetchOssCredential(options);
|
|
196
|
+
const expiresAtMs = resolveCredentialExpiryMs(credential);
|
|
197
|
+
const client = await createOssClient(credential, {
|
|
198
|
+
secure,
|
|
199
|
+
refresh: () => fetchOssCredential(options)
|
|
200
|
+
});
|
|
201
|
+
cachedClient = { client, expiresAtMs };
|
|
202
|
+
clientCache.set(cacheKey, cachedClient);
|
|
203
|
+
}
|
|
204
|
+
const credential = credentialCache.get(options.projectId)?.credential;
|
|
205
|
+
if (!credential) {
|
|
206
|
+
throw new Error('[builder-shared-sdk] OSS credential cache is missing.');
|
|
207
|
+
}
|
|
208
|
+
const client = cachedClient.client;
|
|
209
|
+
const objectKey = buildObjectKey(credential, options.file, options.directory, options.fileName);
|
|
210
|
+
const partSize = options.partSize ?? DEFAULT_PART_SIZE;
|
|
211
|
+
const onProgress = options.onProgress;
|
|
212
|
+
let timer = null;
|
|
213
|
+
try {
|
|
214
|
+
if (options.file.size < partSize) {
|
|
215
|
+
if (onProgress && options.simulateProgress) {
|
|
216
|
+
let progressValue = 0;
|
|
217
|
+
timer = setInterval(() => {
|
|
218
|
+
progressValue = Math.min(progressValue + 0.01, 0.95);
|
|
219
|
+
onProgress(progressValue);
|
|
220
|
+
}, 400);
|
|
221
|
+
}
|
|
222
|
+
const result = await client.put(objectKey, options.file);
|
|
223
|
+
if (timer) {
|
|
224
|
+
clearInterval(timer);
|
|
225
|
+
timer = null;
|
|
226
|
+
}
|
|
227
|
+
onProgress?.(1);
|
|
228
|
+
const url = joinUrl(resolveAccessBaseUrl(credential), objectKey);
|
|
229
|
+
return { url, objectKey };
|
|
230
|
+
}
|
|
231
|
+
const result = await client.multipartUpload(objectKey, options.file, {
|
|
232
|
+
partSize,
|
|
233
|
+
progress: (percentage) => {
|
|
234
|
+
onProgress?.(percentage);
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
onProgress?.(1);
|
|
238
|
+
const url = joinUrl(resolveAccessBaseUrl(credential), objectKey);
|
|
239
|
+
const requestUrls = result?.res?.requestUrls;
|
|
240
|
+
if (requestUrls?.length) {
|
|
241
|
+
return { url, objectKey };
|
|
242
|
+
}
|
|
243
|
+
return { url, objectKey };
|
|
244
|
+
}
|
|
245
|
+
catch (error) {
|
|
246
|
+
if (isAuthError(error) && authAttempt < retryTimes) {
|
|
247
|
+
clearOssCache(options.projectId);
|
|
248
|
+
return attemptUpload(authAttempt + 1, timeoutAttempt);
|
|
249
|
+
}
|
|
250
|
+
if (isTimeoutError(error)) {
|
|
251
|
+
if (timeoutAttempt < timeoutRetryTimes) {
|
|
252
|
+
return attemptUpload(authAttempt, timeoutAttempt + 1);
|
|
253
|
+
}
|
|
254
|
+
throw new Error('Timeout. Please check your network and try again.');
|
|
255
|
+
}
|
|
256
|
+
console.log('[builder-shared-sdk] OSS upload error:', error);
|
|
257
|
+
throw new Error('Upload failed. Please try again later.');
|
|
258
|
+
}
|
|
259
|
+
finally {
|
|
260
|
+
if (timer) {
|
|
261
|
+
clearInterval(timer);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
return attemptUpload(0, 0);
|
|
266
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@realnation/builder-shared-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"private": false,
|
|
6
6
|
"exports": {
|
|
@@ -20,9 +20,11 @@
|
|
|
20
20
|
"prepare": "npm run clean && npm run build"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
+
"ali-oss": "^6.23.0",
|
|
23
24
|
"axios": "^1.7.7"
|
|
24
25
|
},
|
|
25
26
|
"devDependencies": {
|
|
27
|
+
"@types/ali-oss": "^6.16.11",
|
|
26
28
|
"rimraf": "^5.0.5",
|
|
27
29
|
"typescript": "^5.4.5"
|
|
28
30
|
}
|