Skip to content

Commit 3a71083

Browse files
committed
chore: fixed linting, moved helper function
1 parent 6e6b6cf commit 3a71083

3 files changed

Lines changed: 17 additions & 16 deletions

File tree

admin/src/helpers/blob.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export function b64toBlob(dataURI, type) {
2+
const byteString = atob(dataURI);
3+
const ab = new ArrayBuffer(byteString.length);
4+
const ia = new Uint8Array(ab);
5+
for (let i = 0; i < byteString.length; i++) {
6+
ia[i] = byteString.charCodeAt(i);
7+
}
8+
return new Blob([ab], { type });
9+
}

admin/src/state/actions/Config.js

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*
55
*/
66
import { saveAs } from 'file-saver';
7+
import { b64toBlob } from '../../helpers/blob';
78

89
export function getAllConfigDiff(toggleNotification, formatMessage, get) {
910
return async function(dispatch) {
@@ -52,22 +53,13 @@ export function exportAllConfig(partialDiff, toggleNotification, formatMessage,
5253
}
5354

5455
export function downloadZip(toggleNotification, formatMessage, post, get) {
55-
return async function (dispatch) {
56+
return async function(dispatch) {
5657
dispatch(setLoadingState(true));
5758
try {
5859
const { message, base64Data, name } = await get('/config-sync/zip');
5960
toggleNotification({ type: 'success', message });
6061
if (base64Data) {
61-
function b64toBlob(dataURI) {
62-
const byteString = atob(dataURI);
63-
const ab = new ArrayBuffer(byteString.length);
64-
const ia = new Uint8Array(ab);
65-
for (let i = 0; i < byteString.length; i++) {
66-
ia[i] = byteString.charCodeAt(i);
67-
}
68-
return new Blob([ab], { type: 'image/jpeg' });
69-
}
70-
saveAs(b64toBlob(base64Data), name, { type: 'application/zip' })
62+
saveAs(b64toBlob(base64Data, 'application/zip'), name, { type: 'application/zip' });
7163
}
7264
dispatch(setLoadingState(false));
7365
} catch (err) {

server/services/main.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
const { isEmpty } = require('lodash');
44
const fs = require('fs');
55
const util = require('util');
6+
const childProcess = require("child_process");
67
const difference = require('../utils/getObjectDiff');
78
const { logMessage } = require('../utils');
8-
const child_process = require("child_process");
99

1010
/**
1111
* Main services for config import/export.
@@ -73,11 +73,11 @@ module.exports = () => ({
7373
* @returns {void}
7474
*/
7575
zipConfigFiles: async () => {
76-
const fileName = `config-${new Date().toJSON()}.zip`
77-
child_process.execSync(`zip -r ${fileName} *`, {
78-
cwd: strapi.config.get('plugin.config-sync.syncDir')
76+
const fileName = `config-${new Date().toJSON()}.zip`;
77+
childProcess.execSync(`zip -r ${fileName} *`, {
78+
cwd: strapi.config.get('plugin.config-sync.syncDir'),
7979
});
80-
const fullFilePath = `${strapi.config.get('plugin.config-sync.syncDir')}${fileName}`
80+
const fullFilePath = `${strapi.config.get('plugin.config-sync.syncDir')}${fileName}`;
8181
const base64Data = fs.readFileSync(fullFilePath, { encoding: 'base64' });
8282
fs.unlinkSync(fullFilePath);
8383
return { base64Data, name: fileName, message: 'Success' };

0 commit comments

Comments
 (0)