79c6506c5c
* Implement Dropbox export (#82) * Remove wrong dropbox api key * Improve implementation of Dropbox by using identity.launchWebAuthFlow api and get rid of web_accessible_resources * We don't need a dropbox receiver anymore, remove constante with the html file * Implement compression in dropbox export * Add LICENSE file from dropbox and zipjs * Fix code style error * Fix code style and folder structure of the feature * Fix eslint error in dropbox implementation * Add real dropbox api key from stylus dropbox account * For test only: fixed addon's ID on firefox * Change the file not found message to a better one * Add dropdown style on export and import buttons * Changes arrow from buttons to svg * Remove applications entry on manifest.json * Remove unnecessary break line
42 lines
1.1 KiB
JavaScript
42 lines
1.1 KiB
JavaScript
/* global messageBox */
|
|
/* global zip */
|
|
'use strict';
|
|
|
|
onDOMready().then(() => {
|
|
zip.workerScriptsPath = '/sync/vendor/zipjs/';
|
|
});
|
|
|
|
/**
|
|
* @param {String} filename
|
|
* @param {String} text content of the file as text
|
|
* @returns {Promise<Blob>} resolves to a blob object representing the zip file
|
|
*/
|
|
function createZipFileFromText(filename, text) {
|
|
return new Promise((resolve, reject) => {
|
|
zip.createWriter(new zip.BlobWriter('application/zip'), writer => {
|
|
writer.add(filename, new zip.TextReader(text), function () {
|
|
writer.close(blob => {
|
|
resolve(blob);
|
|
});
|
|
});
|
|
}, reject);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* @param {Object} blob object of zip file
|
|
* @returns {Promise<String>} resolves to a string the content of the first file of the zip
|
|
*/
|
|
function readZipFileFromBlob(blob) {
|
|
return new Promise((resolve, reject) => {
|
|
zip.createReader(new zip.BlobReader(blob), zipReader => {
|
|
zipReader.getEntries(entries => {
|
|
entries[0].getData(new zip.BlobWriter('text/plain'), data => {
|
|
zipReader.close();
|
|
resolve(data);
|
|
});
|
|
});
|
|
}, reject);
|
|
});
|
|
}
|