Skip to content

Commit aaf3285

Browse files
committed
添加鸿蒙系统兼容性检查
1 parent e55bcde commit aaf3285

File tree

6 files changed

+29
-10
lines changed

6 files changed

+29
-10
lines changed

packages/harmony/library/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Change logs
22

3+
## v1.0.0-rc.3 (2024-01-12)
4+
5+
### 改动
6+
7+
- 添加直传的非完整能力支持
8+
- 添加系统接口的调用前检查
9+
310
## v1.0.0-rc.2 (2024-01-09)
411

512
### 改动

packages/harmony/library/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ interface Context {
9292
- `result`:上传成功的信息。
9393
- `error`:队列的错误。
9494
- `progress`:整体的任务进度信息。
95-
- `setup()`:初始化函数,队列开始时执行。
9695

9796
### UploadConfig
9897

@@ -102,14 +101,16 @@ interface UploadConfig {
102101
serverUrl?: string;
103102
logLevel?: LogLevel;
104103
protocol?: HttpProtocol;
104+
vars?: Record<string, string>;
105105
}
106106
```
107107

108108
- 上传配置接口,用于配置上传任务的相关参数。
109109
- `serverUrl`:服务器 URL,默认为 api.qiniu.com,专有云根据情况填写。
110-
- `logLevel`:日志级别。
110+
- `logLevel`:日志级别,默认为 NONE,不输出任何日志
111111
- `protocol`:HTTP 协议,默认 HTTPS。
112112
- `tokenProvider`:用于获取上传所需 token 的函数。
113+
- `vars`: 上传过程中是用的自定义变量。
113114

114115
### OnError
115116

packages/harmony/library/oh-package.json5

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@qiniu/upload",
3-
"version": "1.0.0-rc.2",
3+
"version": "1.0.0-rc.3",
44
"keywords": ["qiniu", "upload", "oss"],
55
"description": "Qiniu Cloud object storage upload sdk",
66
"repository": "https://github.com/qiniu/js-sdk.git",

packages/harmony/library/src/main/ets/components/file/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ export class UploadFile implements common.IFile {
5050
}
5151

5252
const initData = async (): Promise<common.Result<boolean>> => {
53+
if (!canIUse('SystemCapability.FileManagement.File.FileIO')) {
54+
return { error: new common.UploadError('FileSystemError', 'The current system api version does not support') }
55+
}
56+
5357
if (this.data.type === 'uri') {
5458
// 如果已经是 internal://cache/ 的文件 url 直接赋值更新
5559
if (this.data.data.startsWith('internal://cache/')) {

packages/harmony/library/src/main/ets/components/http/index.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ export class HttpClient implements HttpClient {
5252
private async request(url: string, options: RequestOptions): Promise<common.Result<common.HttpResponse>> {
5353
// 使用 requestApi 接口发送请求
5454
if (shouldUseUploadFile(options)) {
55+
if (!canIUse('SystemCapability.MiscServices.Upload')) {
56+
return { error: new common.UploadError('NetworkError', 'The current system api version does not support') }
57+
}
58+
5559
const files: requestApi.File[] = []
5660
const formData: requestApi.RequestData[] = []
5761
const bodyEntries = (options.body as common.HttpFormData).entries()
@@ -120,13 +124,12 @@ export class HttpClient implements HttpClient {
120124
})
121125
})
122126

123-
task.on('fail', states => {
124-
const firstState = states[0]
127+
task.on('fail', () => {
125128
return resolve({
126129
result: {
127-
data: firstState.message,
128-
code: firstState.responseCode,
129-
reqId: 'UploadFile api cannot get this value'
130+
data: '',
131+
code: responseCode,
132+
reqId: responseHeader['X-Reqid']
130133
}
131134
})
132135
})
@@ -144,6 +147,10 @@ export class HttpClient implements HttpClient {
144147
})
145148
}
146149

150+
if (!canIUse('SystemCapability.Communication.NetStack')) {
151+
return { error: new common.UploadError('NetworkError', 'The current system api version does not support') }
152+
}
153+
147154
let estimatedTime = 5 // 预估耗时默认为 5s
148155
let normalizedBody: string | ArrayBuffer | Object | undefined = options?.body as any
149156

packages/harmony/library/src/main/ets/components/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ function onCancel(task: common.UploadTask, listener: () => Promise<common.Result
2020
}
2121

2222
/**
23-
* @deprecated 系统原因一直无法调通,请使用分片上传
23+
* @deprecated 受限于当前版本的系统接口暂时无法获取上传之后的结果,优先考虑是用分片。
2424
*/
25-
export function createDirectUploadTask(context: ohCommon.Context, file: FileData, config: common.UploadConfig) {
25+
export function createDirectUploadTask(context: ohCommon.Context, file: FileData, config: common.UploadConfig) {
2626
const innerFile = new UploadFile(context, file)
2727
config.httpClient = config.httpClient ?? new HttpClient(context)
2828
const task = common.createDirectUploadTask(innerFile, config)

0 commit comments

Comments
 (0)