提交 1b0dffd7 编写于 作者: D DCloud_LXH

feat(App): uni.configMTLS

上级 cdb6d25a
import { hasOwn, isPlainObject } from '@vue/shared'
import { hasOwn, isPlainObject, toRawType } from '@vue/shared'
import { elemInArray, HTTP_METHODS } from '../../helpers/protocol'
export const API_REQUEST = 'request'
......@@ -99,3 +99,21 @@ export const RequestOptions: ApiOptions<API_TYPE_REQUEST> = {
},
},
}
export const API_CONFIG_MTLS = 'configMTLS'
export type API_TYPE_CONFIG_MTLS = typeof uni.configMTLS
export const ConfigMTLSProtocol: ApiProtocol<API_TYPE_CONFIG_MTLS> = {
certificates: {
type: Array,
required: true,
},
}
export const ConfigMTLSOptions: ApiOptions<API_TYPE_CONFIG_MTLS> = {
formatArgs: {
certificates(value: Parameters<API_TYPE_CONFIG_MTLS>[0]['certificates']) {
if (value.some((item) => toRawType(item.host) !== 'String')) {
return '参数配置错误,请确认后重试'
}
},
},
}
......@@ -5,6 +5,11 @@ import {
defineTaskApi,
RequestOptions,
RequestProtocol,
API_CONFIG_MTLS,
API_TYPE_CONFIG_MTLS,
defineAsyncApi,
ConfigMTLSOptions,
ConfigMTLSProtocol,
} from '@dcloudio/uni-api'
import { base64ToArrayBuffer } from '@dcloudio/uni-api'
import { requireNativePlugin } from '../plugin/requireNativePlugin'
......@@ -256,3 +261,30 @@ export const request = defineTaskApi<API_TYPE_REQUEST>(
RequestProtocol,
RequestOptions
)
type StreamConfigMTLSCB = {
type: 'success' | 'fail'
code: number
message: string
}
export const configMTLS = defineAsyncApi<API_TYPE_CONFIG_MTLS>(
API_CONFIG_MTLS,
({ certificates }, { resolve, reject }) => {
const stream = requireNativePlugin('stream')
stream.configMTLS(
certificates,
({ type, code, message }: StreamConfigMTLSCB) => {
switch (type) {
case 'success':
resolve({ code })
break
case 'fail':
reject(message, { code })
break
}
}
)
},
ConfigMTLSProtocol,
ConfigMTLSOptions
)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册