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
Boris Kocherov
jio
Commits
4428686a
Commit
4428686a
authored
Feb 18, 2015
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add DavStorage tests
parent
e81183d7
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
845 additions
and
1772 deletions
+845
-1772
src/jio.storage/davstorage.js
src/jio.storage/davstorage.js
+33
-35
test/jio.storage/davstorage.tests.js
test/jio.storage/davstorage.tests.js
+810
-1735
test/tests.html
test/tests.html
+2
-2
No files found.
src/jio.storage/davstorage.js
View file @
4428686a
...
...
@@ -5,15 +5,9 @@
*/
/*jslint nomen: true*/
/*global
window, jIO, RSVP, btoa, DOMParser, Blob, console
*/
/*global
jIO, RSVP, DOMParser, Blob
*/
// JIO Dav Storage Description :
// {
// type: "dav",
// url: {string}
// // No Authentication Here
// }
// {
// type: "dav",
// url: {string},
...
...
@@ -24,7 +18,7 @@
// curl --verbose -X OPTION http://domain/
// In the headers: "WWW-Authenticate: Basic realm="DAV-upload"
(
function
(
jIO
)
{
(
function
(
jIO
,
RSVP
,
DOMParser
,
Blob
)
{
"
use strict
"
;
function
ajax
(
storage
,
options
)
{
...
...
@@ -79,23 +73,33 @@
if
(
typeof
spec
.
url
!==
'
string
'
)
{
throw
new
TypeError
(
"
DavStorage 'url' is not of type string
"
);
}
// Remove last slash
this
.
_url
=
spec
.
url
.
replace
(
/
\/
$/
,
''
);
this
.
_url
=
spec
.
url
;
// XXX digest login
if
(
typeof
spec
.
basic_login
===
'
string
'
)
{
// this._auth_type = 'basic';
this
.
_authorization
=
"
Basic
"
+
spec
.
basic_login
;
// } else {
// this._auth_type = 'none';
}
}
DavStorage
.
prototype
.
put
=
function
(
param
)
{
// XXX Reject if param has other properties than _id
var
id
=
restrictDocumentId
(
param
.
_id
);
delete
param
.
_id
;
if
(
Object
.
getOwnPropertyNames
(
param
).
length
>
0
)
{
// Reject if param has other properties than _id
throw
new
jIO
.
util
.
jIOError
(
"
Can not store properties:
"
+
Object
.
getOwnPropertyNames
(
param
),
400
);
}
return
ajax
(
this
,
{
type
:
"
MKCOL
"
,
url
:
this
.
_url
+
param
.
_id
url
:
this
.
_url
+
id
});
};
DavStorage
.
prototype
.
remove
=
function
(
param
)
{
var
id
=
restrictDocumentId
(
param
.
_id
);
return
ajax
(
this
,
{
type
:
"
DELETE
"
,
url
:
this
.
_url
+
id
});
};
...
...
@@ -111,6 +115,7 @@
url
:
context
.
_url
+
id
,
dataType
:
"
text
"
,
headers
:
{
// Increasing this value is a performance killer
Depth
:
"
1
"
}
});
...
...
@@ -121,9 +126,7 @@
// Extract all meta informations and return them to JSON
var
i
,
result
=
{
"
title
"
:
param
.
_id
},
result
=
{},
attachment
=
{},
id
,
attachment_list
=
new
DOMParser
().
parseFromString
(
...
...
@@ -143,7 +146,7 @@
attachment
[
id
]
=
{};
}
}
if
(
attachment
.
length
!==
0
)
{
if
(
Object
.
getOwnPropertyNames
(
attachment
).
length
>
0
)
{
result
.
_attachments
=
attachment
;
}
return
result
;
...
...
@@ -162,20 +165,11 @@
DavStorage
.
prototype
.
putAttachment
=
function
(
param
)
{
var
id
=
restrictDocumentId
(
param
.
_id
);
restrictAttachmentId
(
param
.
_attachment
);
return
ajax
(
this
,
{
type
:
"
PUT
"
,
url
:
this
.
_url
+
id
+
param
.
_attachment
,
data
:
param
.
_blob
})
.
push
(
undefined
,
function
(
error
)
{
if
((
error
.
target
!==
undefined
)
&&
(
error
.
target
.
status
===
403
))
{
throw
new
jIO
.
util
.
jIOError
(
"
Cannot find document
"
,
404
);
}
throw
error
;
});
});
};
DavStorage
.
prototype
.
getAttachment
=
function
(
param
)
{
...
...
@@ -192,15 +186,17 @@
});
})
.
push
(
function
(
response
)
{
return
new
Blob
(
[
response
.
target
.
response
],
return
{
data
:
new
Blob
(
[
response
.
target
.
response
||
response
.
target
.
responseText
],
{
"
type
"
:
response
.
target
.
getResponseHeader
(
'
Content-Type
'
)
||
"
application/octet-stream
"
}
);
)
}
;
},
function
(
error
)
{
if
((
error
.
target
!==
undefined
)
&&
(
error
.
target
.
status
===
404
))
{
throw
new
jIO
.
util
.
jIOError
(
"
Cannot find document
"
,
404
);
throw
new
jIO
.
util
.
jIOError
(
"
Cannot find attachment:
"
+
param
.
_id
+
"
,
"
+
param
.
_attachment
,
404
);
}
throw
error
;
});
...
...
@@ -222,7 +218,9 @@
.
push
(
undefined
,
function
(
error
)
{
if
((
error
.
target
!==
undefined
)
&&
(
error
.
target
.
status
===
404
))
{
throw
new
jIO
.
util
.
jIOError
(
"
Cannot find document
"
,
404
);
throw
new
jIO
.
util
.
jIOError
(
"
Cannot find attachment:
"
+
param
.
_id
+
"
,
"
+
param
.
_attachment
,
404
);
}
throw
error
;
});
...
...
@@ -257,4 +255,4 @@
jIO
.
addStorage
(
'
dav
'
,
DavStorage
);
}(
jIO
));
}(
jIO
,
RSVP
,
DOMParser
,
Blob
));
test/jio.storage/davstorage.tests.js
View file @
4428686a
This diff is collapsed.
Click to expand it.
test/tests.html
View file @
4428686a
...
...
@@ -29,9 +29,9 @@
<script
src=
"jio.storage/querystorage.tests.js"
></script>
<script
src=
"jio.storage/localstorage.tests.js"
></script>
<script
src=
"jio.storage/documentstorage.tests.js"
></script>
<script
src=
"jio.storage/davstorage.tests.js"
></script>
<!--script src="jio.storage/davstorage.tests.js"></script>
<script src="jio.storage/unionstorage.tests.js"></script-->
<!--script src="jio.storage/unionstorage.tests.js"></script-->
<!--script src="jio.storage/indexeddbstorage.tests.js"></script-->
<!--script src="jio.storage/indexstorage.tests.js"></script-->
...
...
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