Skip to content

Commit

Permalink
chore: fixed linting, moved helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
ae94 committed Oct 14, 2024
1 parent 6e6b6cf commit 3a71083
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
9 changes: 9 additions & 0 deletions admin/src/helpers/blob.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export function b64toBlob(dataURI, type) {
const byteString = atob(dataURI);
const ab = new ArrayBuffer(byteString.length);
const ia = new Uint8Array(ab);
for (let i = 0; i < byteString.length; i++) {
ia[i] = byteString.charCodeAt(i);
}
return new Blob([ab], { type });
}
14 changes: 3 additions & 11 deletions admin/src/state/actions/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*
*/
import { saveAs } from 'file-saver';
import { b64toBlob } from '../../helpers/blob';

export function getAllConfigDiff(toggleNotification, formatMessage, get) {
return async function(dispatch) {
Expand Down Expand Up @@ -52,22 +53,13 @@ export function exportAllConfig(partialDiff, toggleNotification, formatMessage,
}

export function downloadZip(toggleNotification, formatMessage, post, get) {
return async function (dispatch) {
return async function(dispatch) {
dispatch(setLoadingState(true));
try {
const { message, base64Data, name } = await get('/config-sync/zip');
toggleNotification({ type: 'success', message });
if (base64Data) {
function b64toBlob(dataURI) {
const byteString = atob(dataURI);
const ab = new ArrayBuffer(byteString.length);
const ia = new Uint8Array(ab);
for (let i = 0; i < byteString.length; i++) {
ia[i] = byteString.charCodeAt(i);
}
return new Blob([ab], { type: 'image/jpeg' });
}
saveAs(b64toBlob(base64Data), name, { type: 'application/zip' })
saveAs(b64toBlob(base64Data, 'application/zip'), name, { type: 'application/zip' });
}
dispatch(setLoadingState(false));
} catch (err) {
Expand Down
10 changes: 5 additions & 5 deletions server/services/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
const { isEmpty } = require('lodash');
const fs = require('fs');
const util = require('util');
const childProcess = require("child_process");
const difference = require('../utils/getObjectDiff');
const { logMessage } = require('../utils');
const child_process = require("child_process");

/**
* Main services for config import/export.
Expand Down Expand Up @@ -73,11 +73,11 @@ module.exports = () => ({
* @returns {void}
*/
zipConfigFiles: async () => {
const fileName = `config-${new Date().toJSON()}.zip`
child_process.execSync(`zip -r ${fileName} *`, {
cwd: strapi.config.get('plugin.config-sync.syncDir')
const fileName = `config-${new Date().toJSON()}.zip`;
childProcess.execSync(`zip -r ${fileName} *`, {
cwd: strapi.config.get('plugin.config-sync.syncDir'),
});
const fullFilePath = `${strapi.config.get('plugin.config-sync.syncDir')}${fileName}`
const fullFilePath = `${strapi.config.get('plugin.config-sync.syncDir')}${fileName}`;
const base64Data = fs.readFileSync(fullFilePath, { encoding: 'base64' });
fs.unlinkSync(fullFilePath);
return { base64Data, name: fileName, message: 'Success' };
Expand Down

0 comments on commit 3a71083

Please sign in to comment.