Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jio
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Sven Franck
jio
Commits
b8faaed2
Commit
b8faaed2
authored
Jan 17, 2013
by
Sven Franck
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
webDav Storage GET new API and qunit tests added
parent
ad6aae46
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
79 additions
and
160 deletions
+79
-160
src/jio.storage/davstorage.js
src/jio.storage/davstorage.js
+22
-101
test/jiotests.js
test/jiotests.js
+57
-59
No files found.
src/jio.storage/davstorage.js
View file @
b8faaed2
...
@@ -400,15 +400,16 @@ jIO.addStorageType('dav', function (spec, my) {
...
@@ -400,15 +400,16 @@ jIO.addStorageType('dav', function (spec, my) {
};
};
/**
/**
* Loads a document from a distant dav storage.
* Get a document or attachment from distant storage
* @method get
* @method get
* @param {object} command The JIO command
*/
*/
that
.
get
=
function
(
command
)
{
that
.
get
=
function
(
command
)
{
var
doc
=
command
.
getDocId
()
,
var
doc
id
=
command
.
getDocId
(),
doc
,
secured_docid
;
secured_docid
;
// no docId
// no docId
if
(
!
(
typeof
doc
===
"
string
"
&&
doc
!==
""
))
{
if
(
!
(
typeof
doc
id
===
"
string
"
&&
docid
!==
""
))
{
that
.
error
({
that
.
error
({
"
status
"
:
405
,
"
status
"
:
405
,
"
statusText
"
:
"
Method Not Allowed
"
,
"
statusText
"
:
"
Method Not Allowed
"
,
...
@@ -432,22 +433,24 @@ jIO.addStorageType('dav', function (spec, my) {
...
@@ -432,22 +433,24 @@ jIO.addStorageType('dav', function (spec, my) {
secured_docid
=
priv
.
secureDocId
(
command
.
getDocId
());
secured_docid
=
priv
.
secureDocId
(
command
.
getDocId
());
url
=
priv
.
url
+
'
/
'
+
secured_docid
;
url
=
priv
.
url
+
'
/
'
+
secured_docid
;
// get attachment
if
(
typeof
command
.
getAttachmentId
()
===
"
string
"
)
{
if
(
typeof
command
.
getAttachmentId
()
===
"
string
"
)
{
secured_attachmentid
=
priv
.
secureDocId
(
command
.
getAttachmentId
());
attachment_url
=
url
+
'
/
'
+
secured_attachmentid
;
// get attachment
$
.
ajax
({
$
.
ajax
({
url
:
url
+
'
?_=
'
+
Date
.
now
(),
url
:
attachment_url
+
'
?_=
'
+
Date
.
now
(),
type
:
type
,
type
:
'
GET
'
,
data
:
command
.
getDoc
(),
async
:
true
,
async
:
true
,
crossdomain
:
true
,
dataType
:
'
text
'
,
crossdomain
:
true
,
headers
:
{
headers
:
{
Authorization
:
'
Basic
'
+
Base64
.
encode
(
Authorization
:
'
Basic
'
+
Base64
.
encode
(
priv
.
username
+
'
:
'
+
priv
.
password
priv
.
username
+
'
:
'
+
priv
.
password
)
)
},
},
// xhrFields: {withCredentials: 'true'},
success
:
function
(
response
)
{
success
:
function
(
response
)
{
that
.
success
(
response
)
doc
=
JSON
.
parse
(
response
);
that
.
success
(
doc
);
},
},
error
:
function
(
type
)
{
error
:
function
(
type
)
{
that
.
error
({
that
.
error
({
...
@@ -463,18 +466,21 @@ jIO.addStorageType('dav', function (spec, my) {
...
@@ -463,18 +466,21 @@ jIO.addStorageType('dav', function (spec, my) {
// get document
// get document
$
.
ajax
({
$
.
ajax
({
url
:
url
+
'
?_=
'
+
Date
.
now
(),
url
:
url
+
'
?_=
'
+
Date
.
now
(),
type
:
type
,
type
:
'
GET
'
,
data
:
command
.
getDoc
(),
async
:
true
,
async
:
true
,
crossdomain
:
true
,
dataType
:
'
text
'
,
crossdomain
:
true
,
headers
:
{
headers
:
{
Authorization
:
'
Basic
'
+
Base64
.
encode
(
Authorization
:
'
Basic
'
+
Base64
.
encode
(
priv
.
username
+
'
:
'
+
priv
.
password
priv
.
username
+
'
:
'
+
priv
.
password
)
)
},
},
// xhrFields: {withCredentials: 'true'},
success
:
function
(
response
)
{
success
:
function
(
response
)
{
that
.
success
(
response
)
// metadata_only should not be handled by jIO, as it is a
// webDav only option, shouldn't it?
// ditto for content_only
doc
=
JSON
.
parse
(
response
);
that
.
success
(
doc
);
},
},
error
:
function
(
type
)
{
error
:
function
(
type
)
{
that
.
error
({
that
.
error
({
...
@@ -489,91 +495,6 @@ jIO.addStorageType('dav', function (spec, my) {
...
@@ -489,91 +495,6 @@ jIO.addStorageType('dav', function (spec, my) {
}
}
};
};
that
.
get
=
function
(
command
)
{
var
secured_docid
=
priv
.
secureDocId
(
command
.
getDocId
()),
doc
=
{},
getContent
=
function
()
{
$
.
ajax
({
url
:
priv
.
url
+
'
/
'
+
priv
.
secured_username
+
'
/
'
+
priv
.
secured_application_name
+
'
/
'
+
secured_docid
+
'
?_=
'
+
Date
.
now
(),
type
:
"
GET
"
,
async
:
true
,
dataType
:
'
text
'
,
// TODO is it necessary ?
headers
:
{
'
Authorization
'
:
'
Basic
'
+
Base64
.
encode
(
priv
.
username
+
'
:
'
+
priv
.
password
)
},
// xhrFields: {withCredentials: 'true'}, // cross domain
success
:
function
(
content
)
{
doc
.
content
=
content
;
that
.
success
(
doc
);
},
error
:
function
(
type
)
{
type
.
error
=
type
.
statusText
;
// TODO : to lower case
if
(
type
.
status
===
404
)
{
type
.
message
=
'
Document "
'
+
command
.
getDocId
()
+
'
" not found.
'
;
type
.
reason
=
'
missing
'
;
that
.
error
(
type
);
}
else
{
type
.
reason
=
'
An error occured when trying to get "
'
+
command
.
getDocId
()
+
'
"
'
;
type
.
message
=
type
.
reason
+
'
.
'
;
that
.
retry
(
type
);
}
}
});
};
doc
.
_id
=
command
.
getDocId
();
// NOTE : if (command.getOption('content_only') { return getContent(); }
// Get properties
$
.
ajax
({
url
:
priv
.
url
+
'
/
'
+
priv
.
secured_username
+
'
/
'
+
priv
.
secured_application_name
+
'
/
'
+
secured_docid
+
'
?_=
'
+
Date
.
now
(),
type
:
"
PROPFIND
"
,
async
:
true
,
dataType
:
'
xml
'
,
headers
:
{
'
Authorization
'
:
'
Basic
'
+
Base64
.
encode
(
priv
.
username
+
'
:
'
+
priv
.
password
)
},
success
:
function
(
xmlData
)
{
$
(
xmlData
).
find
(
'
lp1
\\
:getlastmodified, getlastmodified
'
).
each
(
function
()
{
doc
.
_last_modified
=
new
Date
(
$
(
this
).
text
()).
getTime
();
}
);
$
(
xmlData
).
find
(
'
lp1
\\
:creationdate, creationdate
'
).
each
(
function
()
{
doc
.
_creation_date
=
new
Date
(
$
(
this
).
text
()).
getTime
();
}
);
if
(
!
command
.
getOption
(
'
metadata_only
'
))
{
getContent
();
}
else
{
that
.
success
(
doc
);
}
},
error
:
function
(
type
)
{
if
(
type
.
status
===
404
)
{
type
.
message
=
'
Cannot find "
'
+
command
.
getDocId
()
+
'
" informations.
'
;
type
.
reason
=
'
missing
'
;
that
.
error
(
type
);
}
else
{
type
.
reason
=
'
Cannot get "
'
+
command
.
getDocId
()
+
'
" informations
'
;
type
.
message
=
type
.
reason
+
'
.
'
;
that
.
retry
(
type
);
}
}
});
};
/**
/**
* Gets a document list from a distant dav storage.
* Gets a document list from a distant dav storage.
* @method allDocs
* @method allDocs
...
...
test/jiotests.js
View file @
b8faaed2
...
@@ -2121,7 +2121,7 @@ test ("PutAttachment", function(){
...
@@ -2121,7 +2121,7 @@ test ("PutAttachment", function(){
o
.
jio
=
JIO
.
newJio
({
o
.
jio
=
JIO
.
newJio
({
"
type
"
:
"
dav
"
,
"
type
"
:
"
dav
"
,
"
username
"
:
"
davput
"
,
"
username
"
:
"
davput
attm
"
,
"
password
"
:
"
checkpwd
"
,
"
password
"
:
"
checkpwd
"
,
"
url
"
:
"
https://ca-davstorage:8080
"
"
url
"
:
"
https://ca-davstorage:8080
"
});
});
...
@@ -2177,6 +2177,62 @@ test ("PutAttachment", function(){
...
@@ -2177,6 +2177,62 @@ test ("PutAttachment", function(){
// check for credentials in sinon
// check for credentials in sinon
});
});
test
(
"
Get
"
,
function
(){
var
o
=
generateTools
(
this
);
o
.
jio
=
JIO
.
newJio
({
"
type
"
:
"
dav
"
,
"
username
"
:
"
davget
"
,
"
password
"
:
"
checkpwd
"
,
"
url
"
:
"
https://ca-davstorage:8080
"
});
// get inexistent document
o
.
addFakeServerResponse
(
"
GET
"
,
"
get1
"
,
404
,
"
HTML RESPONSE
"
);
o
.
spy
(
o
,
"
status
"
,
404
,
"
Get non existing document
"
);
o
.
jio
.
get
(
"
get1
"
,
o
.
f
);
o
.
clock
.
tick
(
5000
);
o
.
server
.
respond
();
// get inexistent attachment
o
.
addFakeServerResponse
(
"
GET
"
,
"
get1/get2
"
,
404
,
"
HTML RESPONSE
"
);
o
.
spy
(
o
,
"
status
"
,
404
,
"
Get non existing attachment
"
);
o
.
jio
.
get
(
"
get1/get2
"
,
o
.
f
);
o
.
clock
.
tick
(
5000
);
o
.
server
.
respond
();
// get document
o
.
answer
=
JSON
.
stringify
({
"
_id
"
:
"
get3
"
,
"
title
"
:
"
some title
"
});
o
.
addFakeServerResponse
(
"
GET
"
,
"
get3
"
,
200
,
o
.
answer
);
o
.
spy
(
o
,
"
value
"
,
{
"
_id
"
:
"
get3
"
,
"
title
"
:
"
some title
"
},
"
Get document
"
);
o
.
jio
.
get
(
"
get3
"
,
o
.
f
);
o
.
clock
.
tick
(
5000
);
o
.
server
.
respond
();
// get inexistent attachment (document exists)
o
.
addFakeServerResponse
(
"
GET
"
,
"
get3/getx
"
,
404
,
"
HTML RESPONSE
"
);
o
.
spy
(
o
,
"
status
"
,
404
,
"
Get non existing attachment (doc exists)
"
);
o
.
jio
.
get
(
"
get3/getx
"
,
o
.
f
);
o
.
clock
.
tick
(
5000
);
o
.
server
.
respond
();
// get attachment
o
.
answer
=
JSON
.
stringify
({
"
_id
"
:
"
get4
"
,
"
title
"
:
"
some attachment
"
});
o
.
addFakeServerResponse
(
"
GET
"
,
"
get3/get4
"
,
200
,
o
.
answer
);
o
.
spy
(
o
,
"
value
"
,
{
"
_id
"
:
"
get4
"
,
"
title
"
:
"
some attachment
"
},
"
Get attachment
"
);
o
.
jio
.
get
(
"
get3/get4
"
,
o
.
f
);
o
.
clock
.
tick
(
5000
);
o
.
server
.
respond
();
o
.
jio
.
stop
();
// do the same tests live webDav-Server/simulate CORS
// check for credentials in sinon
});
/*
/*
// note: http errno:
// note: http errno:
// 200 OK
// 200 OK
...
@@ -2203,64 +2259,6 @@ test ("PutAttachment", function(){
...
@@ -2203,64 +2259,6 @@ test ("PutAttachment", function(){
[200,{},'']);
[200,{},'']);
*/
*/
/*
/*
test ('Document load', function () {
// Test if DavStorage can load documents.
var o = {};
o.davload = getXML('responsexml/davload'),
o.clock = this.sandbox.useFakeTimers();
o.clock.tick(base_tick);
o.t = this;
o.mytest = function (message,doc,errprop,errget) {
var server = o.t.sandbox.useFakeServer();
server.respondWith (
"PROPFIND",
/https:\/\/ca-davstorage:8080\/davload\/jiotests\/file(\?.*|$)/,
[errprop,{'Content-Type':'text/xml; charset="utf-8"'},
o.davload]);
server.respondWith (
"GET",
/https:\/\/ca-davstorage:8080\/davload\/jiotests\/file(\?.*|$)/,
[errget,{},'content']);
o.f = function (err,val) {
if (err) {
err = err.status;
}
deepEqual (err || val,doc,message);
};
o.t.spy(o,'f');
o.jio.get('file',{max_retry:1},o.f);
o.clock.tick(1000);
server.respond();
if (!o.f.calledOnce) {
if (o.f.called) {
ok(false, 'too much results');
} else {
ok(false, 'no response');
}
}
};
o.jio = JIO.newJio({type:'dav',username:'davload',
password:'checkpwd',
url:'https://ca-davstorage:8080',
application_name:'jiotests'});
// note: http errno:
// 200 OK
// 201 Created
// 204 No Content
// 207 Multi Status
// 403 Forbidden
// 404 Not Found
// load an inexistant document.
o.mytest ('load inexistant document',404,404,404);
// load a document.
o.mytest ('load document',{_id:'file',content:'content',
_last_modified:1335953199000,
_creation_date:1335953202000},207,200);
o.jio.stop();
});
test ('Get Document List', function () {
test ('Get Document List', function () {
// Test if DavStorage can get a list a document.
// Test if DavStorage can get a list a document.
...
...
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