Fix code style error

This commit is contained in:
Matheus Faustino 2018-07-18 20:14:58 -03:00
parent 9c5fcc9037
commit 9b6475e30f
2 changed files with 32 additions and 50 deletions

View File

@ -1,23 +1,19 @@
/* global messageBox */ /* global messageBox */
'use strict'; 'use strict';
onDOMready().then(_ => { onDOMready().then(() => {
zip.workerScriptsPath = "/vendor/zipjs/"; zip.workerScriptsPath = '/vendor/zipjs/';
}); });
function createZipFileFromText(filename, text) { function createZipFileFromText(filename, text) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
// use a BlobWriter to store the zip into a Blob object
zip.createWriter(new zip.BlobWriter('application/zip'), writer => { zip.createWriter(new zip.BlobWriter('application/zip'), writer => {
// use a TextReader to read the String to add
writer.add(filename, new zip.TextReader(text), function () { writer.add(filename, new zip.TextReader(text), function () {
// close the zip writer
writer.close(blob => { writer.close(blob => {
// blob contains the zip file as a Blob object
resolve(blob); resolve(blob);
}); });
}); });
}, error => reject(error)); }, reject);
}); });
} }
@ -30,6 +26,6 @@ function readZipFileFromBlob(blob) {
resolve(data); resolve(data);
}); });
}); });
}, error => reject(error)) }, reject);
}); });
} }

View File

