Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
良好的行为成为习惯
uni-app
提交
2b96c634
U
uni-app
项目概览
良好的行为成为习惯
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
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,发现更多精彩内容 >>
提交
2b96c634
编写于
12月 30, 2021
作者:
Q
qiang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(App): request with ArrayBuffer
上级
470056cd
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
108 addition
and
81 deletion
+108
-81
packages/uni-app-plus/dist/index.v3.js
packages/uni-app-plus/dist/index.v3.js
+56
-43
src/platforms/app-plus/service/api/network/request.js
src/platforms/app-plus/service/api/network/request.js
+52
-38
未找到文件。
packages/uni-app-plus/dist/index.v3.js
浏览文件 @
2b96c634
...
@@ -7543,46 +7543,59 @@ var serviceContext = (function () {
...
@@ -7543,46 +7543,59 @@ var serviceContext = (function () {
firstIpv4: firstIpv4,
firstIpv4: firstIpv4,
tls
tls
};
};
let withArrayBuffer;
if (method !== 'GET') {
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);
}
}
}
try {
const callback = ({
stream.fetch(options, ({
ok,
ok,
status,
status,
data,
data,
headers,
headers,
errorMsg
errorMsg
}) => {
}) => {
if (aborted) {
if (aborted) {
return
return
}
}
if (abortTimeout) {
if (abortTimeout) {
clearTimeout(abortTimeout);
clearTimeout(abortTimeout);
}
}
const statusCode = status;
const statusCode = status;
if (statusCode > 0) {
if (statusCode > 0) {
publishStateChange$1({
publishStateChange$1({
requestTaskId,
requestTaskId,
state: 'success',
state: 'success',
data: ok && responseType === 'arraybuffer' ? base64ToArrayBuffer$2(data) : data,
data: ok && responseType === 'arraybuffer' ? base64ToArrayBuffer$2(data) : data,
statusCode,
statusCode,
header: headers,
header: headers,
cookies: cookiesParse(headers)
cookies: cookiesParse(headers)
});
});
} else {
} else {
let errMsg = 'abort statusCode:' + statusCode;
let errMsg = 'abort statusCode:' + statusCode;
if (errorMsg) {
if (errorMsg) {
errMsg = errMsg + ' ' + errorMsg;
errMsg = errMsg + ' ' + errorMsg;
}
publishStateChange$1({
requestTaskId,
state: 'fail',
statusCode,
errMsg
});
}
}
});
publishStateChange$1({
requestTaskId,
state: 'fail',
statusCode,
errMsg
});
}
};
try {
if (withArrayBuffer) {
stream.fetchWithArrayBuffer({
'@type': 'binary',
base64: arrayBufferToBase64$2(data)
}, options, callback);
} else {
stream.fetch(options, callback);
}
requestTasks[requestTaskId] = {
requestTasks[requestTaskId] = {
abort () {
abort () {
aborted = true;
aborted = true;
...
@@ -15794,7 +15807,7 @@ var serviceContext = (function () {
...
@@ -15794,7 +15807,7 @@ var serviceContext = (function () {
var zstream = ZStream;
var zstream = ZStream;
var toString = Object.prototype.toString;
var toString
$1
= Object.prototype.toString;
/* Public constants ==========================================================*/
/* Public constants ==========================================================*/
/* ===========================================================================*/
/* ===========================================================================*/
...
@@ -15958,7 +15971,7 @@ var serviceContext = (function () {
...
@@ -15958,7 +15971,7 @@ var serviceContext = (function () {
if (typeof opt.dictionary === 'string') {
if (typeof opt.dictionary === 'string') {
// If we need to compress text, change encoding to utf8.
// If we need to compress text, change encoding to utf8.
dict = strings.string2buf(opt.dictionary);
dict = strings.string2buf(opt.dictionary);
} else if (toString.call(opt.dictionary) === '[object ArrayBuffer]') {
} else if (toString
$1
.call(opt.dictionary) === '[object ArrayBuffer]') {
dict = new Uint8Array(opt.dictionary);
dict = new Uint8Array(opt.dictionary);
} else {
} else {
dict = opt.dictionary;
dict = opt.dictionary;
...
@@ -16016,7 +16029,7 @@ var serviceContext = (function () {
...
@@ -16016,7 +16029,7 @@ var serviceContext = (function () {
if (typeof data === 'string') {
if (typeof data === 'string') {
// If we need to compress text, change encoding to utf8.
// If we need to compress text, change encoding to utf8.
strm.input = strings.string2buf(data);
strm.input = strings.string2buf(data);
} else if (toString.call(data) === '[object ArrayBuffer]') {
} else if (toString
$1
.call(data) === '[object ArrayBuffer]') {
strm.input = new Uint8Array(data);
strm.input = new Uint8Array(data);
} else {
} else {
strm.input = data;
strm.input = data;
...
@@ -18568,7 +18581,7 @@ var serviceContext = (function () {
...
@@ -18568,7 +18581,7 @@ var serviceContext = (function () {
var gzheader = GZheader;
var gzheader = GZheader;
var toString$
1
= Object.prototype.toString;
var toString$
2
= Object.prototype.toString;
/**
/**
* class Inflate
* class Inflate
...
@@ -18709,7 +18722,7 @@ var serviceContext = (function () {
...
@@ -18709,7 +18722,7 @@ var serviceContext = (function () {
// Convert data if needed
// Convert data if needed
if (typeof opt.dictionary === 'string') {
if (typeof opt.dictionary === 'string') {
opt.dictionary = strings.string2buf(opt.dictionary);
opt.dictionary = strings.string2buf(opt.dictionary);
} else if (toString$
1
.call(opt.dictionary) === '[object ArrayBuffer]') {
} else if (toString$
2
.call(opt.dictionary) === '[object ArrayBuffer]') {
opt.dictionary = new Uint8Array(opt.dictionary);
opt.dictionary = new Uint8Array(opt.dictionary);
}
}
if (opt.raw) { //In raw mode we need to set the dictionary early
if (opt.raw) { //In raw mode we need to set the dictionary early
...
@@ -18767,7 +18780,7 @@ var serviceContext = (function () {
...
@@ -18767,7 +18780,7 @@ var serviceContext = (function () {
if (typeof data === 'string') {
if (typeof data === 'string') {
// Only binary strings can be decompressed on practice
// Only binary strings can be decompressed on practice
strm.input = strings.binstring2buf(data);
strm.input = strings.binstring2buf(data);
} else if (toString$
1
.call(data) === '[object ArrayBuffer]') {
} else if (toString$
2
.call(data) === '[object ArrayBuffer]') {
strm.input = new Uint8Array(data);
strm.input = new Uint8Array(data);
} else {
} else {
strm.input = data;
strm.input = data;
...
...
src/platforms/app-plus/service/api/network/request.js
浏览文件 @
2b96c634
...
@@ -5,7 +5,8 @@ import {
...
@@ -5,7 +5,8 @@ import {
import
{
import
{
publish
,
publish
,
requireNativePlugin
,
requireNativePlugin
,
base64ToArrayBuffer
base64ToArrayBuffer
,
arrayBufferToBase64
}
from
'
../../bridge
'
}
from
'
../../bridge
'
import
{
import
{
...
@@ -107,46 +108,59 @@ export function createRequestTaskById (requestTaskId, {
...
@@ -107,46 +108,59 @@ export function createRequestTaskById (requestTaskId, {
firstIpv4
:
firstIpv4
,
firstIpv4
:
firstIpv4
,
tls
tls
}
}
let
withArrayBuffer
if
(
method
!==
'
GET
'
)
{
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
)
}
}
}
try
{
const
callback
=
({
stream
.
fetch
(
options
,
({
ok
,
ok
,
status
,
status
,
data
,
data
,
headers
,
headers
,
errorMsg
errorMsg
})
=>
{
})
=>
{
if
(
aborted
)
{
if
(
aborted
)
{
return
return
}
}
if
(
abortTimeout
)
{
if
(
abortTimeout
)
{
clearTimeout
(
abortTimeout
)
clearTimeout
(
abortTimeout
)
}
}
const
statusCode
=
status
const
statusCode
=
status
if
(
statusCode
>
0
)
{
if
(
statusCode
>
0
)
{
publishStateChange
({
publishStateChange
({
requestTaskId
,
requestTaskId
,
state
:
'
success
'
,
state
:
'
success
'
,
data
:
ok
&&
responseType
===
'
arraybuffer
'
?
base64ToArrayBuffer
(
data
)
:
data
,
data
:
ok
&&
responseType
===
'
arraybuffer
'
?
base64ToArrayBuffer
(
data
)
:
data
,
statusCode
,
statusCode
,
header
:
headers
,
header
:
headers
,
cookies
:
cookiesParse
(
headers
)
cookies
:
cookiesParse
(
headers
)
})
})
}
else
{
}
else
{
let
errMsg
=
'
abort statusCode:
'
+
statusCode
let
errMsg
=
'
abort statusCode:
'
+
statusCode
if
(
errorMsg
)
{
if
(
errorMsg
)
{
errMsg
=
errMsg
+
'
'
+
errorMsg
errMsg
=
errMsg
+
'
'
+
errorMsg
}
publishStateChange
({
requestTaskId
,
state
:
'
fail
'
,
statusCode
,
errMsg
})
}
}
})
publishStateChange
({
requestTaskId
,
state
:
'
fail
'
,
statusCode
,
errMsg
})
}
}
try
{
if
(
withArrayBuffer
)
{
stream
.
fetchWithArrayBuffer
({
'
@type
'
:
'
binary
'
,
base64
:
arrayBufferToBase64
(
data
)
},
options
,
callback
)
}
else
{
stream
.
fetch
(
options
,
callback
)
}
requestTasks
[
requestTaskId
]
=
{
requestTasks
[
requestTaskId
]
=
{
abort
()
{
abort
()
{
aborted
=
true
aborted
=
true
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录