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
Alexandra Rogova
jio
Commits
90b51d10
Commit
90b51d10
authored
Dec 21, 2012
by
Tristan Cavelier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wip: smart post on storage.js
parent
c8386265
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
72 additions
and
10 deletions
+72
-10
src/jio/storages/storage.js
src/jio/storages/storage.js
+72
-10
No files found.
src/jio/storages/storage.js
View file @
90b51d10
...
...
@@ -290,16 +290,78 @@ var storage = function(spec, my) {
};
that
.
post
=
function
(
command
)
{
var
docid
,
option
;
docid
=
command
.
getDocId
();
option
=
command
.
cloneOption
();
// check if the tree already exists
that
.
_get
(
docid
+
'
.tree.json
'
,
option
,
// if the tree does not exists yet
// if the tree exists
setTimeout
(
function
()
{
var
f
,
options
,
document_tree
,
doc
,
prev_rev
;
f
=
{};
options
=
command
.
cloneOption
();
options
[
"
max_retry
"
]
=
options
[
"
max_retry
"
]
||
3
;
f
.
begin
=
function
()
{
prev_rev
=
command
.
getDocInfo
(
"
_rev
"
);
if
(
typeof
prev_rev
===
"
string
"
&&
!
that
.
checkRevisionFormat
(
prev_rev
))
{
// if the previous revision given is bad
that
.
error
(
that
.
createErrorObject
(
400
,
"
Bad Request
"
,
"
Invalid rev format
"
));
return
;
}
doc
=
that
.
createDocument
(
command
.
getDoc
()
||
{},
command
.
getDocId
()
||
that
.
generateUuid
(),
prev_rev
);
// the previous revision is correct
prev_rev
=
that
.
revisionToArray
(
prev_rev
);
f
.
getDocumentTree
();
};
// check if the tree already exists
f
.
getDocumentTree
=
function
()
{
that
.
addJob
(
'
_get
'
,
that
.
serialized
(),
doc
.
_id
+
'
.tree.json
'
,
options
,
function
(
response
)
{
// if the tree exists
document_tree
=
response
;
f
.
postDocument
();
},
function
(
error
)
{
if
(
error
.
status
===
404
)
{
// if the tree does not exists yet
document_tree
=
that
.
createDocumentTree
();
f
.
postDocument
();
}
else
{
that
.
error
(
that
.
createErrorObject
(
error
.
status
,
error
.
statusText
,
"
Unable to get the revision tree
"
));
}
}
);
};
f
.
postDocument
=
function
()
{
that
.
addJob
(
'
_post
'
,
that
.
serialized
(),
doc
.
_id
+
'
.
'
+
doc
.
_rev
,
options
,
function
(
response
)
{
f
.
putDocumentTree
()
},
function
(
error
)
{
that
.
error
(
that
.
createErrorObject
(
error
.
status
,
error
.
statusText
,
error
));
}
);
};
f
.
putDocumentTree
=
function
()
{
if
(
!
that
.
addDocumentToDocumentTree
(
doc
))
{
// conflict!
}
// xxx
};
f
.
begin
();
});
};
that
.
_post
=
function
()
{
...
...
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