mirror of
https://github.com/strapi/strapi.git
synced 2025-12-18 02:33:53 +00:00
Merge pull request #15283 from strapi/deits/validate-file-before-restore
This commit is contained in:
commit
11854540ed
@ -159,7 +159,7 @@ class TransferEngine<
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#emitTransferUpdate(type: 'start' | 'finish' | 'error', payload?: object) {
|
#emitTransferUpdate(type: 'init' | 'start' | 'finish' | 'error', payload?: object) {
|
||||||
this.progress.stream.emit(`transfer::${type}`, payload);
|
this.progress.stream.emit(`transfer::${type}`, payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -336,9 +336,8 @@ class TransferEngine<
|
|||||||
// reset data between transfers
|
// reset data between transfers
|
||||||
this.progress.data = {};
|
this.progress.data = {};
|
||||||
|
|
||||||
this.#emitTransferUpdate('start');
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
this.#emitTransferUpdate('init');
|
||||||
await this.bootstrap();
|
await this.bootstrap();
|
||||||
await this.init();
|
await this.init();
|
||||||
|
|
||||||
@ -351,6 +350,8 @@ class TransferEngine<
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.#emitTransferUpdate('start');
|
||||||
|
|
||||||
await this.beforeTransfer();
|
await this.beforeTransfer();
|
||||||
|
|
||||||
// Run the transfer stages
|
// Run the transfer stages
|
||||||
|
|||||||
@ -49,6 +49,8 @@ class LocalFileSourceProvider implements ISourceProvider {
|
|||||||
|
|
||||||
options: ILocalFileSourceProviderOptions;
|
options: ILocalFileSourceProviderOptions;
|
||||||
|
|
||||||
|
#metadata?: IMetadata;
|
||||||
|
|
||||||
constructor(options: ILocalFileSourceProviderOptions) {
|
constructor(options: ILocalFileSourceProviderOptions) {
|
||||||
this.options = options;
|
this.options = options;
|
||||||
|
|
||||||
@ -60,15 +62,16 @@ class LocalFileSourceProvider implements ISourceProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pre flight checks regarding the provided options (making sure that the provided path is correct, etc...)
|
* Pre flight checks regarding the provided options, making sure that the file can be opened (decrypted, decompressed), etc.
|
||||||
*/
|
*/
|
||||||
async bootstrap() {
|
async bootstrap() {
|
||||||
const { path: filePath } = this.options.file;
|
const { path: filePath } = this.options.file;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// This is only to show a nicer error, it doesn't ensure the file will still exist when we try to open it later
|
// Read the metadata to ensure the file can be parsed
|
||||||
await fs.access(filePath, fs.constants.R_OK);
|
this.#metadata = await this.getMetadata();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw new Error(`Can't access file "${filePath}".`);
|
throw new Error(`Can't read file "${filePath}".`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -74,8 +74,6 @@ module.exports = async (opts) => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
logger.log(`Starting export...`);
|
|
||||||
|
|
||||||
const progress = engine.progress.stream;
|
const progress = engine.progress.stream;
|
||||||
|
|
||||||
const getTelemetryPayload = (/* payload */) => {
|
const getTelemetryPayload = (/* payload */) => {
|
||||||
@ -88,6 +86,7 @@ module.exports = async (opts) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
progress.on('transfer::start', async () => {
|
progress.on('transfer::start', async () => {
|
||||||
|
logger.log(`Starting export...`);
|
||||||
await strapi.telemetry.send('didDEITSProcessStart', getTelemetryPayload());
|
await strapi.telemetry.send('didDEITSProcessStart', getTelemetryPayload());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -77,9 +77,8 @@ module.exports = async (opts) => {
|
|||||||
],
|
],
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
const engine = createTransferEngine(source, destination, engineOptions);
|
|
||||||
|
|
||||||
logger.info('Starting import...');
|
const engine = createTransferEngine(source, destination, engineOptions);
|
||||||
|
|
||||||
const progress = engine.progress.stream;
|
const progress = engine.progress.stream;
|
||||||
const getTelemetryPayload = () => {
|
const getTelemetryPayload = () => {
|
||||||
@ -92,6 +91,7 @@ module.exports = async (opts) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
progress.on('transfer::start', async () => {
|
progress.on('transfer::start', async () => {
|
||||||
|
logger.info('Starting import...');
|
||||||
await strapiInstance.telemetry.send('didDEITSProcessStart', getTelemetryPayload());
|
await strapiInstance.telemetry.send('didDEITSProcessStart', getTelemetryPayload());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user