Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
jio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
18
Merge Requests
18
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
jio
Commits
7f884987
Commit
7f884987
authored
Mar 20, 2019
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[node] Handle blob responseType
parent
d6408551
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
83 additions
and
23 deletions
+83
-23
src/node/jio.js
src/node/jio.js
+37
-12
test/jio.storage/dropboxstorage.tests.js
test/jio.storage/dropboxstorage.tests.js
+13
-9
test/jio.storage/erp5storage.tests.js
test/jio.storage/erp5storage.tests.js
+1
-2
test/node/ajax.tests.js
test/node/ajax.tests.js
+32
-0
No files found.
src/node/jio.js
View file @
7f884987
...
...
@@ -41,14 +41,42 @@
};
window
.
FormData
=
FormData
;
function
convertToBlob
(
promise
,
convert
)
{
if
(
!
convert
)
{
return
promise
;
}
var
result
;
if
(
promise
instanceof
RSVP
.
Queue
)
{
result
=
promise
;
}
else
{
result
=
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
promise
;
});
}
return
result
.
push
(
function
(
evt
)
{
evt
.
target
.
response
=
new
Blob
(
[
evt
.
target
.
response
||
evt
.
target
.
responseText
],
{
type
:
evt
.
target
.
getResponseHeader
(
'
Content-Type
'
)}
);
return
evt
;
});
}
originalAjax
=
jIO
.
util
.
ajax
;
jIO
.
util
.
ajax
=
function
ajax
(
param
)
{
var
result
,
need_convertion
=
(
param
.
dataType
===
'
blob
'
);
// Copy the param dict document (no need for deep copy) to
// allow tests to check them
param
=
Object
.
assign
({},
param
);
if
(
need_convertion
)
{
param
.
dataType
=
'
arraybuffer
'
;
}
if
(
param
.
data
instanceof
Blob
)
{
// Copy the param dict document (no need for deep copy) to
// allow tests to check them
param
=
Object
.
assign
({},
param
);
// Blob is not supported by xhr2, so convert to ArrayBuffer instead
re
turn
new
RSVP
.
Queue
()
re
sult
=
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
jIO
.
util
.
readBlobAsArrayBuffer
(
param
.
data
);
})
...
...
@@ -56,12 +84,7 @@
param
.
data
=
evt
.
target
.
result
;
return
originalAjax
(
param
);
});
}
if
(
param
.
data
instanceof
FormData
)
{
// Copy the param dict document (no need for deep copy) to
// allow tests to check them
param
=
Object
.
assign
({},
param
);
}
else
if
(
param
.
data
instanceof
FormData
)
{
// Implement minimal FormData for erp5storage
if
(
!
param
.
hasOwnProperty
(
'
headers
'
))
{
param
.
headers
=
{};
...
...
@@ -74,10 +97,12 @@
param
.
data
.
boundary
;
param
.
data
.
body
+=
'
--
'
+
param
.
data
.
boundary
+
'
--
\r\n
'
;
param
.
data
=
param
.
data
.
body
;
return
originalAjax
(
param
);
result
=
originalAjax
(
param
);
}
else
{
result
=
originalAjax
(
param
);
}
return
originalAjax
(
param
);
return
convertToBlob
(
result
,
need_convertion
);
};
}(
window
,
window
.
jIO
,
window
.
Blob
,
window
.
RSVP
));
...
...
test/jio.storage/dropboxstorage.tests.js
View file @
7f884987
...
...
@@ -1003,8 +1003,12 @@
type
:
"
dropbox
"
,
access_token
:
token
});
this
.
spy_ajax
=
sinon
.
spy
(
jIO
.
util
,
"
ajax
"
);
},
teardown
:
function
()
{
this
.
spy_ajax
.
restore
();
delete
this
.
spy_ajax
;
this
.
server
.
restore
();
delete
this
.
server
;
}
...
...
@@ -1075,7 +1079,7 @@
test
(
"
getAttachment document
"
,
function
()
{
var
url
=
"
https://content.dropboxapi.com/2/files/download
"
,
server
=
this
.
server
;
context
=
this
;
this
.
server
.
respondWith
(
"
POST
"
,
url
,
[
200
,
{
"
Content-Type
"
:
"
text/xplain
"
},
"
foo
\n
baré
"
]);
...
...
@@ -1088,20 +1092,20 @@
"
attachment1
"
)
.
then
(
function
(
result
)
{
equal
(
server
.
requests
.
length
,
1
);
equal
(
server
.
requests
[
0
].
method
,
"
POST
"
);
equal
(
server
.
request
s
[
0
].
url
,
url
);
equal
(
server
.
requests
[
0
].
status
,
200
);
equal
(
server
.
requests
[
0
].
requestBody
,
undefined
);
equal
(
server
.
requests
[
0
].
responseText
,
"
foo
\n
baré
"
);
deepEqual
(
server
.
requests
[
0
].
requestH
eaders
,
{
equal
(
context
.
spy_ajax
.
callCount
,
1
);
equal
(
context
.
spy_ajax
.
firstCall
.
args
[
0
].
type
,
"
POST
"
);
equal
(
context
.
spy_ajax
.
firstCall
.
arg
s
[
0
].
url
,
url
);
equal
(
context
.
spy_ajax
.
firstCall
.
args
[
0
].
data
,
undefined
);
equal
(
context
.
spy_ajax
.
firstCall
.
args
[
0
].
dataType
,
'
blob
'
);
deepEqual
(
context
.
spy_ajax
.
firstCall
.
args
[
0
].
xhrFields
,
undefined
);
deepEqual
(
context
.
spy_ajax
.
firstCall
.
args
[
0
].
h
eaders
,
{
"
Authorization
"
:
"
Bearer sample_token
"
,
"
Content-Type
"
:
"
text/plain;charset=utf-8
"
,
"
Dropbox-API-Arg
"
:
'
{"path":"/getAttachment1/attachment1"}
'
});
ok
(
result
instanceof
Blob
,
"
Data is Blob
"
);
deepEqual
(
result
.
type
,
"
text/xplain
"
,
"
Check mimetype
"
);
return
jIO
.
util
.
readBlobAsText
(
result
);
})
.
then
(
function
(
result
)
{
...
...
test/jio.storage/erp5storage.tests.js
View file @
7f884987
...
...
@@ -725,7 +725,7 @@
},
""
]);
stop
();
expect
(
1
7
);
expect
(
1
6
);
this
.
jio
.
putAttachment
(
id
,
...
...
@@ -748,7 +748,6 @@
equal
(
server
.
requests
[
0
].
method
,
"
POST
"
);
equal
(
server
.
requests
[
0
].
url
,
submit_url
);
equal
(
server
.
requests
[
0
].
status
,
204
);
equal
(
server
.
requests
[
0
].
responseType
,
"
blob
"
);
ok
(
context
.
spy
.
calledTwice
,
"
FormData.append count
"
+
context
.
spy
.
callCount
);
...
...
test/node/ajax.tests.js
View file @
7f884987
...
...
@@ -192,4 +192,36 @@
start
();
});
});
test
(
"
Blob responseType handling
"
,
function
()
{
stop
();
expect
(
6
);
var
url
=
"
https://www.example.org/com/bar
"
,
server
=
this
.
server
;
this
.
server
.
respondWith
(
"
POST
"
,
url
,
[
200
,
{},
'
OK
'
]);
return
new
RSVP
.
Queue
()
.
then
(
function
()
{
return
jIO
.
util
.
ajax
({
type
:
'
POST
'
,
url
:
url
,
dataType
:
'
blob
'
});
})
.
then
(
function
(
evt
)
{
equal
(
server
.
requests
.
length
,
1
);
equal
(
server
.
requests
[
0
].
method
,
"
POST
"
);
equal
(
server
.
requests
[
0
].
url
,
url
);
equal
(
server
.
requests
[
0
].
responseType
,
'
arraybuffer
'
);
equal
(
server
.
requests
[
0
].
responseText
,
'
OK
'
);
ok
(
evt
.
target
.
response
instanceof
Blob
,
evt
.
target
.
response
);
})
.
always
(
function
()
{
start
();
});
});
}(
jIO
,
QUnit
,
FormData
,
Blob
,
ArrayBuffer
));
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment