pull/1/head
yflory 5 years ago
parent d593f3961c
commit 4e537e6ddc

@ -830,23 +830,23 @@ define([
var x2tInitialized = false; var x2tInitialized = false;
var x2tInit = function(x2t) { var x2tInit = function(x2t) {
console.log("x2t mount"); console.log("x2t mount");
// x2t.FS.mount(x2t.MEMFS, {} , '/'); // x2t.FS.mount(x2t.MEMFS, {} , '/');
x2t.FS.mkdir('/working'); x2t.FS.mkdir('/working');
x2t.FS.mkdir('/working/media'); x2t.FS.mkdir('/working/media');
console.log("x2t mount done"); console.log("x2t mount done");
} }
/* /*
Converting Data Converting Data
This function converts a data in a specific format to the outputformat This function converts a data in a specific format to the outputformat
The filename extension needs to represent the input format The filename extension needs to represent the input format
Example: fileName=cryptpad.bin outputFormat=xlsx Example: fileName=cryptpad.bin outputFormat=xlsx
*/ */
var x2tConvertDataInternal = function(x2t, data, fileName, outputFormat) { var x2tConvertDataInternal = function(x2t, data, fileName, outputFormat) {
console.log("Converting Data for " + fileName + " to " + outputFormat); console.log("Converting Data for " + fileName + " to " + outputFormat);
// writing file to mounted working disk (in memory) // writing file to mounted working disk (in memory)
x2t.FS.writeFile('/working/' + fileName, data); x2t.FS.writeFile('/working/' + fileName, data);
// Adding images // Adding images
for (var mediaFileName in window.frames[0].AscCommon.g_oDocumentUrls.urls) { for (var mediaFileName in window.frames[0].AscCommon.g_oDocumentUrls.urls) {
@ -858,31 +858,31 @@ define([
console.log("Writing media data " + mediaFileName); console.log("Writing media data " + mediaFileName);
console.log("Data"); console.log("Data");
var fileData = mediaData.content; var fileData = mediaData.content;
x2t.FS.writeFile('/working/media/' + mediaFileName, new Uint8Array(fileData)); x2t.FS.writeFile('/working/media/' + mediaFileName, new Uint8Array(fileData));
} else { } else {
console.log("Could not find media content for " + mediaFileName); console.log("Could not find media content for " + mediaFileName);
} }
} }
var params = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" var params = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
+ "<TaskQueueDataConvert xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" + "<TaskQueueDataConvert xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">"
+ "<m_sFileFrom>/working/" + fileName + "</m_sFileFrom>" + "<m_sFileFrom>/working/" + fileName + "</m_sFileFrom>"
+ "<m_sFileTo>/working/" + fileName + "." + outputFormat + "</m_sFileTo>" + "<m_sFileTo>/working/" + fileName + "." + outputFormat + "</m_sFileTo>"
+ "<m_bIsNoBase64>false</m_bIsNoBase64>" + "<m_bIsNoBase64>false</m_bIsNoBase64>"
+ "</TaskQueueDataConvert>" + "</TaskQueueDataConvert>"
// writing params file to mounted working disk (in memory) // writing params file to mounted working disk (in memory)
x2t.FS.writeFile('/working/params.xml', params); x2t.FS.writeFile('/working/params.xml', params);
// running conversion // running conversion
x2t.ccall("runX2T", ["number"], ["string"], ["/working/params.xml"]); x2t.ccall("runX2T", ["number"], ["string"], ["/working/params.xml"]);
// reading output file from working disk (in memory) // reading output file from working disk (in memory)
try { try {
var result = x2t.FS.readFile('/working/' + fileName + "." + outputFormat); var result = x2t.FS.readFile('/working/' + fileName + "." + outputFormat);
} catch (e) { } catch (e) {
console.log("Failed reading converted file"); console.log("Failed reading converted file");
return ""; return "";
} }
return result; return result;
} }
var x2tSaveAndConvertDataInternal = function(x2t, data, filename, extension, finalFilename) { var x2tSaveAndConvertDataInternal = function(x2t, data, filename, extension, finalFilename) {
var xlsData = x2tConvertDataInternal(x2t, data, filename, extension); var xlsData = x2tConvertDataInternal(x2t, data, filename, extension);
@ -904,12 +904,12 @@ define([
x2t.onRuntimeInitialized = function() { x2t.onRuntimeInitialized = function() {
console.log("x2t in runtime initialized"); console.log("x2t in runtime initialized");
// Init x2t js module // Init x2t js module
x2tInit(x2t); x2tInit(x2t);
x2tInitialized = true; x2tInitialized = true;
x2tSaveAndConvertDataInternal(x2t, data, filename, extension, finalFilename); x2tSaveAndConvertDataInternal(x2t, data, filename, extension, finalFilename);
} }
}); });
} }
@ -936,13 +936,13 @@ define([
} else { } else {
console.log("Import image " + i); console.log("Import image " + i);
var handleFileData = { var handleFileData = {
name: images[i], name: images[i],
mediasSources: getMediasSources(), mediasSources: getMediasSources(),
callback: function() { callback: function() {
console.log("next image"); console.log("next image");
x2tImportImagesInternal(x2t, images, i+1, callback); x2tImportImagesInternal(x2t, images, i+1, callback);
}, },
}; };
var filePath = "/working/media/" + images[i]; var filePath = "/working/media/" + images[i];
console.log("Import filename " + filePath); console.log("Import filename " + filePath);
var fileData = x2t.FS.readFile("/working/media/" + images[i], { encoding : "binary" }); var fileData = x2t.FS.readFile("/working/media/" + images[i], { encoding : "binary" });
@ -951,7 +951,7 @@ define([
console.log(fileData.buffer); console.log(fileData.buffer);
var blob = new Blob([fileData.buffer], {type: 'image/png'}); var blob = new Blob([fileData.buffer], {type: 'image/png'});
blob.name = images[i]; blob.name = images[i];
APP.FMImages.handleFile(blob, handleFileData); APP.FMImages.handleFile(blob, handleFileData);
} }
} }
@ -961,8 +961,8 @@ define([
noHandlers: true, noHandlers: true,
noStore: true, noStore: true,
body: $('body'), body: $('body'),
onUploaded: function (ev, data) { onUploaded: function (ev, data) {
if (!ev.callback) { return; } if (!ev.callback) { return; }
console.log("Image uploaded at " + data.url); console.log("Image uploaded at " + data.url);
var parsed = Hash.parsePadUrl(data.url); var parsed = Hash.parsePadUrl(data.url);
if (parsed.type === 'file') { if (parsed.type === 'file') {
@ -970,12 +970,12 @@ define([
var fileHost = privateData.fileHost || privateData.origin; var fileHost = privateData.fileHost || privateData.origin;
var src = fileHost + Hash.getBlobPathFromHex(secret.channel); var src = fileHost + Hash.getBlobPathFromHex(secret.channel);
var key = Hash.encodeBase64(secret.keys.cryptKey); var key = Hash.encodeBase64(secret.keys.cryptKey);
console.log("Final src: " + src); console.log("Final src: " + src);
ev.mediasSources[ev.name] = { name : ev.name, src : src, key : key }; ev.mediasSources[ev.name] = { name : ev.name, src : src, key : key };
} }
ev.callback(); ev.callback();
} }
}; };
APP.FMImages = common.createFileManager(fmConfigImages); APP.FMImages = common.createFileManager(fmConfigImages);
} }
@ -984,9 +984,9 @@ define([
var files = x2t.FS.readdir("/working/media/"); var files = x2t.FS.readdir("/working/media/");
var images = []; var images = [];
files.forEach(file => { files.forEach(file => {
if (file!="." && file!="..") if (file!="." && file!="..")
images.push(file); images.push(file);
}); });
x2tImportImagesInternal(x2t, images, 0, function() { x2tImportImagesInternal(x2t, images, 0, function() {
console.log("Sync media sources elements"); console.log("Sync media sources elements");
console.log(getMediasSources()); console.log(getMediasSources());
@ -1001,9 +1001,9 @@ define([
var convertedContent; var convertedContent;
if (filename.endsWith(".ods")) { if (filename.endsWith(".ods")) {
convertedContent = x2tConvertDataInternal(x2t, new Uint8Array(data), filename, "xlsx"); convertedContent = x2tConvertDataInternal(x2t, new Uint8Array(data), filename, "xlsx");
convertedContent = x2tConvertDataInternal(x2t, convertedContent, filename + ".xlsx", extension); convertedContent = x2tConvertDataInternal(x2t, convertedContent, filename + ".xlsx", extension);
} else { } else {
convertedContent = x2tConvertDataInternal(x2t, new Uint8Array(data), filename, extension); convertedContent = x2tConvertDataInternal(x2t, new Uint8Array(data), filename, extension);
} }
x2tImportImages(x2t, function() { x2tImportImages(x2t, function() {
callback(convertedContent); callback(convertedContent);
@ -1031,7 +1031,7 @@ define([
x2tInitialized = true; x2tInitialized = true;
var convertedContent = x2tConvertData(x2t, new Uint8Array(content), filename.name, "bin", function(convertedContent) { var convertedContent = x2tConvertData(x2t, new Uint8Array(content), filename.name, "bin", function(convertedContent) {
importFile(convertedContent); importFile(convertedContent);
}); });
} }
}); });
} }
@ -1225,14 +1225,18 @@ define([
var $export = common.createButton('export', true, {}, exportFile); var $export = common.createButton('export', true, {}, exportFile);
$export.appendTo($rightside); $export.appendTo($rightside);
var $exportXLSX = common.createButton('export', true, {}, exportXLSXFile); if (typeof(Atomics) !== "undefined") {
$exportXLSX.appendTo($rightside); var $exportXLSX = common.createButton('export', true, {}, exportXLSXFile);
$exportXLSX.appendTo($rightside);
}
var $import = common.createButton('import', true, {}, importFile); var $import = common.createButton('import', true, {}, importFile);
$import.appendTo($rightside); $import.appendTo($rightside);
var $importXLSX = common.createButton('import', true, { accept: ["xlsx"], types: ["xlsx"], binary : true }, importXLSXFile); if (typeof(Atomics) !== "undefined") {
$importXLSX.appendTo($rightside); var $importXLSX = common.createButton('import', true, { accept: ["xlsx"], types: ["xlsx"], binary : true }, importXLSXFile);
$importXLSX.appendTo($rightside);
}
if (common.isLoggedIn()) { if (common.isLoggedIn()) {
common.createButton('hashtag', true).appendTo($rightside); common.createButton('hashtag', true).appendTo($rightside);

Loading…
Cancel
Save