Skip to content

Commit db353ce

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

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

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: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ export class HttpClient implements HttpClient {
5050
constructor(private context: ohCommon.BaseContext) {}
5151

5252
private async request(url: string, options: RequestOptions): Promise<common.Result<common.HttpResponse>> {
53+
if (!canIUse('SystemCapability.Communication.NetStack')) {
54+
return { error: new common.UploadError('NetworkError', 'The current system api version does not support') }
55+
}
56+
5357
// 使用 requestApi 接口发送请求
5458
if (shouldUseUploadFile(options)) {
5559
const files: requestApi.File[] = []
@@ -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
})

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)