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
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
Stefane Fermigier
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 @@
...
@@ -5,15 +5,9 @@
*/
*/
/*jslint nomen: true*/
/*jslint nomen: true*/
/*global
window, jIO, RSVP, btoa, DOMParser, Blob, console
*/
/*global
jIO, RSVP, DOMParser, Blob
*/
// JIO Dav Storage Description :
// JIO Dav Storage Description :
// {
// type: "dav",
// url: {string}
// // No Authentication Here
// }
// {
// {
// type: "dav",
// type: "dav",
// url: {string},
// url: {string},
...
@@ -24,7 +18,7 @@
...
@@ -24,7 +18,7 @@
// curl --verbose -X OPTION http://domain/
// curl --verbose -X OPTION http://domain/
// In the headers: "WWW-Authenticate: Basic realm="DAV-upload"
// In the headers: "WWW-Authenticate: Basic realm="DAV-upload"
(
function
(
jIO
)
{
(
function
(
jIO
,
RSVP
,
DOMParser
,
Blob
)
{
"
use strict
"
;
"
use strict
"
;
function
ajax
(
storage
,
options
)
{
function
ajax
(
storage
,
options
)
{
...
@@ -79,23 +73,33 @@
...
@@ -79,23 +73,33 @@
if
(
typeof
spec
.
url
!==
'
string
'
)
{
if
(
typeof
spec
.
url
!==
'
string
'
)
{
throw
new
TypeError
(
"
DavStorage 'url' is not of type string
"
);
throw
new
TypeError
(
"
DavStorage 'url' is not of type string
"
);
}
}
// Remove last slash
this
.
_url
=
spec
.
url
;
this
.
_url
=
spec
.
url
.
replace
(
/
\/
$/
,
''
);
// XXX digest login
// XXX digest login
if
(
typeof
spec
.
basic_login
===
'
string
'
)
{
if
(
typeof
spec
.
basic_login
===
'
string
'
)
{
// this._auth_type = 'basic';
this
.
_authorization
=
"
Basic
"
+
spec
.
basic_login
;
this
.
_authorization
=
"
Basic
"
+
spec
.
basic_login
;
// } else {
// this._auth_type = 'none';
}
}
}
}
DavStorage
.
prototype
.
put
=
function
(
param
)
{
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
,
{
return
ajax
(
this
,
{
type
:
"
MKCOL
"
,
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 @@
...
@@ -111,6 +115,7 @@
url
:
context
.
_url
+
id
,
url
:
context
.
_url
+
id
,
dataType
:
"
text
"
,
dataType
:
"
text
"
,
headers
:
{
headers
:
{
// Increasing this value is a performance killer
Depth
:
"
1
"
Depth
:
"
1
"
}
}
});
});
...
@@ -121,9 +126,7 @@
...
@@ -121,9 +126,7 @@
// Extract all meta informations and return them to JSON
// Extract all meta informations and return them to JSON
var
i
,
var
i
,
result
=
{
result
=
{},
"
title
"
:
param
.
_id
},
attachment
=
{},
attachment
=
{},
id
,
id
,
attachment_list
=
new
DOMParser
().
parseFromString
(
attachment_list
=
new
DOMParser
().
parseFromString
(
...
@@ -143,7 +146,7 @@
...
@@ -143,7 +146,7 @@
attachment
[
id
]
=
{};
attachment
[
id
]
=
{};
}
}
}
}
if
(
attachment
.
length
!==
0
)
{
if
(
Object
.
getOwnPropertyNames
(
attachment
).
length
>
0
)
{
result
.
_attachments
=
attachment
;
result
.
_attachments
=
attachment
;
}
}
return
result
;
return
result
;
...
@@ -162,20 +165,11 @@
...
@@ -162,20 +165,11 @@
DavStorage
.
prototype
.
putAttachment
=
function
(
param
)
{
DavStorage
.
prototype
.
putAttachment
=
function
(
param
)
{
var
id
=
restrictDocumentId
(
param
.
_id
);
var
id
=
restrictDocumentId
(
param
.
_id
);
restrictAttachmentId
(
param
.
_attachment
);
restrictAttachmentId
(
param
.
_attachment
);
return
ajax
(
this
,
{
return
ajax
(
this
,
{
type
:
"
PUT
"
,
type
:
"
PUT
"
,
url
:
this
.
_url
+
id
+
param
.
_attachment
,
url
:
this
.
_url
+
id
+
param
.
_attachment
,
data
:
param
.
_blob
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
)
{
DavStorage
.
prototype
.
getAttachment
=
function
(
param
)
{
...
@@ -192,15 +186,17 @@
...
@@ -192,15 +186,17 @@
});
});
})
})
.
push
(
function
(
response
)
{
.
push
(
function
(
response
)
{
return
new
Blob
(
return
{
data
:
new
Blob
(
[
response
.
target
.
response
],
[
response
.
target
.
response
||
response
.
target
.
responseText
],
{
"
type
"
:
response
.
target
.
getResponseHeader
(
'
Content-Type
'
)
||
{
"
type
"
:
response
.
target
.
getResponseHeader
(
'
Content-Type
'
)
||
"
application/octet-stream
"
}
"
application/octet-stream
"
}
);
)
}
;
},
function
(
error
)
{
},
function
(
error
)
{
if
((
error
.
target
!==
undefined
)
&&
if
((
error
.
target
!==
undefined
)
&&
(
error
.
target
.
status
===
404
))
{
(
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
;
throw
error
;
});
});
...
@@ -222,7 +218,9 @@
...
@@ -222,7 +218,9 @@
.
push
(
undefined
,
function
(
error
)
{
.
push
(
undefined
,
function
(
error
)
{
if
((
error
.
target
!==
undefined
)
&&
if
((
error
.
target
!==
undefined
)
&&
(
error
.
target
.
status
===
404
))
{
(
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
;
throw
error
;
});
});
...
@@ -257,4 +255,4 @@
...
@@ -257,4 +255,4 @@
jIO
.
addStorage
(
'
dav
'
,
DavStorage
);
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 @@
...
@@ -29,9 +29,9 @@
<script
src=
"jio.storage/querystorage.tests.js"
></script>
<script
src=
"jio.storage/querystorage.tests.js"
></script>
<script
src=
"jio.storage/localstorage.tests.js"
></script>
<script
src=
"jio.storage/localstorage.tests.js"
></script>
<script
src=
"jio.storage/documentstorage.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/indexeddbstorage.tests.js"></script-->
<!--script src="jio.storage/indexstorage.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