Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
yangkaifeng
uni-app
提交
5de1ba98
U
uni-app
项目概览
yangkaifeng
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
3
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
5de1ba98
编写于
12月 30, 2021
作者:
Q
qiang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(App): request with ArrayBuffer
上级
496de782
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
115 addition
and
71 deletion
+115
-71
packages/uni-app-plus/dist/uni-app-service.es.js
packages/uni-app-plus/dist/uni-app-service.es.js
+24
-11
packages/uni-app-plus/src/service/api/network/request.ts
packages/uni-app-plus/src/service/api/network/request.ts
+57
-60
packages/uni-app-plus/src/service/api/network/stream.d.ts
packages/uni-app-plus/src/service/api/network/stream.d.ts
+34
-0
未找到文件。
packages/uni-app-plus/dist/uni-app-service.es.js
浏览文件 @
5de1ba98
...
...
@@ -6397,7 +6397,7 @@ var serviceContext = (function (vue) {
var ZStream = zstream;
var toString$
1
= Object.prototype.toString;
var toString$
2
= Object.prototype.toString;
/* Public constants ==========================================================*/
/* ===========================================================================*/
...
...
@@ -6561,7 +6561,7 @@ var serviceContext = (function (vue) {
if (typeof opt.dictionary === 'string') {
// If we need to compress text, change encoding to utf8.
dict = strings.string2buf(opt.dictionary);
} else if (toString$
1
.call(opt.dictionary) === '[object ArrayBuffer]') {
} else if (toString$
2
.call(opt.dictionary) === '[object ArrayBuffer]') {
dict = new Uint8Array(opt.dictionary);
} else {
dict = opt.dictionary;
...
...
@@ -6619,7 +6619,7 @@ var serviceContext = (function (vue) {
if (typeof data === 'string') {
// If we need to compress text, change encoding to utf8.
strm.input = strings.string2buf(data);
} else if (toString$
1
.call(data) === '[object ArrayBuffer]') {
} else if (toString$
2
.call(data) === '[object ArrayBuffer]') {
strm.input = new Uint8Array(data);
} else {
strm.input = data;
...
...
@@ -9181,7 +9181,7 @@ var serviceContext = (function (vue) {
var GZheader = gzheader;
var toString = Object.prototype.toString;
var toString
$1
= Object.prototype.toString;
/**
* class Inflate
...
...
@@ -9322,7 +9322,7 @@ var serviceContext = (function (vue) {
// Convert data if needed
if (typeof opt.dictionary === 'string') {
opt.dictionary = strings.string2buf(opt.dictionary);
} else if (toString.call(opt.dictionary) === '[object ArrayBuffer]') {
} else if (toString
$1
.call(opt.dictionary) === '[object ArrayBuffer]') {
opt.dictionary = new Uint8Array(opt.dictionary);
}
if (opt.raw) { //In raw mode we need to set the dictionary early
...
...
@@ -9380,7 +9380,7 @@ var serviceContext = (function (vue) {
if (typeof data === 'string') {
// Only binary strings can be decompressed on practice
strm.input = strings.binstring2buf(data);
} else if (toString.call(data) === '[object ArrayBuffer]') {
} else if (toString
$1
.call(data) === '[object ArrayBuffer]') {
strm.input = new Uint8Array(data);
} else {
strm.input = data;
...
...
@@ -14920,20 +14920,24 @@ var serviceContext = (function (vue) {
const options = {
method,
url: url.trim(),
// weex 官方文档有误,headers 类型实际 object,用 string 类型会无响应
headers,
type: responseType === 'arraybuffer' ? 'base64' : 'text',
// weex 官方文档未说明实际支持 timeout,单位:ms
timeout: timeout || 6e5,
// 配置和weex模块内相反
sslVerify: !sslVerify,
firstIpv4: firstIpv4,
tls,
};
let withArrayBuffer = false;
if (method !== 'GET') {
options.body = typeof data === 'string' ? data : JSON.stringify(data);
if (toString.call(data) === '[object ArrayBuffer]') {
withArrayBuffer = true;
}
else {
options.body = typeof data === 'string' ? data : JSON.stringify(data);
}
}
stream.fetch(options,
({ ok, status, data, headers, errorMsg, }) => {
const callback =
({ ok, status, data, headers, errorMsg, }) => {
if (aborted) {
return;
}
...
...
@@ -14958,7 +14962,16 @@ var serviceContext = (function (vue) {
}
reject(errMsg);
}
});
};
if (withArrayBuffer) {
stream.fetchWithArrayBuffer({
'@type': 'binary',
base64: arrayBufferToBase64(data)
}, options, callback);
}
else {
stream.fetch(options, callback);
}
return new RequestTask({
abort() {
aborted = true;
...
...
packages/uni-app-plus/src/service/api/network/request.ts
浏览文件 @
5de1ba98
...
...
@@ -11,17 +11,10 @@ import {
ConfigMTLSOptions
,
ConfigMTLSProtocol
,
}
from
'
@dcloudio/uni-api
'
import
{
base64ToArrayBuffer
}
from
'
@dcloudio/uni-api
'
import
{
base64ToArrayBuffer
,
arrayBufferToBase64
}
from
'
@dcloudio/uni-api
'
import
{
requireNativePlugin
}
from
'
../plugin/requireNativePlugin
'
import
{
Stream
,
FetchOptions
,
FetchCallback
,
FetchHeaders
}
from
'
./stream
'
type
Type
=
'
base64
'
|
'
text
'
type
Headers
=
Record
<
string
,
string
>
type
Options
=
UniApp
.
RequestOptions
&
{
tls
:
any
headers
:
Headers
type
:
Type
body
?:
string
|
Data
}
interface
RequestTasks
{
abort
:
Function
}
...
...
@@ -139,8 +132,8 @@ export const request = defineTaskApi<API_TYPE_REQUEST>(
data
=
JSON
.
stringify
(
data
)
}
const
stream
=
requireNativePlugin
(
'
stream
'
)
const
headers
:
Headers
=
{}
const
stream
:
Stream
=
requireNativePlugin
(
'
stream
'
)
const
headers
:
Fetch
Headers
=
{}
let
abortTimeout
:
ReturnType
<
typeof
setTimeout
>
let
aborted
:
boolean
let
hasContentType
=
false
...
...
@@ -183,70 +176,74 @@ export const request = defineTaskApi<API_TYPE_REQUEST>(
},
timeout
+
200
)
// TODO +200 发消息到原生层有时间开销,以后考虑由原生层回调超时
}
const
options
:
Options
=
{
const
options
:
Fetch
Options
=
{
method
,
url
:
url
.
trim
(),
// weex 官方文档有误,headers 类型实际 object,用 string 类型会无响应
headers
,
type
:
responseType
===
'
arraybuffer
'
?
'
base64
'
:
'
text
'
,
// weex 官方文档未说明实际支持 timeout,单位:ms
timeout
:
timeout
||
6
e5
,
// 配置和weex模块内相反
sslVerify
:
!
sslVerify
,
firstIpv4
:
firstIpv4
,
tls
,
}
let
withArrayBuffer
:
boolean
=
false
if
(
method
!==
'
GET
'
)
{
options
.
body
=
typeof
data
===
'
string
'
?
data
:
JSON
.
stringify
(
data
)
if
(
toString
.
call
(
data
)
===
'
[object ArrayBuffer]
'
)
{
withArrayBuffer
=
true
}
else
{
options
.
body
=
typeof
data
===
'
string
'
?
data
:
JSON
.
stringify
(
data
)
}
}
stream
.
fetch
(
options
,
({
ok
,
status
,
data
,
headers
,
errorMsg
,
}:
{
ok
:
boolean
status
:
number
data
:
string
headers
:
Headers
errorMsg
:
string
})
=>
{
if
(
aborted
)
{
return
}
if
(
abortTimeout
)
{
clearTimeout
(
abortTimeout
)
}
const
statusCode
=
status
if
(
statusCode
>
0
)
{
resolve
(
formatResponse
(
{
data
:
ok
&&
responseType
===
'
arraybuffer
'
?
base64ToArrayBuffer
(
data
)
:
data
,
statusCode
,
header
:
headers
,
cookies
:
cookiesParse
(
headers
),
},
args
)
const
callback
:
FetchCallback
=
({
ok
,
status
,
data
,
headers
,
errorMsg
,
})
=>
{
if
(
aborted
)
{
return
}
if
(
abortTimeout
)
{
clearTimeout
(
abortTimeout
)
}
const
statusCode
=
status
if
(
statusCode
>
0
)
{
resolve
(
formatResponse
(
{
data
:
ok
&&
responseType
===
'
arraybuffer
'
?
base64ToArrayBuffer
(
data
)
:
data
,
statusCode
,
header
:
headers
,
cookies
:
cookiesParse
(
headers
),
},
args
)
}
else
{
let
errMsg
=
'
abort statusCode:
'
+
statusCode
if
(
errorMsg
)
{
errMsg
=
errMsg
+
'
'
+
errorMsg
}
reject
(
errMsg
)
)
}
else
{
let
errMsg
=
'
abort statusCode:
'
+
statusCode
if
(
errorMsg
)
{
errMsg
=
errMsg
+
'
'
+
errorMsg
}
reject
(
errMsg
)
}
)
}
if
(
withArrayBuffer
)
{
stream
.
fetchWithArrayBuffer
(
{
'
@type
'
:
'
binary
'
,
base64
:
arrayBufferToBase64
(
data
as
ArrayBuffer
),
},
options
,
callback
)
}
else
{
stream
.
fetch
(
options
,
callback
)
}
return
new
RequestTask
({
abort
()
{
...
...
packages/uni-app-plus/src/service/api/network/stream.d.ts
0 → 100644
浏览文件 @
5de1ba98
export
type
FetchHeaders
=
Record
<
string
,
string
>
export
interface
FetchOptions
{
method
?:
string
url
:
string
// weex 官方文档有误,headers 类型实际 object,用 string 类型会无响应
headers
?:
FetchHeaders
type
?:
'
base64
'
|
'
text
'
// weex 官方文档未说明实际支持 timeout,单位:ms
timeout
?:
number
sslVerify
?:
boolean
firstIpv4
?:
boolean
tls
?:
any
body
?:
string
|
Data
}
export
interface
FetchResult
{
ok
:
boolean
status
:
number
data
:
string
headers
:
FetchHeaders
errorMsg
:
string
}
export
type
FetchCallback
=
(
result
:
FetchResult
)
=>
void
export
interface
FetchArrayBuffer
{
'
@type
'
:
'
binary
'
base64
:
string
}
export
interface
Stream
{
fetch
:
(
options
:
FetchOptions
,
callback
:
FetchCallback
)
=>
void
fetchWithArrayBuffer
:
(
body
:
FetchArrayBuffer
,
options
:
FetchOptions
,
callback
:
FetchCallback
)
=>
void
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录