Commit 769ea29c authored by Vincent Bechu's avatar Vincent Bechu

[erp5_officejs] Fix upload with erp5 storage

parent 693fe005
......@@ -16,7 +16,7 @@
return gadget.reload();
});
}
return gadget.repair()
return new RSVP.Queue()
.push(function () {
if (gadget.state.cloudooo) {
return gadget.getDeclaredGadget('cloudooo')
......@@ -25,6 +25,9 @@
});
}
})
.push(function () {
return gadget.repair();
})
.push(function () {
if (gadget.state.redirect) {
return gadget.redirect(window.JSON.parse(gadget.state.redirect));
......
......@@ -230,7 +230,7 @@
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>P0</string> </value>
<value> <string>zope</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
......@@ -244,7 +244,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>969.27633.19787.19507</string> </value>
<value> <string>969.42224.7621.358</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -262,7 +262,7 @@
</tuple>
<state>
<tuple>
<float>1533639756.16</float>
<float>1534757989.87</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -3,6 +3,65 @@
(function (window, rJS, jIO, RSVP) {
"use strict";
function fixDocument(gadget, id) {
var doc, from, name_list;
return gadget.jio_get(id)
.push(function (result) {
doc = result;
delete doc.mime_type;
return RSVP.all([
gadget.getSetting('parent_relative_url'),
gadget.getSetting('file_extension')
]);
})
.push(function (result) {
doc.parent_relative_url = result[0];
if (doc.filename.indexOf(result[1]) < 0) {
name_list = doc.filename.split('.');
from = name_list.pop();
name_list.push(result[1]);
doc.filename = name_list.join('.');
return gadget.jio_put(
'CloudoooConversion/' + id + '/' + result[1],
{
status: 'convert',
from: from,
to: result[1],
id: id,
name: from,
to_name: 'data'
}
)
.push(function () {
return gadget.jio_getAttachment(id, 'data');
})
.push(function (blob) {
return gadget.jio_putAttachment(id, from, blob);
});
}
})
.push(function () {
return gadget.jio_put(id, doc);
});
}
function fixAllDocument(gadget) {
return gadget.getSetting('portal_type')
.push(function (portal_type) {
return gadget.jio_allDocs({
'query': '(portal_type: "' + portal_type +
'") AND (mime_type: "%")'
});
})
.push(function (result) {
var i, promise_list = [];
for (i = 0; i < result.data.total_rows; i += 1) {
promise_list.push(fixDocument(gadget, result.data.rows[i].id));
}
return RSVP.all(promise_list);
});
}
rJS(window)
.ready(function (g) {
g.getDeclaredGadget("jio")
......@@ -24,6 +83,7 @@
.declareAcquiredMethod("jio_allDocs", "jio_allDocs")
.declareAcquiredMethod("jio_put", "jio_put")
.declareAcquiredMethod("jio_get", "jio_get")
.declareAcquiredMethod("getSetting", "getSetting")
/////////////////////////////////////////////////////////////////
// declared methods
......@@ -32,7 +92,7 @@
var gadget = this;
return gadget.jio_get(id)
.push(function (doc) {
return gadget.convert(doc.id, doc.name, doc.from, doc.to)
return gadget.convert(doc)
.push(function () {
doc.status = "converted";
return gadget.jio_put(id, doc);
......@@ -46,24 +106,28 @@
});
});
})
.declareMethod("convert", function (id, name, from, to) {
.declareMethod("convert", function (options) {
var gadget = this, jio_gadget;
return gadget.getDeclaredGadget("jio")
.push(function (sub_gadget) {
jio_gadget = sub_gadget;
return RSVP.all([
gadget.jio_getAttachment(id, name),
jio_gadget.put(id, {from: from, to: to})
gadget.jio_getAttachment(options.id, options.name),
jio_gadget.put(options.id, {from: options.from, to: options.to})
]);
})
.push(function (result) {
return jio_gadget.putAttachment(id, name, result[0]);
return jio_gadget.putAttachment(options.id, options.name, result[0]);
})
.push(function () {
return jio_gadget.getAttachment(id, name);
return jio_gadget.getAttachment(options.id, options.name);
})
.push(function (converted_blob) {
return gadget.jio_putAttachment(id, to, converted_blob);
return gadget.jio_putAttachment(
options.id,
options.to_name || options.to,
converted_blob
);
});
})
.declareMethod('repair', function () {
......@@ -77,9 +141,12 @@
return gadget.convertFromOperation(rows[i].id);
});
}
return gadget.jio_allDocs({
'query': 'status: "convert"'
})
return fixAllDocument(gadget)
.push(function () {
return gadget.jio_allDocs({
'query': 'status: "convert"'
});
})
.push(function (result) {
var i = result.data.total_rows - 1;
return convertAndPush(result.data.rows, i);
......
......@@ -255,7 +255,7 @@
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>P0</string> </value>
<value> <string>zope</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
......@@ -269,7 +269,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>969.27633.19787.19507</string> </value>
<value> <string>969.46608.54855.3123</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -287,7 +287,7 @@
</tuple>
<state>
<tuple>
<float>1533639646.43</float>
<float>1534778298.94</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -3,9 +3,6 @@
(function (window, rJS, RSVP, jIO) {
"use strict";
var ATT_NAME = "data";
function downloadFromBlob(gadget, blob, format) {
var element = gadget.element,
a = window.document.createElement("a"),
......@@ -21,12 +18,43 @@
window.URL.revokeObjectURL(url);
}
function downloadFromFormat(gadget, format) {
return gadget.getDeclaredGadget('ojs_cloudooo')
.push(function (ojs_cloudooo) {
return ojs_cloudooo.getConvertedBlob({
jio_key: gadget.state.jio_key,
format: format,
redirect: jIO.util.stringify({
'command': 'display',
'options': {
'page': 'ojs_download_convert',
'jio_key': gadget.state.jio_key,
'download_format': format
}
})
});
})
.push(function (result) {
return downloadFromBlob(gadget, result, format);
})
.push(function () {
return gadget.notifySubmitted();
}, function (error) {
if (error instanceof jIO.util.jIOError) {
return gadget.notifySubmitted({
message: "Conversion Failed",
status: "error"
});
}
throw error;
});
}
rJS(window)
/////////////////////////////////////////////////////////////////
// Acquired methods
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareAcquiredMethod("redirect", "redirect")
.declareAcquiredMethod("updateHeader", "updateHeader")
.declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("jio_get", "jio_get")
......@@ -37,7 +65,7 @@
// declared methods
/////////////////////////////////////////////////////////////////
.allowPublicAcquisition('submitContent', function () {
var gadget = this, format;
var gadget = this;
return gadget.notifySubmitting()
.push(function () {
......@@ -47,52 +75,7 @@
return form_gadget.getContent();
})
.push(function (result) {
format = result.format;
if (format === gadget.state.format) {
return gadget.jio_getAttachment(gadget.state.jio_key, ATT_NAME);
}
return gadget.getDeclaredGadget('ojs_cloudooo')
.push(function (ojs_cloudooo) {
return ojs_cloudooo.getConvertedBlob({
jio_key: gadget.state.jio_key,
format: format,
filename: gadget.state.doc.filename
});
});
})
.push(function (result) {
return downloadFromBlob(gadget, result, format);
}, function (error) {
if (error instanceof jIO.util.jIOError &&
error.status_code === 500 &&
error.message === "Not converted") {
return gadget.redirect({
'command': 'display',
'options': {
'page': 'ojs_sync',
'auto_repair': true,
'redirect': jIO.util.stringify({
'command': 'display',
'options': {
'page': 'ojs_download_convert',
'jio_key': gadget.state.jio_key
}
})
}
});
}
throw error;
})
.push(function () {
return gadget.notifySubmitted();
}, function (error) {
if (error instanceof jIO.util.jIOError) {
return gadget.notifySubmitted({
message: "Conversion Failed",
status: "error"
});
}
throw error;
return downloadFromFormat(gadget, result.format);
})
.push(function () {
return;
......@@ -105,12 +88,19 @@
.declareMethod("render", function (options) {
var gadget = this;
return gadget.jio_get(options.jio_key)
.push(function (doc) {
return new RSVP.Queue()
.push(function () {
return RSVP.all([
gadget.jio_get(options.jio_key),
gadget.getSetting('file_extension')
]);
})
.push(function (result) {
return gadget.changeState({
jio_key: options.jio_key,
doc: doc,
format: doc.filename.split('.').pop()
doc: result[0],
format: result[1],
download_format: options.download_format
});
});
})
......@@ -173,6 +163,11 @@
previous_url: url_list[1],
next_url: url_list[2]
});
})
.push(function () {
if (gadget.state.download_format) {
return downloadFromFormat(gadget, gadget.state.download_format);
}
});
});
}(window, rJS, RSVP, jIO));
\ No newline at end of file
......@@ -242,7 +242,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>969.40397.55907.1280</string> </value>
<value> <string>969.46498.50089.26265</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -260,7 +260,7 @@
</tuple>
<state>
<tuple>
<float>1534406300.95</float>
<float>1534771376.27</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -33,27 +33,34 @@
form_gadget.getContent(),
gadget.getSetting('portal_type'),
gadget.getSetting('content_type'),
gadget.getSetting('file_extension')
gadget.getSetting('file_extension'),
gadget.getSetting('parent_relative_url')
]);
})
.push(function (result) {
var file_name, from, jio_key, data, to;
var file_name_list, from, jio_key, data, to, att_name = ATT_NAME,
filename;
if (result[0].file !== undefined) {
file_name = result[0].file.file_name;
from = file_name.split('.').pop();
file_name_list = result[0].file.file_name.split('.');
from = file_name_list.pop();
file_name_list.push(result[3]);
filename = file_name_list.join('.');
data = jIO.util.dataURItoBlob(result[0].file.url);
if (gadget.state.upload.hasOwnProperty(from)) {
if (result[3] !== from) {
att_name = from;
}
to = gadget.state.upload[from];
return gadget.jio_post({
title: file_name,
title: filename,
portal_type: result[1],
content_type: result[2],
filename: file_name,
mime_type: from
filename: filename,
parent_relative_url: result[4]
})
.push(function (doc_id) {
jio_key = doc_id;
return gadget.jio_putAttachment(jio_key, ATT_NAME, data);
return gadget.jio_putAttachment(jio_key, att_name, data);
})
.push(function () {
if (result[3] === from) {
......@@ -61,12 +68,31 @@
}
return gadget.getDeclaredGadget('ojs_cloudooo')
.push(function (ojs_cloudooo) {
return ojs_cloudooo.putCloudoooConvertOperation({
status: "convert",
from: from,
to: to,
id: jio_key,
name: ATT_NAME
return RSVP.all([
ojs_cloudooo.putCloudoooConvertOperation({
status: "convert",
from: from,
to: to,
id: jio_key,
name: att_name,
to_name: ATT_NAME
}),
ojs_cloudooo.putCloudoooConvertOperation({
status: "converted",
from: to,
to: from,
id: jio_key,
name: ATT_NAME
})
]);
})
.push(function () {
return gadget.redirect({
'command': 'display',
'options': {
'page': 'ojs_sync',
'auto_repair': true
}
});
});
})
......@@ -74,12 +100,7 @@
return gadget.redirect({
'command': 'display',
'options': {
'page': 'ojs_sync',
'auto_repair': true,
'redirect': jIO.util.stringify({
'command': 'display',
'options': {'jio_key': jio_key}
})
'jio_key': jio_key
}
});
});
......@@ -88,18 +109,15 @@
message: "Can not convert, use format : " +
window.Object.keys(gadget.state.upload).join(', '),
status: "error"
})
.push(function () {
return;
});
});
}
return gadget.notifySubmitted({
message: "File is required",
status: "error"
})
.push(function () {
return;
});
});
})
.push(function () {
return;
});
})
......
......@@ -228,7 +228,7 @@
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>P0</string> </value>
<value> <string>zope</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
......@@ -242,7 +242,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>969.27633.19787.19507</string> </value>
<value> <string>969.46490.21150.57958</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -260,7 +260,7 @@
</tuple>
<state>
<tuple>
<float>1533639694.58</float>
<float>1534779925.16</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -19,40 +19,62 @@
.declareAcquiredMethod("jio_put", "jio_put")
.declareAcquiredMethod("jio_get", "jio_get")
.declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("redirect", "redirect")
/////////////////////////////////////////////////////////////////
// declared methods
/////////////////////////////////////////////////////////////////
.declareMethod("getConvertedBlob", function (options) {
var gadget = this,
mime_type = options.filename.split('.').pop();
if (mime_type === options.format) {
return gadget.jio_getAttachment(options.jio_key, ATT_NAME);
}
return gadget.jio_get(
getCloudoooId(options.jio_key, options.format)
)
.push(function (doc) {
var err, obj;
if (doc.status === "converted") {
return gadget.jio_getAttachment(options.jio_key, options.format);
}
if (doc.status === "error") {
obj = window.JSON.parse(doc.error);
err = new jIO.util.jIOError(obj.message, obj.status_code);
err.detail = obj.detail;
} else {
err = new jIO.util.jIOError("Not converted", 500);
var gadget = this;
return gadget.getSetting('file_extension')
.push(function (file_extension) {
if (file_extension === options.format) {
return gadget.jio_getAttachment(options.jio_key, ATT_NAME);
}
throw err;
}, function (error) {
if (error instanceof jIO.util.jIOError && error.status_code === 404) {
return gadget.putAllCloudoooConvertionOperation({
format: mime_type,
jio_key: options.jio_key
return gadget.jio_get(
getCloudoooId(options.jio_key, options.format)
)
.push(function (doc) {
var err, obj;
if (doc.status === "converted") {
return gadget.jio_getAttachment(options.jio_key, options.format);
}
if (doc.status === "error") {
obj = window.JSON.parse(doc.error);
err = new jIO.util.jIOError(obj.message, obj.status_code);
err.detail = obj.detail;
} else {
return gadget.redirect({
'command': 'display',
'options': {
'page': 'ojs_sync',
'auto_repair': true,
'redirect': options.redirect
}
});
}
throw err;
}, function (error) {
if (error instanceof jIO.util.jIOError && error.status_code === 404) {
return gadget.putAllCloudoooConvertionOperation({
format: file_extension,
jio_key: options.jio_key
})
.push(function () {
if (options.redirect) {
return gadget.redirect({
'command': 'display',
'options': {
'page': 'ojs_sync',
'auto_repair': true,
'redirect': options.redirect
}
});
}
});
}
throw error;
});
}
throw error;
});
})
.declareMethod("putCloudoooConvertOperation", function (options) {
......@@ -78,7 +100,7 @@
from: options.format,
to: format_list[i],
id: options.jio_key,
name: ATT_NAME
name: options.format === result[1] ? ATT_NAME : options.format
}));
}
return RSVP.all(promise_list);
......
......@@ -269,7 +269,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>969.32112.45524.32443</string> </value>
<value> <string>969.46486.51629.28689</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -287,7 +287,7 @@
</tuple>
<state>
<tuple>
<float>1534407519.6</float>
<float>1534770737.04</float>
<string>UTC</string>
</tuple>
</state>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment