Skip to content

Commit 38563db

Browse files
committed
fix: do not store config file
1 parent 761024c commit 38563db

4 files changed

Lines changed: 21 additions & 15 deletions

File tree

admin/src/state/actions/Config.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
import { request } from '@strapi/helper-plugin';
8+
import { saveAs } from 'file-saver';
89

910
export function getAllConfigDiff(toggleNotification) {
1011
return async function (dispatch) {
@@ -59,12 +60,21 @@ export function downloadZip(toggleNotification) {
5960
return async function (dispatch) {
6061
dispatch(setLoadingState(true));
6162
try {
62-
const { message, url } = await request('/config-sync/zip', {
63+
const { message, base64Data, name } = await request('/config-sync/zip', {
6364
method: 'GET'
6465
});
6566
toggleNotification({ type: 'success', message });
66-
if (url) {
67-
window.location = url;
67+
if (base64Data) {
68+
function b64toBlob(dataURI) {
69+
const byteString = atob(dataURI);
70+
const ab = new ArrayBuffer(byteString.length);
71+
const ia = new Uint8Array(ab);
72+
for (let i = 0; i < byteString.length; i++) {
73+
ia[i] = byteString.charCodeAt(i);
74+
}
75+
return new Blob([ab], { type: 'image/jpeg' });
76+
}
77+
saveAs(b64toBlob(base64Data), name, { type: 'application/zip' })
6878
}
6979
dispatch(setLoadingState(false));
7080
} catch (err) {

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"chalk": "^4.1.2",
2828
"cli-table": "^0.3.6",
2929
"commander": "^8.3.0",
30+
"file-saver": "^2.0.5",
3031
"git-diff": "^2.0.6",
3132
"immutable": "^3.8.2",
3233
"inquirer": "^8.2.0",

server/services/main.js

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -78,19 +78,9 @@ module.exports = () => ({
7878
cwd: strapi.config.get('plugin.config-sync.syncDir')
7979
});
8080
const fullFilePath = `${strapi.config.get('plugin.config-sync.syncDir')}${fileName}`
81-
const stats = fs.statSync(fullFilePath);
82-
83-
const result = await strapi.plugins.upload.services.upload.upload({
84-
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.
85-
files: {
86-
path: fullFilePath,
87-
name: `configs/${fileName}`,
88-
type: 'application/zip', // mime type of the file
89-
size: stats.size,
90-
},
91-
});
81+
const base64Data = fs.readFileSync(fullFilePath, { encoding: 'base64' });
9282
fs.unlinkSync(fullFilePath);
93-
return { url: result[0].url, message: 'Success' };
83+
return { base64Data, name: fileName, message: 'Success' };
9484
},
9585

9686
/**

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2660,6 +2660,11 @@ file-entry-cache@^6.0.1:
26602660
dependencies:
26612661
flat-cache "^3.0.4"
26622662

2663+
file-saver@^2.0.5:
2664+
version "2.0.5"
2665+
resolved "https://registry.yarnpkg.com/file-saver/-/file-saver-2.0.5.tgz#d61cfe2ce059f414d899e9dd6d4107ee25670c38"
2666+
integrity sha512-P9bmyZ3h/PRG+Nzga+rbdI4OEpNDzAVyy74uVO9ATgzLK6VtAsYybF/+TOCvrc0MO793d6+42lLyZTw7/ArVzA==
2667+
26632668
fill-range@^7.0.1:
26642669
version "7.0.1"
26652670
resolved "https://registry.yarnpkg.com/fill-range/-/fill-range-7.0.1.tgz#1919a6a7c75fe38b2c7c77e5198535da9acdda40"

0 commit comments

Comments
 (0)