Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jio-main
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Hardik Juneja
jio-main
Commits
6bc97e8e
Commit
6bc97e8e
authored
Jul 15, 2015
by
Klaus Wölfel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ERP5Storage: Add range and blob support
parent
9f23bfd0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
135 additions
and
14 deletions
+135
-14
src/jio.storage/erp5storage.js
src/jio.storage/erp5storage.js
+66
-14
test/jio.storage/erp5storage.tests.js
test/jio.storage/erp5storage.tests.js
+69
-0
No files found.
src/jio.storage/erp5storage.js
View file @
6bc97e8e
...
...
@@ -296,8 +296,10 @@
});
};
ERP5Storage
.
prototype
.
getAttachment
=
function
(
id
,
action
)
{
ERP5Storage
.
prototype
.
getAttachment
=
function
(
id
,
action
,
options
)
{
if
(
options
===
undefined
)
{
options
=
{};
}
if
(
action
===
"
view
"
)
{
if
(
this
.
_default_view_reference
===
undefined
)
{
throw
new
jIO
.
util
.
jIOError
(
...
...
@@ -335,21 +337,71 @@
if
(
action
.
indexOf
(
this
.
_url
)
===
0
)
{
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
jIO
.
util
.
ajax
({
"
type
"
:
"
GET
"
,
"
url
"
:
action
,
"
xhrFields
"
:
{
withCredentials
:
true
var
start
,
end
,
range
,
request_options
=
{
"
type
"
:
"
GET
"
,
"
dataType
"
:
"
blob
"
,
"
url
"
:
action
,
"
xhrFields
"
:
{
withCredentials
:
true
}
};
if
(
options
.
start
!==
undefined
||
options
.
end
!==
undefined
)
{
start
=
options
.
start
||
0
;
end
=
options
.
end
;
if
(
end
!==
undefined
&&
end
<
0
)
{
throw
new
jIO
.
util
.
jIOError
(
"
end must be positive
"
,
400
);
}
});
if
(
start
<
0
)
{
range
=
"
bytes=
"
+
start
;
}
else
if
(
end
===
undefined
)
{
range
=
"
bytes=
"
+
start
+
"
-
"
;
}
else
{
if
(
start
>
end
)
{
throw
new
jIO
.
util
.
jIOError
(
"
start is greater than end
"
,
400
);
}
range
=
"
bytes=
"
+
start
+
"
-
"
+
end
;
}
request_options
.
headers
=
{
Range
:
range
};
}
return
jIO
.
util
.
ajax
(
request_options
);
})
.
push
(
function
(
evt
)
{
var
result
=
JSON
.
parse
(
evt
.
target
.
responseText
);
result
.
_id
=
id
;
return
new
Blob
(
[
JSON
.
stringify
(
result
)],
{
"
type
"
:
evt
.
target
.
getResponseHeader
(
"
Content-Type
"
)}
);
var
content_type
=
evt
.
target
.
getResponseHeader
(
"
Content-Type
"
);
if
(
content_type
===
"
application/json
"
)
{
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
if
(
evt
.
target
.
responseText
===
undefined
)
{
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
jIO
.
util
.
readBlobAsText
(
evt
.
target
.
response
);
})
.
push
(
function
(
evt
)
{
return
evt
.
target
.
result
;
});
}
return
evt
.
target
.
responseText
;
})
.
push
(
function
(
response_text
)
{
var
result
=
JSON
.
parse
(
response_text
);
result
.
_id
=
id
;
return
new
Blob
(
[
JSON
.
stringify
(
result
)],
{
"
type
"
:
content_type
}
);
});
}
if
(
evt
.
target
.
response
===
undefined
)
{
return
new
Blob
(
[
evt
.
target
.
responseText
],
{
"
type
"
:
content_type
}
);
}
return
evt
.
target
.
response
;
});
}
throw
new
jIO
.
util
.
jIOError
(
"
ERP5: not support get attachment:
"
+
action
,
...
...
test/jio.storage/erp5storage.tests.js
View file @
6bc97e8e
...
...
@@ -917,6 +917,75 @@
});
});
test
(
"
getAttachment: non-JSON callable url
"
,
function
()
{
var
callable_url
=
domain
+
"
foobar
"
,
id
=
"
fake
"
,
server
=
this
.
server
;
this
.
server
.
respondWith
(
"
GET
"
,
callable_url
,
[
200
,
{
"
Content-Type
"
:
"
text/plain
"
},
"
foo
\n
baré
"
]);
stop
();
expect
(
8
);
this
.
jio
.
getAttachment
(
id
,
callable_url
)
.
then
(
function
(
result
)
{
equal
(
server
.
requests
.
length
,
1
);
equal
(
server
.
requests
[
0
].
method
,
"
GET
"
);
equal
(
server
.
requests
[
0
].
url
,
callable_url
);
equal
(
server
.
requests
[
0
].
requestBody
,
undefined
);
equal
(
server
.
requests
[
0
].
withCredentials
,
true
);
ok
(
result
instanceof
Blob
,
"
Data is Blob
"
);
deepEqual
(
result
.
type
,
"
text/plain
"
,
"
Check mimetype
"
);
return
jIO
.
util
.
readBlobAsText
(
result
);
})
.
then
(
function
(
result
)
{
var
expected
=
"
foo
\n
baré
"
;
equal
(
result
.
target
.
result
,
expected
,
"
Attachment correctly fetched
"
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
test
(
"
getAttachment: slicing parameters
"
,
function
()
{
var
callable_url
=
domain
+
"
foobar
"
,
id
=
"
fake
"
,
server
=
this
.
server
;
this
.
server
.
respondWith
(
"
GET
"
,
callable_url
,
[
200
,
{
"
Content-Type
"
:
"
application/octet-stream
"
},
"
foo
\n
baré
"
]);
stop
();
expect
(
8
);
this
.
jio
.
getAttachment
(
id
,
callable_url
,
{
start
:
123
,
end
:
456
})
.
then
(
function
(
result
)
{
equal
(
server
.
requests
.
length
,
1
);
equal
(
server
.
requests
[
0
].
method
,
"
GET
"
);
equal
(
server
.
requests
[
0
].
url
,
callable_url
);
equal
(
server
.
requests
[
0
].
requestBody
,
undefined
);
equal
(
server
.
requests
[
0
].
withCredentials
,
true
);
equal
(
server
.
requests
[
0
].
requestHeaders
.
Range
,
"
bytes=123-456
"
);
ok
(
result
instanceof
Blob
,
"
Data is Blob
"
);
deepEqual
(
result
.
type
,
"
application/octet-stream
"
,
"
Check mimetype
"
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
/////////////////////////////////////////////////////////////////
// erp5Storage.hasCapacity
/////////////////////////////////////////////////////////////////
...
...
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