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
Labels
Merge Requests
18
Merge Requests
18
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
jio
Commits
339567d7
Commit
339567d7
authored
Mar 02, 2018
by
Vincent Bechu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[cloudoostorage] add convert on putAttachment with format
parent
01c6bc34
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
146 additions
and
13 deletions
+146
-13
src/jio.storage/cloudoostorage.js
src/jio.storage/cloudoostorage.js
+52
-12
test/jio.storage/cloudoostorage.tests.js
test/jio.storage/cloudoostorage.tests.js
+94
-1
No files found.
src/jio.storage/cloudoostorage.js
View file @
339567d7
...
...
@@ -84,7 +84,7 @@
}
function
getOrCreateInfoDoc
(
storage
,
id
,
attachment_id
)
{
return
storage
.
get
(
getInfoDocId
(
id
,
attachment_id
))
return
storage
.
_sub_storage
.
get
(
getInfoDocId
(
id
,
attachment_id
))
.
push
(
undefined
,
function
(
error
)
{
if
(
error
instanceof
jIO
.
util
.
jIOError
&&
error
.
status_code
===
404
)
{
return
storage
.
get
(
id
)
...
...
@@ -106,20 +106,24 @@
});
}
function
convert
Attachmen
t
(
storage
,
id
,
attachment_id
,
format
)
{
function
convert
FromBaseForma
t
(
storage
,
id
,
attachment_id
,
format
)
{
var
info_doc
;
return
getOrCreateInfoDoc
(
storage
,
id
,
attachment_id
)
.
push
(
function
(
doc
)
{
info_doc
=
doc
;
return
storage
.
getAttachment
(
id
,
attachment_id
)
return
storage
.
_sub_storage
.
getAttachment
(
id
,
attachment_id
)
.
push
(
function
(
blob
)
{
return
convert
(
storage
,
blob
,
info_doc
.
format
,
format
);
})
.
push
(
function
(
blob
)
{
return
storage
.
putAttachment
(
id
,
attachment_id
+
'
?
'
+
format
,
blob
)
return
storage
.
_sub_storage
.
putAttachment
(
id
,
attachment_id
+
'
?
'
+
format
,
blob
)
.
push
(
function
()
{
info_doc
.
convert_dict
[
format
]
=
true
;
return
storage
.
put
(
return
storage
.
_sub_storage
.
put
(
getInfoDocId
(
id
,
attachment_id
),
info_doc
);
...
...
@@ -129,7 +133,7 @@
});
},
undefined
,
function
(
error
)
{
info_doc
.
convert_dict
[
format
]
=
false
;
return
storage
.
put
(
return
storage
.
_sub_storage
.
put
(
getInfoDocId
(
id
,
attachment_id
),
info_doc
)
...
...
@@ -140,6 +144,25 @@
});
}
function
convertToBaseFormat
(
storage
,
id
,
attachment_id
,
format
,
blob
)
{
var
info_doc
;
return
getOrCreateInfoDoc
(
storage
,
id
,
attachment_id
)
.
push
(
function
(
doc
)
{
info_doc
=
doc
;
return
convert
(
storage
,
blob
,
format
,
info_doc
.
format
);
})
.
push
(
function
(
blob
)
{
return
storage
.
_sub_storage
.
putAttachment
(
id
,
attachment_id
,
blob
);
})
.
push
(
function
()
{
info_doc
.
convert_dict
[
format
]
=
true
;
return
storage
.
_sub_storage
.
put
(
getInfoDocId
(
id
,
attachment_id
),
info_doc
);
});
}
function
removeConvertedAttachment
(
storage
,
id
,
attachment_id
)
{
var
doc_info
;
return
getOrCreateInfoDoc
(
storage
,
id
,
attachment_id
)
...
...
@@ -150,7 +173,10 @@
if
(
doc
.
convert_list
.
hasOwnProperty
(
format
))
{
if
(
doc
.
convert_list
[
format
])
{
promise_list
.
push
(
storage
.
removeAttachment
(
id
,
attachment_id
+
'
?
'
+
format
)
storage
.
_sub_storage
.
removeAttachment
(
id
,
attachment_id
+
'
?
'
+
format
)
);
}
}
...
...
@@ -203,7 +229,7 @@
if
(
error
instanceof
jIO
.
util
.
jIOError
&&
error
.
status_code
===
404
&&
att_id_list
.
length
>
1
)
{
return
convert
Attachmen
t
(
return
convert
FromBaseForma
t
(
storage
,
id
,
att_id_list
[
0
],
...
...
@@ -213,7 +239,7 @@
throw
error
;
});
};
CloudooStorage
.
prototype
.
putAttachment
=
function
(
id
,
attachment_id
)
{
CloudooStorage
.
prototype
.
putAttachment
=
function
(
id
,
attachment_id
,
blob
)
{
var
storage
=
this
;
return
this
.
_sub_storage
.
putAttachment
.
apply
(
this
.
_sub_storage
,
arguments
)
.
push
(
function
(
result
)
{
...
...
@@ -221,12 +247,24 @@
if
(
att_id_list
.
length
===
1
)
{
return
removeConvertedAttachment
(
storage
,
id
,
attachment_id
)
.
push
(
function
(
doc_info
)
{
return
storage
.
put
(
getInfoDocId
(
id
,
attachment_id
),
doc_info
);
return
storage
.
_sub_storage
.
put
(
getInfoDocId
(
id
,
attachment_id
),
doc_info
);
})
.
push
(
function
()
{
return
result
;
});
}
if
(
att_id_list
.
length
===
2
)
{
return
convertToBaseFormat
(
storage
,
id
,
att_id_list
[
0
],
att_id_list
[
1
],
blob
);
}
});
};
CloudooStorage
.
prototype
.
removeAttachment
=
function
(
id
,
attachment_id
)
{
...
...
@@ -240,7 +278,9 @@
if
(
att_id_list
.
length
===
1
)
{
return
removeConvertedAttachment
(
storage
,
id
,
attachment_id
)
.
push
(
function
()
{
return
storage
.
remove
(
getInfoDocId
(
id
,
attachment_id
));
return
storage
.
_sub_storage
.
remove
(
getInfoDocId
(
id
,
attachment_id
)
);
});
}
});
...
...
@@ -264,7 +304,7 @@
for
(
format
in
value
.
convert_dict
)
{
if
(
value
.
convert_dict
.
hasOwnProperty
(
format
)
&&
value
.
convert_dict
[
format
]
===
false
)
{
promise_list
.
push
(
convert
Attachmen
t
(
promise_list
.
push
(
convert
FromBaseForma
t
(
storage
,
value
.
doc_id
,
value
.
attachment_id
,
...
...
test/jio.storage/cloudoostorage.tests.js
View file @
339567d7
...
...
@@ -510,7 +510,27 @@
/////////////////////////////////////////////////////////////////
// CloudooStorage.putAttachment
/////////////////////////////////////////////////////////////////
module
(
"
cloudooStorage.putAttachment
"
);
module
(
"
cloudooStorage.putAttachment
"
,
{
setup
:
function
()
{
this
.
server
=
sinon
.
fakeServer
.
create
();
this
.
server
.
autoRespond
=
true
;
this
.
server
.
autoRespondAfter
=
5
;
this
.
jio
=
jIO
.
createJIO
({
type
:
"
cloudoo
"
,
url
:
cloudoo_url
,
sub_storage
:
{
type
:
"
cloudoostorage200
"
}
});
},
teardown
:
function
()
{
this
.
server
.
restore
();
delete
this
.
server
;
}
});
test
(
"
putAttachment called substorage putAttachment
"
,
function
()
{
stop
();
expect
(
6
);
...
...
@@ -563,6 +583,79 @@
});
});
test
(
"
putAttachment convert from docx to docy
"
,
function
()
{
stop
();
expect
(
10
);
var
blob
=
new
Blob
([
"
documentauformatdocy
"
],
{
type
:
"
docy
"
}),
server
=
this
.
server
,
blob_convert
=
new
Blob
([
"
documentauformatdocx
"
],
{
type
:
"
docx
"
});
this
.
server
.
respondWith
(
"
POST
"
,
cloudoo_url
,
[
200
,
{
"
Content-Type
"
:
"
text/xml
"
},
'
<?xml version="1.0" encoding="UTF-8"?>
'
+
'
<string>ZG9jdW1lbnRhdWZvcm1hdGRvY3k=</string>
'
]);
Storage200
.
prototype
.
putAttachment
=
function
(
id
,
att_id
,
data
)
{
equal
(
id
,
"
bar
"
,
"
putAttachment 200 called
"
);
if
(
att_id
===
"
data?docx
"
)
{
deepEqual
(
data
,
blob_convert
,
"
putAttachment 200 called
"
);
return
"
OK
"
;
}
if
(
att_id
===
"
data
"
)
{
deepEqual
(
data
,
blob
,
"
putAttachment 200 called
"
);
return
"
OK
"
;
}
};
Storage200
.
prototype
.
get
=
function
(
id
)
{
if
(
id
===
"
cloudoo/bar/data
"
)
{
throw
new
jIO
.
util
.
jIOError
(
"
can't find
"
,
404
);
}
if
(
id
===
"
bar
"
)
{
return
{
content_type
:
"
application/x-asc-text
"
};
}
equal
(
id
,
""
,
"
get 200 called
"
);
return
{};
};
Storage200
.
prototype
.
put
=
function
(
id
,
doc
)
{
equal
(
id
,
"
cloudoo/bar/data
"
,
"
put 200 called
"
);
deepEqual
(
doc
,
{
"
attachment_id
"
:
"
data
"
,
"
convert_dict
"
:
{
"
docx
"
:
true
},
"
doc_id
"
:
"
bar
"
,
"
format
"
:
"
docy
"
,
"
portal_type
"
:
"
Conversion Info
"
},
"
put doc 200 called
"
);
return
id
;
};
this
.
jio
.
putAttachment
(
"
bar
"
,
"
data?docx
"
,
blob_convert
)
.
then
(
function
()
{
equal
(
server
.
requests
.
length
,
1
);
equal
(
server
.
requests
[
0
].
method
,
"
POST
"
);
equal
(
server
.
requests
[
0
].
url
,
cloudoo_url
);
equal
(
server
.
requests
[
0
].
requestBody
,
'
<?xml version="1.0" encoding=
\
"UTF-8
\
"?><methodCall>
'
+
'
<methodName>convertFile</methodName><params><param><value>
'
+
'
<string>ZG9jdW1lbnRhdWZvcm1hdGRvY3g=</string></value></param>
'
+
'
<param><value><string>docx</string></value></param>
'
+
'
<param><value><string>docy
'
+
'
</string></value></param></params></methodCall>
'
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
/////////////////////////////////////////////////////////////////
// CloudooStorage.repair
/////////////////////////////////////////////////////////////////
...
...
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