From 38563dbe6d5e9b3a620c533ad4ce4085529e02d1 Mon Sep 17 00:00:00 2001 From: Alexander Engel Date: Mon, 14 Oct 2024 11:58:53 -0700 Subject: [PATCH] fix: do not store config file --- admin/src/state/actions/Config.js | 16 +++++++++++++--- package.json | 1 + server/services/main.js | 14 ++------------ yarn.lock | 5 +++++ 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/admin/src/state/actions/Config.js b/admin/src/state/actions/Config.js index a9c6b64..7232366 100644 --- a/admin/src/state/actions/Config.js +++ b/admin/src/state/actions/Config.js @@ -5,6 +5,7 @@ */ import { request } from '@strapi/helper-plugin'; +import { saveAs } from 'file-saver'; export function getAllConfigDiff(toggleNotification) { return async function (dispatch) { @@ -59,12 +60,21 @@ export function downloadZip(toggleNotification) { return async function (dispatch) { dispatch(setLoadingState(true)); try { - const { message, url } = await request('/config-sync/zip', { + const { message, base64Data, name } = await request('/config-sync/zip', { method: 'GET' }); toggleNotification({ type: 'success', message }); - if (url) { - window.location = url; + 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' }) } dispatch(setLoadingState(false)); } catch (err) { diff --git a/package.json b/package.json index 02e9002..2b401f7 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "chalk": "^4.1.2", "cli-table": "^0.3.6", "commander": "^8.3.0", + "file-saver": "^2.0.5", "git-diff": "^2.0.6", "immutable": "^3.8.2", "inquirer": "^8.2.0", diff --git a/server/services/main.js b/server/services/main.js index 3dc5935..4e9fa96 100644 --- a/server/services/main.js +++ b/server/services/main.js @@ -78,19 +78,9 @@ module.exports = () => ({ cwd: strapi.config.get('plugin.config-sync.syncDir') }); const fullFilePath = `${strapi.config.get('plugin.config-sync.syncDir')}${fileName}` - const stats = fs.statSync(fullFilePath); - - const result = await strapi.plugins.upload.services.upload.upload({ - data: {}, //mandatory declare the data(can be empty), otherwise it will give you an undefined error. This parameters will be used to relate the file with a collection. - files: { - path: fullFilePath, - name: `configs/${fileName}`, - type: 'application/zip', // mime type of the file - size: stats.size, - }, - }); + const base64Data = fs.readFileSync(fullFilePath, { encoding: 'base64' }); fs.unlinkSync(fullFilePath); - return { url: result[0].url, message: 'Success' }; + return { base64Data, name: fileName, message: 'Success' }; }, /** diff --git a/yarn.lock b/yarn.lock index 49c0c71..35648a0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2660,6 +2660,11 @@ file-entry-cache@^6.0.1: dependencies: flat-cache "^3.0.4" +file-saver@^2.0.5: + version "2.0.5" + resolved "https://registry.yarnpkg.com/file-saver/-/file-saver-2.0.5.tgz#d61cfe2ce059f414d899e9dd6d4107ee25670c38" + integrity sha512-P9bmyZ3h/PRG+Nzga+rbdI4OEpNDzAVyy74uVO9ATgzLK6VtAsYybF/+TOCvrc0MO793d6+42lLyZTw7/ArVzA== + fill-range@^7.0.1: version "7.0.1" resolved "https://registry.yarnpkg.com/fill-range/-/fill-range-7.0.1.tgz#1919a6a7c75fe38b2c7c77e5198535da9acdda40"