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
Tomáš Peterka
jio
Commits
2b579525
Commit
2b579525
authored
Nov 23, 2012
by
Tristan Cavelier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add putAttachment method to JIO
parent
77e522dc
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
87 additions
and
18 deletions
+87
-18
grunt/30_gruntJIO/grunt.js
grunt/30_gruntJIO/grunt.js
+1
-0
src/jio/commands/command.js
src/jio/commands/command.js
+26
-18
src/jio/commands/putAttachmentCommand.js
src/jio/commands/putAttachmentCommand.js
+28
-0
src/jio/jio.outro.js
src/jio/jio.outro.js
+32
-0
No files found.
grunt/30_gruntJIO/grunt.js
View file @
2b579525
...
@@ -24,6 +24,7 @@ module.exports = function(grunt) {
...
@@ -24,6 +24,7 @@ module.exports = function(grunt) {
'
<file_strip_banner:../../src/<%= pkg.name %>/commands/allDocsCommand.js>
'
,
'
<file_strip_banner:../../src/<%= pkg.name %>/commands/allDocsCommand.js>
'
,
'
<file_strip_banner:../../src/<%= pkg.name %>/commands/getCommand.js>
'
,
'
<file_strip_banner:../../src/<%= pkg.name %>/commands/getCommand.js>
'
,
'
<file_strip_banner:../../src/<%= pkg.name %>/commands/removeCommand.js>
'
,
'
<file_strip_banner:../../src/<%= pkg.name %>/commands/removeCommand.js>
'
,
'
<file_strip_banner:../../src/<%= pkg.name %>/commands/putAttachmentCommand.js>
'
,
'
<file_strip_banner:../../src/<%= pkg.name %>/commands/putCommand.js>
'
,
'
<file_strip_banner:../../src/<%= pkg.name %>/commands/putCommand.js>
'
,
'
<file_strip_banner:../../src/<%= pkg.name %>/commands/postCommand.js>
'
,
'
<file_strip_banner:../../src/<%= pkg.name %>/commands/postCommand.js>
'
,
'
<file_strip_banner:../../src/<%= pkg.name %>/jobs/status/jobStatus.js>
'
,
'
<file_strip_banner:../../src/<%= pkg.name %>/jobs/status/jobStatus.js>
'
,
...
...
src/jio/commands/command.js
View file @
2b579525
...
@@ -4,11 +4,14 @@ var command = function(spec, my) {
...
@@ -4,11 +4,14 @@ var command = function(spec, my) {
my
=
my
||
{};
my
=
my
||
{};
// Attributes //
// Attributes //
var
priv
=
{};
var
priv
=
{};
priv
.
commandlist
=
{
'
post
'
:
postCommand
,
priv
.
commandlist
=
{
'
put
'
:
putCommand
,
'
post
'
:
postCommand
,
'
get
'
:
getCommand
,
'
put
'
:
putCommand
,
'
remove
'
:
removeCommand
,
'
get
'
:
getCommand
,
'
allDocs
'
:
allDocsCommand
};
'
remove
'
:
removeCommand
,
'
allDocs
'
:
allDocsCommand
,
'
putAttachment
'
:
putAttachmentCommand
};
// creates the good command thanks to his label
// creates the good command thanks to his label
if
(
spec
.
label
&&
priv
.
commandlist
[
spec
.
label
])
{
if
(
spec
.
label
&&
priv
.
commandlist
[
spec
.
label
])
{
priv
.
label
=
spec
.
label
;
priv
.
label
=
spec
.
label
;
...
@@ -20,6 +23,9 @@ var command = function(spec, my) {
...
@@ -20,6 +23,9 @@ var command = function(spec, my) {
priv
.
doc
=
spec
.
doc
||
{};
priv
.
doc
=
spec
.
doc
||
{};
priv
.
docid
=
spec
.
docid
||
''
;
priv
.
docid
=
spec
.
docid
||
''
;
priv
.
option
=
spec
.
options
||
{};
priv
.
option
=
spec
.
options
||
{};
priv
.
content
=
typeof
spec
.
content
===
'
string
'
?
spec
.
content
:
undefined
;
priv
.
callbacks
=
spec
.
callbacks
||
{};
priv
.
callbacks
=
spec
.
callbacks
||
{};
priv
.
success
=
priv
.
callbacks
.
success
||
function
(){};
priv
.
success
=
priv
.
callbacks
.
success
||
function
(){};
priv
.
error
=
priv
.
callbacks
.
error
||
function
(){};
priv
.
error
=
priv
.
callbacks
.
error
||
function
(){};
...
@@ -56,10 +62,13 @@ var command = function(spec, my) {
...
@@ -56,10 +62,13 @@ var command = function(spec, my) {
};
};
that
.
getDocId
=
function
()
{
that
.
getDocId
=
function
()
{
return
priv
.
docid
||
priv
.
doc
.
_id
;
return
(
priv
.
docid
||
priv
.
doc
.
_id
).
split
(
'
/
'
)[
0
];
};
that
.
getAttachmentId
=
function
()
{
return
(
priv
.
docid
||
priv
.
doc
.
_id
).
split
(
'
/
'
)[
1
];
};
};
that
.
get
Doc
Content
=
function
()
{
that
.
getContent
=
function
()
{
return
priv
.
doc
.
content
;
return
priv
.
content
;
};
};
/**
/**
...
@@ -87,6 +96,15 @@ var command = function(spec, my) {
...
@@ -87,6 +96,15 @@ var command = function(spec, my) {
* @param {object} storage The storage.
* @param {object} storage The storage.
*/
*/
that
.
validate
=
function
(
storage
)
{
that
.
validate
=
function
(
storage
)
{
if
(
!
(
priv
.
docid
||
priv
.
doc
.
_id
).
match
(
/^
[^\/]
+
([\/][^\/]
+
)?
$/
))
{
that
.
error
({
status
:
21
,
statusText
:
'
Invalid Document Id
'
,
error
:
'
invalid_document_id
'
,
message
:
'
The document id must be like "abc" or "abc/def".
'
,
reason
:
'
The document id is no like "abc" or "abc/def"
'
});
return
false
;
}
if
(
!
that
.
validateState
())
{
if
(
!
that
.
validateState
())
{
return
false
;
return
false
;
}
}
...
@@ -97,16 +115,6 @@ var command = function(spec, my) {
...
@@ -97,16 +115,6 @@ var command = function(spec, my) {
* Extend this function
* Extend this function
*/
*/
that
.
validateState
=
function
()
{
that
.
validateState
=
function
()
{
if
(
typeof
priv
.
doc
!==
'
object
'
)
{
that
.
error
({
status
:
20
,
statusText
:
'
Document_Id Required
'
,
error
:
'
document_id_required
'
,
message
:
'
No document id.
'
,
reason
:
'
no document id
'
});
return
false
;
}
return
true
;
return
true
;
};
};
...
...
src/jio/commands/putAttachmentCommand.js
0 → 100644
View file @
2b579525
var
putAttachmentCommand
=
function
(
spec
,
my
)
{
var
that
=
command
(
spec
,
my
);
spec
=
spec
||
{};
my
=
my
||
{};
// Attributes //
// Methods //
that
.
getLabel
=
function
()
{
return
'
putAttachment
'
;
};
that
.
executeOn
=
function
(
storage
)
{
storage
.
putAttachment
(
that
);
};
that
.
validateState
=
function
()
{
if
(
typeof
that
.
getContent
()
!==
'
string
'
)
{
that
.
error
({
status
:
22
,
statusText
:
'
Content Required
'
,
error
:
'
content_required
'
,
message
:
'
No data to put.
'
,
reason
:
'
no data to put
'
});
return
false
;
}
return
true
;
};
return
that
;
};
src/jio/jio.outro.js
View file @
2b579525
...
@@ -318,5 +318,37 @@
...
@@ -318,5 +318,37 @@
}
}
});
});
/**
* Put an attachment to a document.
* @method putAttachment
* @param {string} id The attachment id ("document/attachment").
* @param {string} rev The document revision.
* @param {string} doc Base64 attachment content.
* @param {string} mimetype The attachment mimetype
* @param {object} options (optional) Contains some options:
* - {number} max_retry The number max of retries, 0 = infinity.
* - {boolean} revs Include revision history of the document.
* - {boolean} revs_info Include revisions.
* - {boolean} conflicts Include conflicts.
* @param {function} callback (optional) The callback(err,respons)
* @param {function} error (optional) The callback on error, if this
* callback is given in parameter, "callback" is changed as "success",
* called on success.
*/
Object
.
defineProperty
(
that
,
"
putAttachment
"
,{
configurable
:
false
,
enumerable
:
false
,
writable
:
false
,
value
:
function
(
id
,
rev
,
doc
,
mimetype
,
options
,
success
,
error
)
{
var
param
=
priv
.
parametersToObject
(
[
options
,
success
,
error
],
{
max_retry
:
0
}
);
priv
.
addJob
(
putAttachmentCommand
,{
doc
:{
_id
:
id
,
content
:
doc
},
options
:
param
.
options
,
callbacks
:{
success
:
param
.
success
,
error
:
param
.
error
}
});
}
});
return
that
;
return
that
;
};
// End Class jio
};
// End Class jio
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