@ -1,7 +1,7 @@
/* global messageBox */ /* global messageBox */
'use strict'; 'use strict';
const DROPBOX_API_KEY = 'uyfixgzre8v1bkg'; const DROPBOX_API_KEY = '';
const FILENAME_ZIP_FILE = 'stylus.json'; const FILENAME_ZIP_FILE = 'stylus.json';
const DROPBOX_FILE = 'stylus.zip'; const DROPBOX_FILE = 'stylus.zip';
const API_ERROR_STATUS_FILE_NOT_FOUND = 409; const API_ERROR_STATUS_FILE_NOT_FOUND = 409;
@ -18,7 +18,7 @@ function messageProgressBar(data) {
textContent: t('confirmClose'), textContent: t('confirmClose'),
dataset: {cmd: 'close'}, dataset: {cmd: 'close'},
}], }],
}).then(_ => { }).then(() => {
document.body.style.minWidth = ''; document.body.style.minWidth = '';
document.body.style.minHeight = ''; document.body.style.minHeight = '';
}); });
@ -35,10 +35,8 @@ function requestDropboxAccessToken() {
return browserApi.identity.launchWebAuthFlow({url: authUrl, interactive: true}) return browserApi.identity.launchWebAuthFlow({url: authUrl, interactive: true})
.then(urlReturned => { .then(urlReturned => {
const params = new URLSearchParams(new URL(urlReturned).hash.replace('#', '?')); const params = new URLSearchParams(new URL(urlReturned).hash.replace('#', ''));
chromeLocal.setValue('dropbox_access_token', params.get('access_token')); chromeLocal.setValue('dropbox_access_token', params.get('access_token'));
return params.get('access_token'); return params.get('access_token');
}); });
} }
@ -51,13 +49,7 @@ $('#sync-dropbox-export').onclick = () => {
messageProgressBar({title: t('bckpDropboxStyles'), text: t('connectingDropbox')}); messageProgressBar({title: t('bckpDropboxStyles'), text: t('connectingDropbox')});
hasDropboxAccessToken().then(token => { hasDropboxAccessToken().then(token => token || requestDropboxAccessToken())
if (typeof token === 'undefined') {
return requestDropboxAccessToken();
}
return token;
})
.then(token => { .then(token => {
const client = new Dropbox.Dropbox({ const client = new Dropbox.Dropbox({
clientId: DROPBOX_API_KEY, clientId: DROPBOX_API_KEY,
@ -65,63 +57,63 @@ $('#sync-dropbox-export').onclick = () => {
}); });
return client.filesDownload({path: '/' + DROPBOX_FILE}) return client.filesDownload({path: '/' + DROPBOX_FILE})
.then(_ => messageBox.confirm(t('overwriteFileExport'))) .then(() => messageBox.confirm(t('overwriteFileExport')))
.then(ok => { .then(ok => {
/** deletes file if user want to */ // deletes file if user want to
if (!ok) { if (!ok) {
return Promise.reject({status: HTTP_STATUS_CANCEL}); return Promise.reject({status: HTTP_STATUS_CANCEL});
} }
return client.filesDelete({path: '/' + DROPBOX_FILE}); return client.filesDelete({path: '/' + DROPBOX_FILE});
}) })
/** file deleted with success, get styles and create a file */ // file deleted with success, get styles and create a file
.then(_ => { .then(() => {
messageProgressBar({title: t('bckpDropboxStyles'), text: t('gettingStyles') }); messageProgressBar({title: t('bckpDropboxStyles'), text: t('gettingStyles')});
return API.getStyles().then(styles => JSON.stringify(styles, null, '\t')); return API.getStyles().then(styles => JSON.stringify(styles, null, '\t'));
}) })
/** create zip file */ // create zip file
.then(stylesText => { .then(stylesText => {
messageProgressBar({title: t('bckpDropboxStyles'), text: t('compactStyles') }); messageProgressBar({title: t('bckpDropboxStyles'), text: t('compactStyles')});
return createZipFileFromText(FILENAME_ZIP_FILE, stylesText); return createZipFileFromText(FILENAME_ZIP_FILE, stylesText);
}) })
/** create file dropbox */ // create file dropbox
.then(zipedText =>{ .then(zipedText =>{
messageProgressBar({title: t('bckpDropboxStyles'), text: t('uploadingFile') }); messageProgressBar({title: t('bckpDropboxStyles'), text: t('uploadingFile')});
return uploadFileDropbox(client, zipedText); return uploadFileDropbox(client, zipedText);
}) })
/** gives feedback to user */ // gives feedback to user
.then(_ => messageProgressBar({title: t('bckpDropboxStyles'), text: t('exportSavedSuccess') })) .then(() => messageProgressBar({title: t('bckpDropboxStyles'), text: t('exportSavedSuccess')}))
/* handle not found cases and cancel action */ // handle not found cases and cancel action
.catch(error => { .catch(error => {
/* saving file first time */ // saving file first time
if (error.status === API_ERROR_STATUS_FILE_NOT_FOUND) { if (error.status === API_ERROR_STATUS_FILE_NOT_FOUND) {
API.getStyles() API.getStyles()
.then(styles => { .then(styles => {
messageProgressBar({title: t('bckpDropboxStyles'), text: t('gettingStyles') }); messageProgressBar({title: t('bckpDropboxStyles'), text: t('gettingStyles')});
return JSON.stringify(styles, null, '\t'); return JSON.stringify(styles, null, '\t');
}) })
.then(stylesText => { .then(stylesText => {
messageProgressBar({title: t('bckpDropboxStyles'), text: t('compactStyles') }); messageProgressBar({title: t('bckpDropboxStyles'), text: t('compactStyles')});
return createZipFileFromText(FILENAME_ZIP_FILE, stylesText); return createZipFileFromText(FILENAME_ZIP_FILE, stylesText);
}) })
.then(zipedText => { .then(zipedText => {
messageProgressBar({title: t('bckpDropboxStyles'), text: t('uploadingFile') }); messageProgressBar({title: t('bckpDropboxStyles'), text: t('uploadingFile')});
return uploadFileDropbox(client, zipedText); return uploadFileDropbox(client, zipedText);
}) })
.then(_ => messageProgressBar({title: t('bckpDropboxStyles'), text: t('exportSavedSuccess') })) .then(() => messageProgressBar({title: t('bckpDropboxStyles'), text: t('exportSavedSuccess')}))
.catch(err => messageBox.alert(err)); .catch(err => messageBox.alert(err));
return; return;
} }
/* user cancelled the flow */ // user cancelled the flow
if (error.status === HTTP_STATUS_CANCEL) { if (error.status === HTTP_STATUS_CANCEL) {
return; return;
} }
@ -133,15 +125,9 @@ $('#sync-dropbox-export').onclick = () => {
$('#sync-dropbox-import').onclick = () => { $('#sync-dropbox-import').onclick = () => {
messageProgressBar({title: t('retrieveDropboxBckp'), text: t('connectingDropbox') }); messageProgressBar({title: t('retrieveDropboxBckp'), text: t('connectingDropbox')});
hasDropboxAccessToken().then(token => { hasDropboxAccessToken().then(token => token || requestDropboxAccessToken())
if (typeof token === 'undefined') {
return requestDropboxAccessToken();
}
return token;
})
.then(token => { .then(token => {
const client = new Dropbox.Dropbox({ const client = new Dropbox.Dropbox({
clientId: DROPBOX_API_KEY, clientId: DROPBOX_API_KEY,
@ -150,16 +136,16 @@ $('#sync-dropbox-import').onclick = () => {
return client.filesDownload({path: '/' + DROPBOX_FILE}) return client.filesDownload({path: '/' + DROPBOX_FILE})
.then(response => { .then(response => {
messageProgressBar({title: t('retrieveDropboxBckp'), text: t('descompactStyles') }); messageProgressBar({title: t('retrieveDropboxBckp'), text: t('descompactStyles')});
return readZipFileFromBlob(response.fileBlob); return readZipFileFromBlob(response.fileBlob);
}) })
.then(zipedFileBlob => { .then(zipedFileBlob => {
messageProgressBar({title: t('retrieveDropboxBckp'), text: t('readingStyles') }); messageProgressBar({title: t('retrieveDropboxBckp'), text: t('readingStyles')});
const fileBlob = zipedFileBlob; const fileBlob = zipedFileBlob;
/* it's based on the import-export.js */ // it's based on the import-export.js
const fReader = new FileReader(); const fReader = new FileReader();
fReader.onloadend = event => { fReader.onloadend = event => {
const text = event.target.result; const text = event.target.result;
@ -178,7 +164,7 @@ $('#sync-dropbox-import').onclick = () => {
fReader.readAsText(fileBlob, 'utf-8'); fReader.readAsText(fileBlob, 'utf-8');
}) })
.catch(error => { .catch(error => {
/* no file */ // no file
if (error.status === API_ERROR_STATUS_FILE_NOT_FOUND) { if (error.status === API_ERROR_STATUS_FILE_NOT_FOUND) {
messageBox.alert(t('noFileToImport')); messageBox.alert(t('noFileToImport'));