fix: do not store config file
parent
761024cc74
commit
38563dbe6d
|
@ -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) {
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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' };
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue