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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Ivan Tyagov
jio
Commits
a91c592e
Commit
a91c592e
authored
Apr 08, 2013
by
Tristan Cavelier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Dav storage completed + tests
parent
9e5c6ae6
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
757 additions
and
522 deletions
+757
-522
src/jio.storage/davstorage.js
src/jio.storage/davstorage.js
+431
-398
test/jiotests.js
test/jiotests.js
+299
-121
test/responsexml/davlist
test/responsexml/davlist
+27
-3
No files found.
src/jio.storage/davstorage.js
View file @
a91c592e
...
@@ -204,6 +204,34 @@ jIO.addStorageType("dav", function (spec, my) {
...
@@ -204,6 +204,34 @@ jIO.addStorageType("dav", function (spec, my) {
return
doc_id
;
return
doc_id
;
};
};
/**
* Convert a file name to a document id (and attachment id if there)
* @method fileNameToIds
* @param {string} file_name The file name to convert
* @return {array} ["document id", "attachment id"] or ["document id"]
*/
priv
.
fileNameToIds
=
function
(
file_name
)
{
var
separator_index
=
-
1
,
split
=
file_name
.
split
(
"
.
"
);
split
.
slice
(
0
,
-
1
).
forEach
(
function
(
file_name_part
,
index
)
{
if
(
file_name_part
.
slice
(
-
1
)
!==
"
_
"
)
{
separator_index
=
index
;
}
});
if
(
separator_index
===
-
1
)
{
return
[
priv
.
restoreName
(
priv
.
restoreName
(
file_name
).
split
(
"
_.
"
).
join
(
"
.
"
))];
}
return
[
priv
.
restoreName
(
priv
.
restoreName
(
split
.
slice
(
0
,
separator_index
+
1
).
join
(
"
.
"
)
).
split
(
"
_.
"
).
join
(
"
.
"
)),
priv
.
restoreName
(
priv
.
restoreName
(
split
.
slice
(
separator_index
+
1
).
join
(
"
.
"
)
).
split
(
"
_.
"
).
join
(
"
.
"
))
];
};
/**
/**
* Removes the last character if it is a "/". "/a/b/c/" become "/a/b/c"
* Removes the last character if it is a "/". "/a/b/c/" become "/a/b/c"
* @method removeSlashIfLast
* @method removeSlashIfLast
...
@@ -246,13 +274,8 @@ jIO.addStorageType("dav", function (spec, my) {
...
@@ -246,13 +274,8 @@ jIO.addStorageType("dav", function (spec, my) {
*/
*/
priv
.
ajax
=
function
(
doc_id
,
attachment_id
,
method
,
ajax_object
)
{
priv
.
ajax
=
function
(
doc_id
,
attachment_id
,
method
,
ajax_object
)
{
var
new_ajax_object
=
JSON
.
parse
(
JSON
.
stringify
(
ajax_object
)
||
"
{}
"
);
var
new_ajax_object
=
JSON
.
parse
(
JSON
.
stringify
(
ajax_object
)
||
"
{}
"
);
console
.
log
(
priv
.
makeAjaxObject
(
priv
.
idsToFileName
(
doc_id
,
attachment_id
),
method
,
new_ajax_object
));
return
$
.
ajax
(
priv
.
makeAjaxObject
(
return
$
.
ajax
(
priv
.
makeAjaxObject
(
priv
.
idsToFileName
(
doc_id
,
attachment_id
),
priv
.
idsToFileName
(
doc_id
||
''
,
attachment_id
),
method
,
method
,
new_ajax_object
new_ajax_object
));
//.always(then || function () {});
));
//.always(then || function () {});
...
@@ -281,7 +304,7 @@ jIO.addStorageType("dav", function (spec, my) {
...
@@ -281,7 +304,7 @@ jIO.addStorageType("dav", function (spec, my) {
error
.
statusText
=
"
Conflicts
"
;
error
.
statusText
=
"
Conflicts
"
;
break
;
break
;
case
24
:
case
24
:
error
.
statusText
=
"
Broken
Document
"
;
error
.
statusText
=
"
Corrupted
Document
"
;
break
;
break
;
}
}
error
.
error
=
error
.
statusText
.
toLowerCase
().
split
(
"
"
).
join
(
"
_
"
);
error
.
error
=
error
.
statusText
.
toLowerCase
().
split
(
"
"
).
join
(
"
_
"
);
...
@@ -345,39 +368,229 @@ jIO.addStorageType("dav", function (spec, my) {
...
@@ -345,39 +368,229 @@ jIO.addStorageType("dav", function (spec, my) {
// DAV REQUESTS //
// DAV REQUESTS //
/**
/**
* Retrieve a document
* Retrieve a document
file
* @method dav.getDocument
* @method dav.getDocument
* @param {string} doc_id The document id
* @param {string} doc_id The document id
* @param {function} then The callback(err, response)
*/
*/
dav
.
getDocument
=
function
(
doc_id
)
{
dav
.
getDocument
=
function
(
doc_id
)
{
var
doc
,
jql
=
priv
.
makeJQLikeCallback
();
var
doc
,
jql
=
priv
.
makeJQLikeCallback
()
,
error
=
null
;
priv
.
ajax
(
doc_id
,
undefined
,
"
GET
"
).
always
(
function
(
one
,
state
,
three
)
{
priv
.
ajax
(
doc_id
,
undefined
,
"
GET
"
).
always
(
function
(
one
,
state
,
three
)
{
if
(
state
!==
"
success
"
)
{
if
(
state
!==
"
success
"
)
{
jql
.
respond
(
priv
.
ajaxErrorToJioError
(
error
=
priv
.
ajaxErrorToJioError
(
one
,
one
,
"
Cannot retrieve document
"
,
"
Cannot retrieve document
"
,
"
Unknown error
"
"
Unknown
"
);
if
(
one
.
status
===
404
)
{
error
.
reason
=
"
Not Found
"
;
}
return
jql
.
respond
(
error
,
undefined
);
}
try
{
doc
=
JSON
.
parse
(
one
);
}
catch
(
e
)
{
return
jql
.
respond
(
priv
.
createError
(
24
,
"
Cannot parse document
"
,
"
Document is corrupted
"
),
undefined
);
),
undefined
);
}
else
{
}
try
{
// document health is good
doc
=
JSON
.
parse
(
one
);
return
jql
.
respond
(
undefined
,
doc
);
}
catch
(
e
)
{
});
return
jql
.
respond
(
priv
.
createError
(
return
jql
.
to_return
;
24
,
};
"
Cannot parse document
"
,
"
Document is broken
"
/**
),
undefined
);
* Retrieve an attachment file
* @method dav.getAttachment
* @param {string} doc_id The document id
* @param {string} attachment_id The attachment id
*/
dav
.
getAttachment
=
function
(
doc_id
,
attachment_id
)
{
var
jql
=
priv
.
makeJQLikeCallback
(),
error
=
null
;
priv
.
ajax
(
doc_id
,
attachment_id
,
"
GET
"
).
always
(
function
(
one
,
state
,
three
)
{
if
(
state
!==
"
success
"
)
{
error
=
priv
.
ajaxErrorToJioError
(
one
,
"
Cannot retrieve attachment
"
,
"
Unknown
"
);
if
(
one
.
status
===
404
)
{
error
.
reason
=
"
Not Found
"
;
}
}
// document health is good
return
jql
.
respond
(
error
,
undefined
);
jql
.
respond
(
undefined
,
doc
);
}
}
return
jql
.
respond
(
undefined
,
one
);
});
});
return
jql
.
to_return
;
return
jql
.
to_return
;
};
};
/**
* Uploads a document file
* @method dav.putDocument
* @param {object} doc The document object
*/
dav
.
putDocument
=
function
(
doc
)
{
dav
.
putDocument
=
function
(
doc
)
{
// TODO
var
jql
=
priv
.
makeJQLikeCallback
();
priv
.
ajax
(
doc
.
_id
,
undefined
,
"
PUT
"
,
{
"
dataType
"
:
"
text
"
,
"
data
"
:
JSON
.
stringify
(
doc
)
}).
always
(
function
(
one
,
state
,
three
)
{
if
(
state
!==
"
success
"
)
{
return
jql
.
respond
(
priv
.
ajaxErrorToJioError
(
one
,
"
Cannot upload document
"
,
"
Unknown
"
),
undefined
);
}
jql
.
respond
(
undefined
,
{
"
ok
"
:
true
,
"
id
"
:
doc
.
_id
});
});
return
jql
.
to_return
;
};
/**
* Uploads an attachment file
* @method dav.putAttachment
* @param {string} doc_id The document id
* @param {string} attachment_id The attachment id
* @param {string} data The attachment data
*/
dav
.
putAttachment
=
function
(
doc_id
,
attachment_id
,
data
)
{
var
jql
=
priv
.
makeJQLikeCallback
();
priv
.
ajax
(
doc_id
,
attachment_id
,
"
PUT
"
,
{
"
dataType
"
:
"
text
"
,
"
data
"
:
data
}).
always
(
function
(
one
,
state
,
three
)
{
if
(
state
!==
"
success
"
)
{
return
jql
.
respond
(
priv
.
ajaxErrorToJioError
(
one
,
"
Cannot upload attachment
"
,
"
Unknown
"
),
undefined
);
}
return
jql
.
respond
(
undefined
,
{
"
ok
"
:
true
,
"
id
"
:
doc_id
,
"
attachment
"
:
attachment_id
});
});
return
jql
.
to_return
;
};
/**
* Deletes a document file
* @method dav.removeDocument
* @param {string} doc_id The document id
*/
dav
.
removeDocument
=
function
(
doc_id
)
{
var
jql
=
priv
.
makeJQLikeCallback
(),
error
=
null
;
priv
.
ajax
(
doc_id
,
undefined
,
"
DELETE
"
).
always
(
function
(
one
,
state
,
three
)
{
if
(
state
!==
"
success
"
)
{
error
=
priv
.
ajaxErrorToJioError
(
one
,
"
Cannot delete document
"
,
"
Unknown
"
);
if
(
one
.
status
===
404
)
{
error
.
reason
=
"
Not Found
"
;
}
return
jql
.
respond
(
error
,
undefined
);
}
jql
.
respond
(
undefined
,
{
"
ok
"
:
true
,
"
id
"
:
doc_id
});
});
return
jql
.
to_return
;
};
/**
* Deletes an attachment file
* @method dav.removeAttachment
* @param {string} doc_id The document id
* @param {string} attachment_id The attachment id
*/
dav
.
removeAttachment
=
function
(
doc_id
,
attachment_id
)
{
var
jql
=
priv
.
makeJQLikeCallback
(),
error
=
null
;
priv
.
ajax
(
doc_id
,
attachment_id
,
"
DELETE
"
).
always
(
function
(
one
,
state
,
three
)
{
if
(
state
!==
"
success
"
)
{
error
=
priv
.
ajaxErrorToJioError
(
one
,
"
Cannot delete attachment
"
,
"
Unknown
"
);
if
(
one
.
status
===
404
)
{
error
.
reason
=
"
Not Found
"
;
}
return
jql
.
respond
(
error
,
undefined
);
}
jql
.
respond
(
undefined
,
{
"
ok
"
:
true
,
"
id
"
:
doc_id
});
});
return
jql
.
to_return
;
};
/**
* Get a list of document file
* @method dav.allDocs
*/
dav
.
allDocs
=
function
()
{
var
jql
=
priv
.
makeJQLikeCallback
(),
rows
=
[];
priv
.
ajax
(
undefined
,
undefined
,
"
PROPFIND
"
,
{
"
dataType
"
:
"
xml
"
,
"
headers
"
:
{
"
Depth
"
:
1
}
}).
always
(
function
(
one
,
state
,
three
)
{
var
response
,
len
;
if
(
state
!==
"
success
"
)
{
return
jql
.
respond
(
priv
.
ajaxErrorToJioError
(
one
,
"
Cannot get the document list
"
,
"
Unknown
"
),
undefined
);
}
response
=
$
(
one
).
find
(
"
D
\\
:response, response
"
);
len
=
response
.
length
;
if
(
len
===
1
)
{
return
jql
.
respond
({
"
total_rows
"
:
0
,
"
rows
"
:
[]});
}
response
.
each
(
function
(
i
,
data
)
{
var
row
;
if
(
i
>
0
)
{
// exclude parent folder
row
=
{
"
id
"
:
""
,
"
key
"
:
""
,
"
value
"
:
{}
};
$
(
data
).
find
(
"
D
\\
:href, href
"
).
each
(
function
()
{
row
.
id
=
$
(
this
).
text
().
split
(
'
/
'
).
slice
(
-
1
)[
0
];
row
.
id
=
priv
.
fileNameToIds
(
row
.
id
);
if
(
row
.
id
.
length
!==
1
)
{
row
=
undefined
;
}
else
{
row
.
id
=
row
.
id
[
0
];
row
.
key
=
row
.
id
;
}
});
if
(
row
!==
undefined
)
{
rows
.
push
(
row
);
}
}
});
jql
.
respond
(
undefined
,
{
"
total_rows
"
:
rows
.
length
,
"
rows
"
:
rows
});
});
return
jql
.
to_return
;
};
};
// JIO COMMANDS //
// JIO COMMANDS //
...
@@ -414,46 +627,32 @@ jIO.addStorageType("dav", function (spec, my) {
...
@@ -414,46 +627,32 @@ jIO.addStorageType("dav", function (spec, my) {
*/
*/
that
.
post
=
function
(
command
)
{
that
.
post
=
function
(
command
)
{
var
doc_id
=
command
.
getDocId
()
||
priv
.
generateUuid
();
var
doc_id
=
command
.
getDocId
()
||
priv
.
generateUuid
();
priv
.
ajax
(
doc_id
,
undefined
,
"
GET
"
).
always
(
function
(
one
,
state
,
thre
e
)
{
dav
.
getDocument
(
doc_id
).
always
(
function
(
err
,
respons
e
)
{
if
(
state
!==
"
success
"
)
{
if
(
err
)
{
if
(
one
.
status
===
404
)
{
if
(
err
.
status
===
404
)
{
// the document does not already exist
// the document does not already exist
// updating document
// updating document
priv
.
ajax
(
doc_id
,
undefined
,
"
PUT
"
,
{
var
doc
=
command
.
cloneDoc
();
"
dataType
"
:
"
text
"
,
doc
.
_id
=
doc_id
;
"
data
"
:
JSON
.
stringify
(
command
.
cloneDoc
())
return
dav
.
putDocument
(
doc
).
always
(
function
(
err
,
response
)
{
}).
always
(
function
(
one
,
state
,
three
)
{
if
(
err
)
{
if
(
state
!==
"
success
"
)
{
return
that
.
retry
(
err
);
// an error occured
that
.
retry
(
priv
.
ajaxErrorToJioError
(
one
,
"
An error occured when trying to PUT data
"
,
"
Unknown
"
));
}
else
{
// document updated
that
.
success
({
"
ok
"
:
true
,
"
id
"
:
doc_id
});
}
}
return
that
.
success
(
response
);
});
});
}
else
{
// an error occured
that
.
retry
(
priv
.
ajaxErrorToJioError
(
one
,
"
An error occured when trying to GET data
"
,
"
Unknown
"
));
}
}
}
else
{
if
(
err
.
status
===
24
)
{
// the document already exists
return
that
.
error
(
err
);
that
.
error
(
priv
.
createError
(
}
405
,
// an error occured
"
Cannot create document
"
,
return
that
.
retry
(
err
);
"
Document already exists
"
));
}
}
// the document already exists
return
that
.
error
(
priv
.
createError
(
405
,
"
Cannot create document
"
,
"
Document already exists
"
));
});
});
};
};
...
@@ -463,25 +662,13 @@ jIO.addStorageType("dav", function (spec, my) {
...
@@ -463,25 +662,13 @@ jIO.addStorageType("dav", function (spec, my) {
* @param {object} command The JIO command
* @param {object} command The JIO command
*/
*/
that
.
put
=
function
(
command
)
{
that
.
put
=
function
(
command
)
{
var
doc_id
=
command
.
getDocId
();
dav
.
putDocument
(
command
.
cloneDoc
()).
always
(
function
(
err
,
response
)
{
priv
.
ajax
(
doc_id
,
undefined
,
"
PUT
"
,
{
if
(
err
)
{
"
dataType
"
:
"
text
"
,
"
data
"
:
JSON
.
stringify
(
command
.
cloneDoc
())
}).
always
(
function
(
one
,
state
,
three
)
{
if
(
state
!==
"
success
"
)
{
// an error occured
// an error occured
that
.
retry
(
priv
.
ajaxErrorToJioError
(
return
that
.
retry
(
err
);
one
,
"
Cannot update document
"
,
"
Unknown error
"
));
}
else
{
// document updated
that
.
success
({
"
ok
"
:
true
,
"
id
"
:
doc_id
});
}
}
// document updated
return
that
.
success
(
response
);
});
});
};
};
...
@@ -493,70 +680,42 @@ jIO.addStorageType("dav", function (spec, my) {
...
@@ -493,70 +680,42 @@ jIO.addStorageType("dav", function (spec, my) {
that
.
putAttachment
=
function
(
command
)
{
that
.
putAttachment
=
function
(
command
)
{
var
doc
=
null
,
doc_id
=
command
.
getDocId
(),
attachment_id
,
tmp
;
var
doc
=
null
,
doc_id
=
command
.
getDocId
(),
attachment_id
,
tmp
;
attachment_id
=
command
.
getAttachmentId
();
attachment_id
=
command
.
getAttachmentId
();
priv
.
ajax
(
doc_id
,
undefined
,
"
GET
"
).
always
(
function
(
one
,
state
,
thre
e
)
{
dav
.
getDocument
(
doc_id
).
always
(
function
(
err
,
respons
e
)
{
if
(
state
!==
"
success
"
)
{
if
(
err
)
{
// document not found or error
// document not found or error
tmp
=
that
.
retry
;
tmp
=
that
.
retry
;
if
(
one
.
status
===
404
)
{
if
(
err
.
status
===
404
||
err
.
status
===
24
)
{
tmp
=
that
.
error
;
tmp
=
that
.
error
;
}
}
tmp
(
priv
.
ajaxErrorToJioError
(
return
tmp
(
err
);
one
,
}
"
Cannot update document
"
,
doc
=
response
;
"
Unknown error
"
doc
.
_attachments
=
doc
.
_attachments
||
{};
));
doc
.
_attachments
[
attachment_id
]
=
{
}
else
{
"
length
"
:
command
.
getAttachmentLength
(),
try
{
"
digest
"
:
"
md5-
"
+
command
.
md5SumAttachmentData
(),
doc
=
JSON
.
parse
(
one
);
"
content_type
"
:
command
.
getAttachmentMimeType
()
}
catch
(
e
)
{
};
return
that
.
error
(
priv
.
createError
(
// put the attachment
24
,
dav
.
putAttachment
(
"
Cannot upload attachment
"
,
doc_id
,
"
Document is broken
"
attachment_id
,
));
command
.
getAttachmentData
()
).
always
(
function
(
err
,
response
)
{
if
(
err
)
{
// an error occured
return
that
.
retry
(
err
);
}
}
// document health is good
// update the document
doc
.
_attachments
=
doc
.
_attachments
||
{};
dav
.
putDocument
(
doc
).
always
(
function
(
err
,
response
)
{
doc
.
_attachments
[
attachment_id
]
=
{
if
(
err
)
{
"
length
"
:
command
.
getAttachmentLength
(),
return
that
.
retry
(
err
);
"
digest
"
:
"
md5-
"
+
command
.
md5SumAttachmentData
(),
"
content_type
"
:
command
.
getAttachmentMimeType
()
};
// put the attachment
priv
.
ajax
(
doc_id
,
attachment_id
,
"
PUT
"
,
{
"
dataType
"
:
"
text
"
,
"
data
"
:
command
.
getAttachmentData
()
}).
always
(
function
(
one
,
state
,
three
)
{
if
(
state
!==
"
success
"
)
{
// an error occured
that
.
retry
(
priv
.
ajaxErrorToJioError
(
one
,
"
An error occured when trying to PUT data
"
,
"
Unknown
"
));
}
else
{
// update the document
priv
.
ajax
(
doc_id
,
undefined
,
"
PUT
"
,
{
"
dataType
"
:
"
text
"
,
"
data
"
:
JSON
.
stringify
(
doc
)
}).
always
(
function
(
one
,
state
,
three
)
{
if
(
state
!==
"
success
"
)
{
that
.
retry
(
priv
.
ajaxErrorToJioError
(
one
,
"
An error occured when trying to PUT data
"
,
"
Unknown
"
));
}
else
{
that
.
success
({
"
ok
"
:
true
,
"
id
"
:
doc_id
,
"
attachment
"
:
attachment_id
});
}
});
}
}
response
.
attachment
=
attachment_id
;
return
that
.
success
(
response
);
});
});
}
}
);
});
});
};
};
...
@@ -567,6 +726,27 @@ jIO.addStorageType("dav", function (spec, my) {
...
@@ -567,6 +726,27 @@ jIO.addStorageType("dav", function (spec, my) {
*/
*/
that
.
get
=
function
(
command
)
{
that
.
get
=
function
(
command
)
{
dav
.
getDocument
(
command
.
getDocId
()).
always
(
function
(
err
,
response
)
{
dav
.
getDocument
(
command
.
getDocId
()).
always
(
function
(
err
,
response
)
{
if
(
err
)
{
if
(
err
.
status
===
404
||
err
.
status
===
24
)
{
return
that
.
error
(
err
);
}
return
that
.
retry
(
err
);
}
return
that
.
success
(
response
);
});
};
/**
* Get an attachment
* @method getAttachment
* @param {object} command The JIO command
*/
that
.
getAttachment
=
function
(
command
)
{
dav
.
getAttachment
(
command
.
getDocId
(),
command
.
getAttachmentId
()
).
always
(
function
(
err
,
response
)
{
if
(
err
)
{
if
(
err
)
{
if
(
err
.
status
===
404
)
{
if
(
err
.
status
===
404
)
{
return
that
.
error
(
err
);
return
that
.
error
(
err
);
...
@@ -578,176 +758,100 @@ jIO.addStorageType("dav", function (spec, my) {
...
@@ -578,176 +758,100 @@ jIO.addStorageType("dav", function (spec, my) {
};
};
/**
/**
* Remove a document
or attachment
* Remove a document
* @method remove
* @method remove
* @param {object} command The JIO command
* @param {object} command The JIO command
*/
*/
that
.
_remove
=
function
(
command
)
{
that
.
remove
=
function
(
command
)
{
var
docid
=
command
.
getDocId
(),
doc
,
url
,
var
doc_id
=
command
.
getDocId
(),
count
=
0
,
end
;
secured_docid
,
secured_attachmentid
,
attachment_url
,
end
=
function
()
{
attachment_list
=
[],
i
,
j
,
k
=
1
,
deleteAttachment
,
ajax_object
;
count
-=
1
;
if
(
count
===
0
)
{
if
(
priv
.
support
(
docid
))
{
that
.
success
({
"
ok
"
:
true
,
"
id
"
:
doc_id
});
return
;
}
}
};
dav
.
getDocument
(
doc_id
).
always
(
function
(
err
,
response
)
{
secured_docid
=
priv
.
secureDocId
(
command
.
getDocId
());
var
attachment_id
=
null
;
url
=
priv
.
url
+
'
/
'
+
priv
.
underscoreFileExtenisons
(
secured_docid
);
if
(
err
)
{
if
(
err
.
status
===
404
)
{
// remove attachment
return
that
.
error
(
err
);
if
(
typeof
command
.
getAttachmentId
()
===
"
string
"
)
{
secured_attachmentid
=
priv
.
secureDocId
(
command
.
getAttachmentId
());
attachment_url
=
url
+
'
.
'
+
priv
.
underscoreFileExtenisons
(
secured_attachmentid
);
ajax_object
=
{
url
:
attachment_url
+
'
?_=
'
+
Date
.
now
(),
type
:
"
DELETE
"
,
success
:
function
()
{
// retrieve underlying document
ajax_object
=
{
url
:
url
+
'
?_=
'
+
Date
.
now
(),
type
:
"
GET
"
,
dataType
:
"
text
"
,
success
:
function
(
response
)
{
// underlying document
doc
=
JSON
.
parse
(
response
);
// update doc._attachments
if
(
typeof
doc
.
_attachments
===
"
object
"
)
{
if
(
typeof
doc
.
_attachments
[
command
.
getAttachmentId
()]
===
"
object
"
)
{
delete
doc
.
_attachments
[
command
.
getAttachmentId
()];
if
(
priv
.
objectIsEmpty
(
doc
.
_attachments
))
{
delete
doc
.
_attachments
;
}
// PUT back to server
ajax_object
=
{
url
:
url
+
'
?_=
'
+
Date
.
now
(),
type
:
'
PUT
'
,
data
:
JSON
.
stringify
(
doc
),
success
:
function
()
{
that
.
success
({
"
ok
"
:
true
,
"
id
"
:
command
.
getDocId
()
+
'
/
'
+
command
.
getAttachmentId
()
});
},
error
:
function
()
{
that
.
error
(
priv
.
createError
(
409
,
"
Cannot modify document
"
,
"
Error saving attachment
"
));
}
};
priv
.
ajax
(
ajax_object
);
}
else
{
// sure this if-else is needed?
that
.
error
(
priv
.
createError
(
404
,
"
Cannot find document
"
,
"
Error updating attachment
"
));
}
}
else
{
// no attachments, we are done
that
.
success
({
"
ok
"
:
true
,
"
id
"
:
command
.
getDocId
()
+
'
/
'
+
command
.
getAttachmentId
()
});
}
},
error
:
function
()
{
that
.
error
(
priv
.
createError
(
404
,
"
Cannot find the document
"
,
"
Document does not exist
"
));
}
};
priv
.
ajax
(
ajax_object
);
},
error
:
function
()
{
that
.
error
(
priv
.
createError
(
404
,
"
Cannot find the attachment
"
,
"
Error removing attachment
"
));
}
}
};
if
(
err
.
status
!==
24
)
{
// 24 -> corrupted document
priv
.
ajax
(
ajax_object
);
return
that
.
retry
(
err
);
// remove document incl. all attachments
}
}
else
{
response
=
{};
ajax_object
=
{
}
url
:
url
+
'
?_=
'
+
Date
.
now
(),
count
+=
2
;
type
:
'
GET
'
,
dav
.
removeDocument
(
doc_id
).
always
(
function
(
err
,
response
)
{
dataType
:
'
text
'
,
if
(
err
)
{
success
:
function
(
response
)
{
if
(
err
.
status
===
404
)
{
var
x
;
return
that
.
error
(
err
);
doc
=
JSON
.
parse
(
response
);
// prepare attachment loop
if
(
typeof
doc
.
_attachments
===
"
object
"
)
{
// prepare list of attachments
for
(
x
in
doc
.
_attachments
)
{
if
(
doc
.
_attachments
.
hasOwnProperty
(
x
))
{
attachment_list
.
push
(
x
);
}
}
}
}
// delete document
return
that
.
retry
(
err
);
ajax_object
=
{
url
:
url
+
'
?_=
'
+
Date
.
now
(),
type
:
'
DELETE
'
,
success
:
function
()
{
j
=
attachment_list
.
length
;
// no attachments, done
if
(
j
===
0
)
{
that
.
success
({
"
ok
"
:
true
,
"
id
"
:
command
.
getDocId
()
});
}
else
{
deleteAttachment
=
function
(
attachment_url
,
j
,
k
)
{
ajax_object
=
{
url
:
attachment_url
+
'
?_=
'
+
Date
.
now
(),
type
:
'
DELETE
'
,
success
:
function
()
{
// all deleted, return response, need k as async couter
if
(
j
===
k
)
{
that
.
success
({
"
ok
"
:
true
,
"
id
"
:
command
.
getDocId
()
});
}
else
{
k
+=
1
;
}
},
error
:
function
()
{
that
.
error
(
priv
.
createError
(
404
,
"
Cannot find attachment
"
,
"
Error removing attachment
"
));
}
};
priv
.
ajax
(
ajax_object
);
};
for
(
i
=
0
;
i
<
j
;
i
+=
1
)
{
secured_attachmentid
=
priv
.
secureDocId
(
attachment_list
[
i
]);
attachment_url
=
url
+
'
.
'
+
priv
.
underscoreFileExtenisons
(
secured_attachmentid
);
deleteAttachment
(
attachment_url
,
j
,
k
);
}
}
},
error
:
function
()
{
that
.
error
(
priv
.
createError
(
404
,
"
Cannot find the document
"
,
"
Error removing document
"
));
}
};
priv
.
ajax
(
ajax_object
);
},
error
:
function
()
{
that
.
error
(
priv
.
createError
(
404
,
"
Cannot find the document
"
,
"
Document does not exist
"
));
}
}
};
return
end
();
priv
.
ajax
(
ajax_object
);
});
}
for
(
attachment_id
in
response
.
_attachments
)
{
if
(
response
.
_attachments
.
hasOwnProperty
(
attachment_id
))
{
count
+=
1
;
dav
.
removeAttachment
(
doc_id
,
attachment_id
).
always
(
end
);
}
}
end
();
});
};
/**
* Remove an attachment
* @method removeAttachment
* @param {object} command The JIO command
*/
that
.
removeAttachment
=
function
(
command
)
{
var
doc_id
=
command
.
getDocId
(),
doc
,
attachment_id
;
attachment_id
=
command
.
getAttachmentId
();
dav
.
getDocument
(
doc_id
).
always
(
function
(
err
,
response
)
{
var
still_has_attachments
;
if
(
err
)
{
if
(
err
.
status
===
404
||
err
.
status
===
24
)
{
return
that
.
error
(
err
);
}
return
that
.
retry
(
err
);
}
doc
=
response
;
if
(
typeof
(
doc
.
_attachments
||
{})[
attachment_id
]
!==
"
object
"
)
{
return
that
.
error
(
priv
.
createError
(
404
,
"
Cannot remove attachment
"
,
"
Not Found
"
));
}
delete
doc
.
_attachments
[
attachment_id
];
// check if there is still attachments
for
(
still_has_attachments
in
doc
.
_attachments
)
{
if
(
doc
.
_attachments
.
hasOwnProperty
(
still_has_attachments
))
{
break
;
}
}
if
(
still_has_attachments
===
undefined
)
{
delete
doc
.
_attachments
;
}
doc
.
_id
=
doc_id
;
dav
.
putDocument
(
doc
).
always
(
function
(
err
,
response
)
{
if
(
err
)
{
return
that
.
retry
(
err
);
}
dav
.
removeAttachment
(
doc_id
,
attachment_id
).
always
(
function
(
err
,
response
)
{
that
.
success
({
"
ok
"
:
true
,
"
id
"
:
doc_id
,
"
attachment
"
:
attachment_id
});
});
});
});
};
};
/**
/**
...
@@ -757,112 +861,41 @@ jIO.addStorageType("dav", function (spec, my) {
...
@@ -757,112 +861,41 @@ jIO.addStorageType("dav", function (spec, my) {
* @method allDocs
* @method allDocs
* @param {object} command The JIO command
* @param {object} command The JIO command
*/
*/
//{
that
.
allDocs
=
function
(
command
)
{
// "total_rows": 4,
var
count
=
0
,
end
,
rows
;
// "rows": [
end
=
function
()
{
// {
count
-=
1
;
// "id": "otherdoc",
if
(
count
===
0
)
{
// "key": "otherdoc",
that
.
success
(
rows
);
// "value": {
}
// "rev": "1-3753476B70A49EA4D8C9039E7B04254C"
// }
// },{...}
// ]
//}
that
.
_allDocs
=
function
(
command
)
{
var
rows
=
[],
url
,
am
=
priv
.
newAsyncModule
(),
o
=
{},
ajax_object
;
o
.
getContent
=
function
(
file
)
{
var
docid
=
priv
.
secureDocId
(
file
.
id
),
url
=
priv
.
url
+
'
/
'
+
docid
;
ajax_object
=
{
url
:
url
+
'
?_=
'
+
Date
.
now
(),
type
:
'
GET
'
,
dataType
:
'
text
'
,
success
:
function
(
content
)
{
file
.
doc
=
JSON
.
parse
(
content
);
rows
.
push
(
file
);
am
.
call
(
o
,
'
success
'
);
},
error
:
function
(
type
)
{
that
.
error
(
priv
.
createError
(
404
,
"
Cannot find the document
"
,
"
Can't get document from storage
"
));
am
.
call
(
o
,
'
error
'
,
[
type
]);
}
};
priv
.
ajax
(
ajax_object
);
};
};
o
.
getDocumentList
=
function
()
{
dav
.
allDocs
().
always
(
function
(
err
,
response
)
{
url
=
priv
.
url
+
'
/
'
;
if
(
err
)
{
ajax_object
=
{
return
that
.
retry
(
err
);
url
:
url
+
'
?_=
'
+
Date
.
now
(),
}
type
:
"
PROPFIND
"
,
if
(
command
.
getOption
(
"
include_docs
"
)
===
true
)
{
dataType
:
"
xml
"
,
count
+=
1
;
headers
:
{
depth
:
'
1
'
},
rows
=
response
;
success
:
function
(
xml
)
{
rows
.
rows
.
forEach
(
function
(
row
)
{
var
response
=
$
(
xml
).
find
(
'
D
\\
:response, response
'
),
count
+=
1
;
len
=
response
.
length
;
dav
.
getDocument
(
row
.
id
if
(
len
===
1
)
{
).
always
(
function
(
err
,
response
)
{
return
am
.
call
(
o
,
'
success
'
);
if
(
err
)
{
}
if
(
err
.
status
===
404
||
err
.
status
===
24
)
{
am
.
wait
(
o
,
'
success
'
,
len
-
2
);
return
that
.
error
(
err
);
response
.
each
(
function
(
i
,
data
)
{
if
(
i
>
0
)
{
// exclude parent folder
var
file
=
{
value
:
{}
};
$
(
data
).
find
(
'
D
\\
:href, href
'
).
each
(
function
()
{
var
split
=
$
(
this
).
text
().
split
(
'
/
'
);
file
.
id
=
split
[
split
.
length
-
1
];
file
.
id
=
priv
.
restoreSlashes
(
file
.
id
);
file
.
key
=
file
.
id
;
});
if
(
command
.
getOption
(
'
include_docs
'
))
{
am
.
call
(
o
,
'
getContent
'
,
[
file
]);
}
else
{
rows
.
push
(
file
);
am
.
call
(
o
,
'
success
'
);
}
}
return
that
.
retry
(
err
);
}
}
row
.
doc
=
response
;
end
();
});
});
},
});
error
:
function
(
type
)
{
end
();
that
.
error
(
priv
.
createError
(
404
,
}
else
{
"
Cannot find the document
"
,
"
Can't get document list
"
that
.
success
(
response
);
));
}
am
.
call
(
o
,
'
retry
'
,
[
type
]);
});
}
};
priv
.
ajax
(
ajax_object
);
};
o
.
retry
=
function
(
error
)
{
am
.
neverCall
(
o
,
'
retry
'
);
am
.
neverCall
(
o
,
'
success
'
);
am
.
neverCall
(
o
,
'
error
'
);
that
.
retry
(
error
);
};
o
.
error
=
function
(
error
)
{
am
.
neverCall
(
o
,
'
retry
'
);
am
.
neverCall
(
o
,
'
success
'
);
am
.
neverCall
(
o
,
'
error
'
);
that
.
error
(
error
);
};
o
.
success
=
function
()
{
am
.
neverCall
(
o
,
'
retry
'
);
am
.
neverCall
(
o
,
'
success
'
);
am
.
neverCall
(
o
,
'
error
'
);
that
.
success
({
total_rows
:
rows
.
length
,
rows
:
rows
});
};
// first get the XML list
am
.
call
(
o
,
'
getDocumentList
'
);
};
};
priv
.
__init__
(
spec
);
priv
.
__init__
(
spec
);
...
...
test/jiotests.js
View file @
a91c592e
...
@@ -3634,21 +3634,6 @@ test ("Put", function(){
...
@@ -3634,21 +3634,6 @@ test ("Put", function(){
o
.
tick
(
o
);
o
.
tick
(
o
);
o
.
server
.
restore
();
o
.
server
.
restore
();
o
.
jio
.
stop
();
});
test
(
"
PutAttachment
"
,
function
(){
var
o
=
generateTools
(
this
);
o
.
jio
=
JIO
.
newJio
({
"
type
"
:
"
dav
"
,
"
url
"
:
"
https://ca-davstorage:8080
"
,
"
auth_type
"
:
"
basic
"
,
"
username
"
:
"
admin
"
,
"
password
"
:
"
pwd
"
});
// putAttachment without document id => 20 Id Required
// putAttachment without document id => 20 Id Required
o
.
spy
(
o
,
"
status
"
,
20
,
"
PutAttachment without doc id -> 20
"
);
o
.
spy
(
o
,
"
status
"
,
20
,
"
PutAttachment without doc id -> 20
"
);
o
.
jio
.
putAttachment
({
"
_attachment
"
:
"
body.html
"
},
o
.
f
);
o
.
jio
.
putAttachment
({
"
_attachment
"
:
"
body.html
"
},
o
.
f
);
...
@@ -3777,97 +3762,241 @@ test ("Get", function(){
...
@@ -3777,97 +3762,241 @@ test ("Get", function(){
o
.
tick
(
o
);
o
.
tick
(
o
);
o
.
server
.
restore
();
o
.
server
.
restore
();
// get inexistent attachment
o
.
server
=
sinon
.
fakeServer
.
create
();
o
.
server
.
respondWith
(
"
GET
"
,
/https:
\/\/
ca-davstorage:8080
\/
http:%252F%252F100%2525_
\.
json
\.
body_
\.
html/
,
[
404
,
{
"
Content-Type
"
:
"
text/html
"
},
"
<h1>Not Found</h1>
"
]
);
o
.
spy
(
o
,
"
status
"
,
404
,
"
Get inexistent attachment -> 404
"
);
o
.
jio
.
getAttachment
({
"
_id
"
:
"
http://100%.json
"
,
"
_attachment
"
:
"
body.html
"
},
{
"
max_retry
"
:
1
},
o
.
f
);
o
.
clock
.
tick
(
1000
);
o
.
server
.
respond
();
o
.
tick
(
o
);
o
.
server
.
restore
();
// get attachment
o
.
server
=
sinon
.
fakeServer
.
create
();
o
.
server
.
respondWith
(
"
GET
"
,
/https:
\/\/
ca-davstorage:8080
\/
http:%252F%252F100%2525_
\.
json
\.
body_
\.
html/
,
[
200
,
{
"
Content-Type
"
:
"
text/plain
"
},
"
My Attachment Content
"
]
);
o
.
spy
(
o
,
"
value
"
,
"
My Attachment Content
"
,
"
Get attachment
"
);
o
.
jio
.
getAttachment
({
"
_id
"
:
"
http://100%.json
"
,
"
_attachment
"
:
"
body.html
"
},
{
"
max_retry
"
:
1
},
o
.
f
);
o
.
clock
.
tick
(
1000
);
o
.
server
.
respond
();
o
.
tick
(
o
);
o
.
server
.
restore
();
o
.
jio
.
stop
();
o
.
jio
.
stop
();
});
});
/*
test
(
"
Remove
"
,
function
(){
test
(
"
Remove
"
,
function
(){
var
o
=
generateTools
(
this
);
var
o
=
generateTools
(
this
);
o
.
jio
=
JIO
.
newJio
({
o
.
jio
=
JIO
.
newJio
({
"type": "dav",
"
type
"
:
"
dav
"
,
"username": "davremove",
"
url
"
:
"
https://ca-davstorage:8080
"
,
"password": "checkpwd",
"
auth_type
"
:
"
basic
"
,
"url": "https://ca-davstorage:8080"
"
username
"
:
"
admin
"
,
"
password
"
:
"
pwd
"
});
});
// remove inexistent document
// remove inexistent document
o.addFakeServerResponse("dav", "GET", "remove1", 404, "HTML RESPONSE");
o
.
server
=
sinon
.
fakeServer
.
create
();
o.spy(o, "status", 404, "Remove non existening document");
o
.
server
.
respondWith
(
o.jio.remove({"_id": "remove1"}, o.f);
"
GET
"
,
o.clock.tick(5000);
/https:
\/\/
ca-davstorage:8080
\/
http:%252F%252F100%2525_
\.
json/
,
[
404
,
{
"
Content-Type
"
:
"
text/html
"
},
"
<h1>Not Found</h1>
"
]
);
o
.
spy
(
o
,
"
status
"
,
404
,
"
Remove inexistent document -> 404
"
);
o
.
jio
.
remove
({
"
_id
"
:
"
http://100%.json
"
},
{
"
max_retry
"
:
1
},
o
.
f
);
o
.
clock
.
tick
(
1000
);
o
.
server
.
respond
();
o
.
server
.
respond
();
o
.
tick
(
o
);
o
.
server
.
restore
();
// remove inexistent document/attachment
// remove document
o.addFakeServerResponse("dav", "GET", "remove1.remove2", 404, "HTML" +
o
.
server
=
sinon
.
fakeServer
.
create
();
"RESPONSE");
o
.
server
.
respondWith
(
o.spy(o, "status", 404, "Remove inexistent document/attachment");
"
GET
"
,
o.jio.remove({"_id": "remove1/remove2"}, o.f);
/https:
\/\/
ca-davstorage:8080
\/
http:%252F%252F100%2525_
\.
json/
,
o.clock.tick(5000);
[
200
,
{
"
Content-Type
"
:
"
text/html
"
},
"
{My corrupted document}
"
]
);
o
.
server
.
respondWith
(
"
DELETE
"
,
/https:
\/\/
ca-davstorage:8080
\/
http:%252F%252F100%2525_
\.
json/
,
[
200
,
{
"
Content-Type
"
:
"
text/plain
"
},
"
<h1>Deleted</h1>
"
]
);
o
.
spy
(
o
,
"
value
"
,
{
"
ok
"
:
true
,
"
id
"
:
"
http://100%.json
"
},
"
Remove document
"
);
o
.
jio
.
remove
({
"
_id
"
:
"
http://100%.json
"
},
{
"
max_retry
"
:
1
},
o
.
f
);
o
.
clock
.
tick
(
1000
);
o
.
server
.
respond
();
o
.
server
.
respond
();
o
.
tick
(
o
);
o
.
server
.
restore
();
// remove document
// remove inexistent attachment
o.answer = JSON.stringify({"_id": "remove3", "title": "some doc"});
o
.
server
=
sinon
.
fakeServer
.
create
();
o.addFakeServerResponse("dav", "GET", "remove3", 200, o.answer);
o
.
server
.
respondWith
(
o.addFakeServerResponse("dav", "DELETE", "remove3", 200, "HTML RESPONSE");
"
GET
"
,
o.spy(o, "value", {"ok": true, "id": "remove3"}, "Remove document");
/https:
\/\/
ca-davstorage:8080
\/
http:%252F%252F100%2525_
\.
json/
,
o.jio.remove({"_id": "remove3"}, o.f);
[
o.clock.tick(5000);
200
,
{
"
Content-Type
"
:
"
text/plain
"
},
"
{}
"
]
);
o
.
spy
(
o
,
"
status
"
,
404
,
"
Remove inexistent attachment -> 404
"
);
o
.
jio
.
removeAttachment
({
"
_id
"
:
"
http://100%.json
"
,
"
_attachment
"
:
"
body.html
"
},
{
"
max_retry
"
:
1
},
o
.
f
);
o
.
clock
.
tick
(
1000
);
o
.
server
.
respond
();
o
.
server
.
respond
();
o
.
tick
(
o
);
// o.server.respond();
// o.server.respond();
o
.
server
.
restore
();
o.answer = JSON.stringify({
"_id": "remove4",
"title": "some doc",
"_attachments": {
"remove5": {
"length": 4,
"digest": "md5-d41d8cd98f00b204e9800998ecf8427e"
}
}
});
// remove attachment
// remove attachment
o.addFakeServerResponse("dav", "GET", "remove4", 200, o.answer);
o
.
server
=
sinon
.
fakeServer
.
create
();
o.addFakeServerResponse("dav", "PUT", "remove4", 201, "HTML RESPONSE");
o
.
server
.
respondWith
(
o.addFakeServerResponse("dav", "DELETE", "remove4.remove5", 200, "HTML"+
"
GET
"
,
"RESPONSE");
/https:
\/\/
ca-davstorage:8080
\/
http:%252F%252F100%2525_
\.
json/
,
o.spy(o, "value", {"ok": true, "id": "remove4/remove5"},
[
"Remove attachment");
200
,
o.jio.remove({"_id": "remove4/remove5"}, o.f);
{
"
Content-Type
"
:
"
text/plain
"
},
o.clock.tick(5000);
JSON
.
stringify
({
"
_attachments
"
:
{
"
body.html
"
:
{
"
length
"
:
32
,
"
digest
"
:
"
md5-dontcare
"
,
"
content_type
"
:
"
text/html
"
}
}
})
]
);
o
.
server
.
respondWith
(
"
PUT
"
,
/https:
\/\/
ca-davstorage:8080
\/
http:%252F%252F100%2525_
\.
json/
,
[
200
,
{
"
Content-Type
"
:
"
text/html
"
},
"
<h1>OK</h1>
"
]
);
o
.
server
.
respondWith
(
"
DELETE
"
,
/https:
\/\/
ca-davstorage:8080
\/
http:%252F%252F100%2525_
\.
json.body_
\.
html/
,
[
200
,
{
"
Content-Type
"
:
"
text/html
"
},
"
<h1>OK</h1>
"
]
);
o
.
spy
(
o
,
"
value
"
,
{
"
ok
"
:
true
,
"
id
"
:
"
http://100%.json
"
,
"
attachment
"
:
"
body.html
"
},
"
Remove attachment
"
);
o
.
jio
.
removeAttachment
({
"
_id
"
:
"
http://100%.json
"
,
"
_attachment
"
:
"
body.html
"
},
{
"
max_retry
"
:
1
},
o
.
f
);
o
.
clock
.
tick
(
1000
);
o
.
server
.
respond
();
o
.
server
.
respond
();
o
.
tick
(
o
);
o
.
server
.
restore
();
o.answer = JSON.stringify({
// remove document with multiple attachments
"_id": "remove6",
o
.
server
=
sinon
.
fakeServer
.
create
();
"title": "some other doc",
o
.
server
.
respondWith
(
"_attachments": {
"
GET
"
,
"remove7": {
/https:
\/\/
ca-davstorage:8080
\/
http:%252F%252F100%2525_
\.
json/
,
"length": 4,
[
"digest": "md5-d41d8cd98f00b204e9800998ecf8427e"
200
,
},
{
"
Content-Type
"
:
"
text/html
"
},
"remove8": {
JSON
.
stringify
({
"length": 4,
"
_attachments
"
:
{
"digest": "md5-e41d8cd98f00b204e9800998ecf8427e"
"
body.html
"
:
{
"
length
"
:
32
,
"
digest
"
:
"
md5-dontcare
"
,
"
content_type
"
:
"
text/html
"
},
},
"remove9": {
"
other
"
:
{
"length": 4,
"
length
"
:
3
,
"digest": "md5-f41d8cd98f00b204e9800998ecf8427e"
"
digest
"
:
"
md5-dontcare-again
"
,
"
content_type
"
:
"
text/plain
"
}
}
}
}
});
})
// remove document with multiple attachments
]
o.addFakeServerResponse("dav", "GET", "remove6", 200, o.answer);
);
o.addFakeServerResponse("dav", "DELETE", "remove6.remove7", 200, "HTML"+
o
.
server
.
respondWith
(
"RESPONSE");
"
DELETE
"
,
o.addFakeServerResponse("dav", "DELETE", "remove6.remove8", 200, "HTML"+
/https:
\/\/
ca-davstorage:8080
\/
http:%252F%252F100%2525_
\.
json/
,
"RESPONSE");
[
o.addFakeServerResponse("dav", "DELETE", "remove6.remove9", 200, "HTML"+
200
,
"RESPONSE");
{
"
Content-Type
"
:
"
text/plain
"
},
o.addFakeServerResponse("dav", "DELETE", "remove6", 200, "HTML RESPONSE");
"
<h1>Deleted</h1>
"
o.spy(o, "value", {"ok": true, "id": "remove6"},
]
"Remove document with multiple attachments");
);
o.jio.remove({"_id": "remove6"}, o.f);
o
.
server
.
respondWith
(
o.clock.tick(5000);
"
DELETE
"
,
/https:
\/\/
ca-davstorage:8080
\/
http:%252F%252F100%2525_
\.
json
\.
body_
\.
html/
,
[
200
,
{
"
Content-Type
"
:
"
text/plain
"
},
"
<h1>Deleted</h1>
"
]
);
o
.
server
.
respondWith
(
"
DELETE
"
,
/https:
\/\/
ca-davstorage:8080
\/
http:%252F%252F100%2525_
\.
json
\.
other/
,
[
200
,
{
"
Content-Type
"
:
"
text/plain
"
},
"
<h1>Deleted</h1>
"
]
);
o
.
spy
(
o
,
"
value
"
,
{
"
ok
"
:
true
,
"
id
"
:
"
http://100%.json
"
},
"
Remove document containing multiple attachments
"
);
o
.
jio
.
remove
({
"
_id
"
:
"
http://100%.json
"
},
{
"
max_retry
"
:
1
},
o
.
f
);
o
.
clock
.
tick
(
1000
);
o
.
server
.
respond
();
o
.
server
.
respond
();
o
.
tick
(
o
);
o
.
server
.
restore
();
o
.
jio
.
stop
();
o
.
jio
.
stop
();
});
});
...
@@ -3876,47 +4005,96 @@ test ("AllDocs", function () {
...
@@ -3876,47 +4005,96 @@ test ("AllDocs", function () {
// need to make server requests before activating fakeServer
// need to make server requests before activating fakeServer
var
davlist
=
getXML
(
'
responsexml/davlist
'
),
var
davlist
=
getXML
(
'
responsexml/davlist
'
),
o = generateTools(this);
o
=
generateTools
(
this
);
o.jio = JIO.newJio({
o
.
jio
=
JIO
.
newJio
({
"type": "dav",
"
type
"
:
"
dav
"
,
"username": "davall",
"
url
"
:
"
https://ca-davstorage:8080
"
,
"password": "checkpwd",
"
auth_type
"
:
"
basic
"
,
"url": "https://ca-davstorage:8080"
"
username
"
:
"
admin
"
,
});
"
password
"
:
"
pwd
"
});
// get allDocs, no content
// get all documents
o.addFakeServerResponse("dav", "PROPFIND", "", 200, davlist);
o
.
server
=
sinon
.
fakeServer
.
create
();
o.thisShouldBeTheAnswer = {
o
.
server
.
respondWith
(
"rows": [
"
PROPFIND
"
,
{"id": "alldocs1", "key": "alldocs1", "value": {}},
/https:
\/\/
ca-davstorage:8080
\/
/
,
{"id": "alldocs2", "key": "alldocs2", "value": {}}
[
],
200
,
"total_rows": 2
{
"
Content-Type
"
:
"
text/xml
"
},
}
davlist
o.spy(o, "value", o.thisShouldBeTheAnswer, "allDocs (no content)");
]
);
o
.
spy
(
o
,
"
value
"
,
{
"
rows
"
:
[
{
"
id
"
:
"
http://100%.json
"
,
"
key
"
:
"
http://100%.json
"
,
"
value
"
:
{}},
{
"
id
"
:
"
ISBN:1038729410372
"
,
"
key
"
:
"
ISBN:1038729410372
"
,
"
value
"
:
{}}
],
"
total_rows
"
:
2
},
"
allDocs
"
);
o
.
jio
.
allDocs
(
o
.
f
);
o
.
jio
.
allDocs
(
o
.
f
);
o.clock.tick(
5
000);
o
.
clock
.
tick
(
1
000
);
o
.
server
.
respond
();
o
.
server
.
respond
();
o
.
tick
(
o
);
// allDocs with option include
o
.
server
.
restore
();
o.all1 = {"_id": "allDocs1", "title": "a doc title"};
o.all2 = {"_id": "allDocs2", "title": "another doc title"};
// allDocs with option include_docs
o.thisShouldBeTheAnswer = {
o
.
server
=
sinon
.
fakeServer
.
create
();
"rows": [
o
.
server
.
respondWith
(
{"id": "alldocs1", "key": "alldocs1", "value": {}, "doc": o.all1},
"
PROPFIND
"
,
{"id": "alldocs2", "key": "alldocs2", "value": {}, "doc": o.all2}
/https:
\/\/
ca-davstorage:8080
\/
/
,
],
[
"total_rows": 2
200
,
}
{
"
Content-Type
"
:
"
text/xml
"
},
o.addFakeServerResponse("dav", "GET", "alldocs1", 200,
davlist
JSON.stringify(o.all1));
]
o.addFakeServerResponse("dav", "GET", "alldocs2", 200,
);
JSON.stringify(o.all2));
o
.
doc1
=
{
"
_id
"
:
"
http://100%.json
"
,
"
_attachments
"
:
{
o.spy(o, "value", o.thisShouldBeTheAnswer, "allDocs (include_docs)");
"
body.html
"
:
{
o.jio.allDocs({"include_docs":true}, o.f);
"
length
"
:
32
,
o.clock.tick(5000);
"
digest
"
:
"
md5-doncare
"
,
"
content_type
"
:
"
text/html
"
}
}};
o
.
doc2
=
{
"
_id
"
:
"
ISBN:1038729410372
"
,
"
title
"
:
"
Book Title
"
};
o
.
server
.
respondWith
(
"
GET
"
,
/https:
\/\/
ca-davstorage:8080
\/
http:%252F%252F100%2525_
\.
json/
,
[
200
,
{
"
Content-Type
"
:
"
text/plain
"
},
JSON
.
stringify
(
o
.
doc1
)
]
);
o
.
server
.
respondWith
(
"
GET
"
,
/https:
\/\/
ca-davstorage:8080
\/
ISBN:1038729410372/
,
[
200
,
{
"
Content-Type
"
:
"
text/plain
"
},
JSON
.
stringify
(
o
.
doc2
)
]
);
o
.
spy
(
o
,
"
value
"
,
{
"
rows
"
:
[{
"
id
"
:
"
http://100%.json
"
,
"
key
"
:
"
http://100%.json
"
,
"
value
"
:
{},
"
doc
"
:
o
.
doc1
},
{
"
id
"
:
"
ISBN:1038729410372
"
,
"
key
"
:
"
ISBN:1038729410372
"
,
"
value
"
:
{},
"
doc
"
:
o
.
doc2
}],
"
total_rows
"
:
2
},
"
allDocs (include_docs)
"
);
o
.
jio
.
allDocs
({
"
include_docs
"
:
true
},
o
.
f
);
o
.
clock
.
tick
(
1000
);
o
.
server
.
respond
();
o
.
server
.
respond
();
o
.
tick
(
o
);
o
.
server
.
restore
();
o
.
jio
.
stop
();
o
.
jio
.
stop
();
});
});
...
...
test/responsexml/davlist
View file @
a91c592e
...
@@ -25,7 +25,7 @@
...
@@ -25,7 +25,7 @@
</D:propstat>
</D:propstat>
</D:response>
</D:response>
<D:response
xmlns:lp1=
"DAV:"
xmlns:lp2=
"http://apache.org/dav/props/"
>
<D:response
xmlns:lp1=
"DAV:"
xmlns:lp2=
"http://apache.org/dav/props/"
>
<D:href>
/some/path/
alldocs1
</D:href>
<D:href>
/some/path/
http:%252F%252F100%2525_.json
</D:href>
<D:propstat>
<D:propstat>
<D:prop>
<D:prop>
<lp1:resourcetype/>
<lp1:resourcetype/>
...
@@ -50,7 +50,32 @@
...
@@ -50,7 +50,32 @@
</D:propstat>
</D:propstat>
</D:response>
</D:response>
<D:response
xmlns:lp1=
"DAV:"
xmlns:lp2=
"http://apache.org/dav/props/"
>
<D:response
xmlns:lp1=
"DAV:"
xmlns:lp2=
"http://apache.org/dav/props/"
>
<D:href>
/some/path/alldocs2
</D:href>
<D:href>
/some/path/ISBN:1038729410372
</D:href>
<D:propstat>
<D:prop>
<lp1:resourcetype/>
<lp1:creationdate>
2012-05-01T17:41:13Z
</lp1:creationdate>
<lp1:getcontentlength>
223
</lp1:getcontentlength>
<lp1:getlastmodified>
Wed, 02 May 2012 10:48:33 GMT
</lp1:getlastmodified>
<lp1:getetag>
"c9-4bf0d1aeb9e43"
</lp1:getetag>
<lp2:executable>
F
</lp2:executable>
<D:supportedlock>
<D:lockentry>
<D:lockscope><D:exclusive/></D:lockscope>
<D:locktype><D:write/></D:locktype>
</D:lockentry>
<D:lockentry>
<D:lockscope><D:shared/></D:lockscope>
<D:locktype><D:write/></D:locktype>
</D:lockentry>
</D:supportedlock>
<D:lockdiscovery/>
</D:prop>
<D:status>
HTTP/1.1 200 OK
</D:status>
</D:propstat>
</D:response>
<D:response
xmlns:lp1=
"DAV:"
xmlns:lp2=
"http://apache.org/dav/props/"
>
<D:href>
/some/path/http:%252F%252F100%2525_.json.body_.html
</D:href>
<D:propstat>
<D:propstat>
<D:prop>
<D:prop>
<lp1:resourcetype/>
<lp1:resourcetype/>
...
@@ -75,4 +100,3 @@
...
@@ -75,4 +100,3 @@
</D:propstat>
</D:propstat>
</D:response>
</D:response>
</D:multistatus>
</D:multistatus>
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