Merge pull request #15283 from strapi/deits/validate-file-before-restore

This commit is contained in:
Ben Irvin 2022-12-29 10:58:40 +01:00 committed by GitHub
commit 11854540ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 11 deletions

View File

@ -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);
}
@ -336,9 +336,8 @@ class TransferEngine<
// reset data between transfers
this.progress.data = {};
this.#emitTransferUpdate('start');
try {
this.#emitTransferUpdate('init');
await this.bootstrap();
await this.init();
@ -351,6 +350,8 @@ class TransferEngine<
);
}
this.#emitTransferUpdate('start');
await this.beforeTransfer();
// Run the transfer stages

View File

@ -49,6 +49,8 @@ class LocalFileSourceProvider implements ISourceProvider {
options: ILocalFileSourceProviderOptions;
#metadata?: IMetadata;
constructor(options: ILocalFileSourceProviderOptions) {
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() {
const { path: filePath } = this.options.file;
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
await fs.access(filePath, fs.constants.R_OK);
// Read the metadata to ensure the file can be parsed
this.#metadata = await this.getMetadata();
} catch (e) {
throw new Error(`Can't access file "${filePath}".`);
throw new Error(`Can't read file "${filePath}".`);
}
}

View File

@ -74,8 +74,6 @@ module.exports = async (opts) => {
},
});
logger.log(`Starting export...`);
const progress = engine.progress.stream;
const getTelemetryPayload = (/* payload */) => {
@ -88,6 +86,7 @@ module.exports = async (opts) => {
};
progress.on('transfer::start', async () => {
logger.log(`Starting export...`);
await strapi.telemetry.send('didDEITSProcessStart', getTelemetryPayload());
});

View File

@ -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 getTelemetryPayload = () => {
@ -92,6 +91,7 @@ module.exports = async (opts) => {
};
progress.on('transfer::start', async () => {
logger.info('Starting import...');
await strapiInstance.telemetry.send('didDEITSProcessStart', getTelemetryPayload());
});