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
a9493535
Commit
a9493535
authored
May 06, 2013
by
Jonathan Rivalan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
JSLint correction
parent
379f636d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
56 additions
and
37 deletions
+56
-37
src/jio.storage/s3storage.js
src/jio.storage/s3storage.js
+56
-37
No files found.
src/jio.storage/s3storage.js
View file @
a9493535
"
use strict
"
;
/*jslint indent: 2, maxlen: 80, sloppy: true, nomen: true */
/*jslint indent: 2, maxlen: 80, nomen: true */
/*global jIO: true, btoa: true, b64_hmac_sha1: true */
/*global jIO: true, btoa: true, b64_hmac_sha1: true */
/*global XMLHttpRequest: true */
/*global XHRwrapper: true */
/*global FormData: true */
/*global $: true */
/**
/**
* JIO S3 Storage. Type = "s3".
* JIO S3 Storage. Type = "s3".
* Amazon S3 "database" storage.
* Amazon S3 "database" storage.
...
@@ -411,8 +414,7 @@ jIO.addStorageType("s3", function (spec, my) {
...
@@ -411,8 +414,7 @@ jIO.addStorageType("s3", function (spec, my) {
doc
=
JSON
.
stringify
(
doc
);
doc
=
JSON
.
stringify
(
doc
);
break
;
break
;
case
"
remove
"
:
case
"
remove
"
:
//if (typeof doc._attachments !== 'undefined') {
if
(
doc
.
_attachments
!==
undefined
)
{
if
(
doc
.
_attachments
!==
'
undefined
'
)
{
delete
doc
.
_attachments
[
attachid
];
delete
doc
.
_attachments
[
attachid
];
}
}
doc
=
JSON
.
stringify
(
doc
);
doc
=
JSON
.
stringify
(
doc
);
...
@@ -468,7 +470,7 @@ jIO.addStorageType("s3", function (spec, my) {
...
@@ -468,7 +470,7 @@ jIO.addStorageType("s3", function (spec, my) {
return
Signature
;
return
Signature
;
};
};
function
XHRwrapper
(
command
,
that
.
XHRwrapper
=
function
(
command
,
docId
,
docId
,
attachId
,
attachId
,
http
,
http
,
...
@@ -496,7 +498,7 @@ jIO.addStorageType("s3", function (spec, my) {
...
@@ -496,7 +498,7 @@ jIO.addStorageType("s3", function (spec, my) {
var
Signature
=
b64_hmac_sha1
(
priv
.
password
,
StringToSign
);
var
Signature
=
b64_hmac_sha1
(
priv
.
password
,
StringToSign
);
var
xhr
,
XMLHttpRequest
;
var
xhr
;
xhr
=
new
XMLHttpRequest
();
xhr
=
new
XMLHttpRequest
();
xhr
.
open
(
http
,
url
,
true
);
xhr
.
open
(
http
,
url
,
true
);
...
@@ -522,7 +524,7 @@ jIO.addStorageType("s3", function (spec, my) {
...
@@ -522,7 +524,7 @@ jIO.addStorageType("s3", function (spec, my) {
}
else
{
}
else
{
xhr
.
send
(
null
);
xhr
.
send
(
null
);
}
}
}
}
;
// ==================== commands ====================
// ==================== commands ====================
/**
/**
...
@@ -545,8 +547,7 @@ jIO.addStorageType("s3", function (spec, my) {
...
@@ -545,8 +547,7 @@ jIO.addStorageType("s3", function (spec, my) {
//conflicts due to the multipart enctype
//conflicts due to the multipart enctype
doc
=
JSON
.
stringify
(
doc
);
doc
=
JSON
.
stringify
(
doc
);
var
http_response
=
''
;
var
http_response
=
''
;
var
fd
,
FormData
;
var
fd
=
new
FormData
();
fd
=
new
FormData
();
//virtually builds the form fields
//virtually builds the form fields
//filename
//filename
fd
.
append
(
'
key
'
,
doc_id
);
fd
.
append
(
'
key
'
,
doc_id
);
...
@@ -572,8 +573,7 @@ jIO.addStorageType("s3", function (spec, my) {
...
@@ -572,8 +573,7 @@ jIO.addStorageType("s3", function (spec, my) {
fd
.
append
(
'
signature
'
,
Signature
);
fd
.
append
(
'
signature
'
,
Signature
);
//uploaded content !!may must be a string rather than an object
//uploaded content !!may must be a string rather than an object
fd
.
append
(
'
file
'
,
doc
);
fd
.
append
(
'
file
'
,
doc
);
var
xhr
,
XMLHttpRequest
;
var
xhr
=
new
XMLHttpRequest
();
xhr
=
new
XMLHttpRequest
();
xhr_onreadystatechange
(
doc_id
,
command
,
xhr
,
'
POST
'
,
true
,
false
,
''
);
xhr_onreadystatechange
(
doc_id
,
command
,
xhr
,
'
POST
'
,
true
,
false
,
''
);
xhr
.
open
(
'
POST
'
,
'
https://
'
+
priv
.
server
+
'
.s3.amazonaws.com/
'
,
true
);
xhr
.
open
(
'
POST
'
,
'
https://
'
+
priv
.
server
+
'
.s3.amazonaws.com/
'
,
true
);
xhr
.
send
(
fd
);
xhr
.
send
(
fd
);
...
@@ -585,7 +585,7 @@ jIO.addStorageType("s3", function (spec, my) {
...
@@ -585,7 +585,7 @@ jIO.addStorageType("s3", function (spec, my) {
doc
.
_id
=
doc_id
;
doc
.
_id
=
doc_id
;
}
}
var
mime
=
'
text/plain; charset=UTF-8
'
;
var
mime
=
'
text/plain; charset=UTF-8
'
;
XHRwrapper
(
command
,
doc_id
,
''
,
'
GET
'
,
mime
,
''
,
false
,
false
,
that
.
XHRwrapper
(
command
,
doc_id
,
''
,
'
GET
'
,
mime
,
''
,
false
,
false
,
function
(
response
)
{
function
(
response
)
{
if
(
response
===
'
404
'
)
{
if
(
response
===
'
404
'
)
{
postDocument
();
postDocument
();
...
@@ -613,7 +613,7 @@ jIO.addStorageType("s3", function (spec, my) {
...
@@ -613,7 +613,7 @@ jIO.addStorageType("s3", function (spec, my) {
var
attachId
=
command
.
getAttachmentId
()
||
''
;
var
attachId
=
command
.
getAttachmentId
()
||
''
;
var
isJIO
=
true
;
var
isJIO
=
true
;
var
mime
=
'
text/plain; charset=UTF-8
'
;
var
mime
=
'
text/plain; charset=UTF-8
'
;
XHRwrapper
(
command
,
docId
,
attachId
,
'
GET
'
,
mime
,
''
,
isJIO
,
false
);
that
.
XHRwrapper
(
command
,
docId
,
attachId
,
'
GET
'
,
mime
,
''
,
isJIO
,
false
);
};
};
that
.
getAttachment
=
function
(
command
)
{
that
.
getAttachment
=
function
(
command
)
{
...
@@ -621,7 +621,7 @@ jIO.addStorageType("s3", function (spec, my) {
...
@@ -621,7 +621,7 @@ jIO.addStorageType("s3", function (spec, my) {
var
attachId
=
command
.
getAttachmentId
();
var
attachId
=
command
.
getAttachmentId
();
var
isJIO
=
true
;
var
isJIO
=
true
;
var
mime
=
'
text/plain; charset=UTF-8
'
;
var
mime
=
'
text/plain; charset=UTF-8
'
;
XHRwrapper
(
command
,
docId
,
attachId
,
'
GET
'
,
mime
,
''
,
isJIO
,
true
);
that
.
XHRwrapper
(
command
,
docId
,
attachId
,
'
GET
'
,
mime
,
''
,
isJIO
,
true
);
};
};
/**
/**
...
@@ -640,10 +640,17 @@ jIO.addStorageType("s3", function (spec, my) {
...
@@ -640,10 +640,17 @@ jIO.addStorageType("s3", function (spec, my) {
var
data
=
JSON
.
stringify
(
doc
);
var
data
=
JSON
.
stringify
(
doc
);
var
isJIO
=
true
;
var
isJIO
=
true
;
var
mime
=
'
text/plain; charset=UTF-8
'
;
var
mime
=
'
text/plain; charset=UTF-8
'
;
XHRwrapper
(
command
,
docId
,
attachId
,
'
PUT
'
,
mime
,
data
,
isJIO
,
false
);
that
.
XHRwrapper
(
command
,
docId
,
attachId
,
'
PUT
'
,
mime
,
data
,
isJIO
,
false
);
}
}
XHRwrapper
(
command
,
docId
,
''
,
'
GET
'
,
mime
,
''
,
false
,
false
,
that
.
XHRwrapper
(
command
,
docId
,
''
,
'
GET
'
,
mime
,
''
,
false
,
false
,
function
(
response
)
{
function
(
response
)
{
//if (response === '404') {}
//if (response === '404') {}
if
(
response
.
_attachments
!==
undefined
)
{
if
(
response
.
_attachments
!==
undefined
)
{
...
@@ -672,7 +679,14 @@ jIO.addStorageType("s3", function (spec, my) {
...
@@ -672,7 +679,14 @@ jIO.addStorageType("s3", function (spec, my) {
attachment_length
=
command
.
getAttachmentLength
();
attachment_length
=
command
.
getAttachmentLength
();
function
putAttachment
()
{
function
putAttachment
()
{
XHRwrapper
(
command
,
docId
,
attachId
,
'
PUT
'
,
mime
,
attachment_data
,
false
,
true
,
that
.
XHRwrapper
(
command
,
docId
,
attachId
,
'
PUT
'
,
mime
,
attachment_data
,
false
,
true
,
function
(
reponse
)
{
function
(
reponse
)
{
that
.
success
({
that
.
success
({
// response
// response
...
@@ -696,7 +710,7 @@ jIO.addStorageType("s3", function (spec, my) {
...
@@ -696,7 +710,7 @@ jIO.addStorageType("s3", function (spec, my) {
var
doc
=
priv
.
updateMeta
(
data
,
docId
,
attachId
,
"
add
"
,
attachment_obj
);
var
doc
=
priv
.
updateMeta
(
data
,
docId
,
attachId
,
"
add
"
,
attachment_obj
);
XHRwrapper
(
command
,
docId
,
''
,
'
PUT
'
,
mime
,
doc
,
false
,
false
,
that
.
XHRwrapper
(
command
,
docId
,
''
,
'
PUT
'
,
mime
,
doc
,
false
,
false
,
function
(
reponse
)
{
function
(
reponse
)
{
putAttachment
();
putAttachment
();
}
}
...
@@ -705,7 +719,7 @@ jIO.addStorageType("s3", function (spec, my) {
...
@@ -705,7 +719,7 @@ jIO.addStorageType("s3", function (spec, my) {
function
getDocument
()
{
function
getDocument
()
{
//XHRwrapper(command,'PUT','text/plain; charset=UTF-8',true);
//XHRwrapper(command,'PUT','text/plain; charset=UTF-8',true);
XHRwrapper
(
command
,
docId
,
''
,
'
GET
'
,
mime
,
''
,
false
,
false
,
that
.
XHRwrapper
(
command
,
docId
,
''
,
'
GET
'
,
mime
,
''
,
false
,
false
,
function
(
reponse
)
{
function
(
reponse
)
{
if
(
reponse
===
'
404
'
)
{
if
(
reponse
===
'
404
'
)
{
return
that
.
error
(
priv
.
createError
(
return
that
.
error
(
priv
.
createError
(
...
@@ -733,7 +747,7 @@ jIO.addStorageType("s3", function (spec, my) {
...
@@ -733,7 +747,7 @@ jIO.addStorageType("s3", function (spec, my) {
var
mime
=
'
text/plain; charset=UTF-8
'
;
var
mime
=
'
text/plain; charset=UTF-8
'
;
function
deleteDocument
()
{
function
deleteDocument
()
{
XHRwrapper
(
command
,
docId
,
''
,
'
DELETE
'
,
mime
,
''
,
true
,
false
,
that
.
XHRwrapper
(
command
,
docId
,
''
,
'
DELETE
'
,
mime
,
''
,
true
,
false
,
function
(
reponse
)
{
function
(
reponse
)
{
that
.
success
({
that
.
success
({
// response
// response
...
@@ -745,13 +759,20 @@ jIO.addStorageType("s3", function (spec, my) {
...
@@ -745,13 +759,20 @@ jIO.addStorageType("s3", function (spec, my) {
);
);
}
}
XHRwrapper
(
command
,
docId
,
''
,
'
GET
'
,
mime
,
''
,
false
,
false
,
that
.
XHRwrapper
(
command
,
docId
,
''
,
'
GET
'
,
mime
,
''
,
false
,
false
,
function
(
response
)
{
function
(
response
)
{
console
.
log
(
response
);
console
.
log
(
response
);
var
attachKeys
=
(
JSON
.
parse
(
response
)).
_attachments
;
var
attachKeys
=
(
JSON
.
parse
(
response
)).
_attachments
;
var
keys
;
var
keys
;
for
(
keys
in
attachKeys
)
{
for
(
keys
in
attachKeys
)
{
XHRwrapper
(
command
,
docId
,
keys
,
'
DELETE
'
,
mime
,
''
,
false
,
false
,
that
.
XHRwrapper
(
command
,
docId
,
keys
,
'
DELETE
'
,
mime
,
''
,
false
,
false
,
function
(
response
)
{
function
(
response
)
{
//console.log('this key got deleted : ' + keys);
//console.log('this key got deleted : ' + keys);
}
}
...
@@ -781,7 +802,7 @@ jIO.addStorageType("s3", function (spec, my) {
...
@@ -781,7 +802,7 @@ jIO.addStorageType("s3", function (spec, my) {
attachment_length
=
command
.
getAttachmentLength
();
attachment_length
=
command
.
getAttachmentLength
();
function
removeAttachment
()
{
function
removeAttachment
()
{
XHRwrapper
(
command
,
docId
,
attachId
,
'
DELETE
'
,
mime
,
''
,
true
,
true
,
that
.
XHRwrapper
(
command
,
docId
,
attachId
,
'
DELETE
'
,
mime
,
''
,
true
,
true
,
function
(
reponse
)
{
function
(
reponse
)
{
}
}
);
);
...
@@ -790,7 +811,7 @@ jIO.addStorageType("s3", function (spec, my) {
...
@@ -790,7 +811,7 @@ jIO.addStorageType("s3", function (spec, my) {
function
putDocument
()
{
function
putDocument
()
{
var
data
=
JSON
.
parse
(
mon_document
);
var
data
=
JSON
.
parse
(
mon_document
);
var
doc
=
priv
.
updateMeta
(
data
,
docId
,
attachId
,
"
remove
"
,
''
);
var
doc
=
priv
.
updateMeta
(
data
,
docId
,
attachId
,
"
remove
"
,
''
);
XHRwrapper
(
command
,
docId
,
''
,
'
PUT
'
,
mime
,
doc
,
that
.
XHRwrapper
(
command
,
docId
,
''
,
'
PUT
'
,
mime
,
doc
,
false
,
false
,
function
(
reponse
)
{
false
,
false
,
function
(
reponse
)
{
removeAttachment
();
removeAttachment
();
}
}
...
@@ -798,7 +819,7 @@ jIO.addStorageType("s3", function (spec, my) {
...
@@ -798,7 +819,7 @@ jIO.addStorageType("s3", function (spec, my) {
}
}
function
getDocument
()
{
function
getDocument
()
{
XHRwrapper
(
command
,
docId
,
''
,
'
GET
'
,
mime
,
''
,
false
,
false
,
that
.
XHRwrapper
(
command
,
docId
,
''
,
'
GET
'
,
mime
,
''
,
false
,
false
,
function
(
reponse
)
{
function
(
reponse
)
{
mon_document
=
reponse
;
mon_document
=
reponse
;
putDocument
();
putDocument
();
...
@@ -819,7 +840,6 @@ jIO.addStorageType("s3", function (spec, my) {
...
@@ -819,7 +840,6 @@ jIO.addStorageType("s3", function (spec, my) {
var
mime
=
'
text/plain; charset=UTF-8
'
;
var
mime
=
'
text/plain; charset=UTF-8
'
;
function
makeJSON
()
{
function
makeJSON
()
{
var
$
;
var
keys
=
$
(
mon_document
).
find
(
'
Key
'
);
var
keys
=
$
(
mon_document
).
find
(
'
Key
'
);
var
resultTable
=
[];
var
resultTable
=
[];
var
counter
=
0
;
var
counter
=
0
;
...
@@ -858,18 +878,17 @@ jIO.addStorageType("s3", function (spec, my) {
...
@@ -858,18 +878,17 @@ jIO.addStorageType("s3", function (spec, my) {
};
};
var
i
=
resultTable
.
length
-
1
;
var
i
=
resultTable
.
length
-
1
;
var
keyId
;
if
(
command
.
getOption
(
"
include_docs
"
)
===
true
)
{
if
(
command
.
getOption
(
"
include_docs
"
)
===
true
)
{
for
(
i
;
i
>=
0
;
i
--
)
{
for
(
i
;
i
>=
0
;
i
--
)
{
docId
=
resultTable
[
i
];
keyId
=
resultTable
[
i
];
var
Signature
=
that
.
encodeAuthorization
(
keyId
);
var
Signature
=
that
.
encodeAuthorization
(
docId
);
var
callURL
=
priv
.
url
+
keyId
;
var
callURL
=
priv
.
url
+
docId
;
var
requestUTC
=
new
Date
().
toUTCString
();
var
requestUTC
=
new
Date
().
toUTCString
();
var
parse
=
true
;
var
parse
=
true
;
allDocResponse
.
rows
[
i
]
=
{
allDocResponse
.
rows
[
i
]
=
{
"
id
"
:
priv
.
fileNameToIds
(
docId
)
+
''
,
"
id
"
:
priv
.
fileNameToIds
(
keyId
).
join
()
,
"
key
"
:
doc
Id
,
"
key
"
:
key
Id
,
"
value
"
:
{}
"
value
"
:
{}
};
};
var
checkCounter
=
i
;
var
checkCounter
=
i
;
...
@@ -912,10 +931,10 @@ jIO.addStorageType("s3", function (spec, my) {
...
@@ -912,10 +931,10 @@ jIO.addStorageType("s3", function (spec, my) {
}
}
}
else
{
}
else
{
for
(
i
;
i
>=
0
;
i
--
)
{
for
(
i
;
i
>=
0
;
i
--
)
{
doc
Id
=
resultTable
[
i
];
key
Id
=
resultTable
[
i
];
allDocResponse
.
rows
[
i
]
=
{
allDocResponse
.
rows
[
i
]
=
{
"
id
"
:
priv
.
fileNameToIds
(
docId
)
+
''
,
"
id
"
:
priv
.
fileNameToIds
(
keyId
).
join
()
,
"
key
"
:
doc
Id
,
"
key
"
:
key
Id
,
"
value
"
:
{}
"
value
"
:
{}
};
};
}
}
...
@@ -925,7 +944,7 @@ jIO.addStorageType("s3", function (spec, my) {
...
@@ -925,7 +944,7 @@ jIO.addStorageType("s3", function (spec, my) {
function
getXML
()
{
function
getXML
()
{
//XHRwrapper(command,'PUT','text/plain; charset=UTF-8',true);
//XHRwrapper(command,'PUT','text/plain; charset=UTF-8',true);
XHRwrapper
(
command
,
''
,
''
,
'
GET
'
,
mime
,
''
,
false
,
false
,
that
.
XHRwrapper
(
command
,
''
,
''
,
'
GET
'
,
mime
,
''
,
false
,
false
,
function
(
reponse
)
{
function
(
reponse
)
{
mon_document
=
reponse
;
mon_document
=
reponse
;
makeJSON
();
makeJSON
();
...
...
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