Confirm continuing the transfer process if assets backup fakls

This commit is contained in:
Christian Capeans 2023-07-19 12:14:30 +02:00
parent 999ff029f0
commit d04d944fcd
3 changed files with 23 additions and 4 deletions

View File

@ -27,6 +27,7 @@ import type {
SchemaDiffHandler,
SchemaDiffHandlerContext,
AssetsBackupErrorHandler,
AssetsBackupErrorHandlerContext,
} from '../../types';
import type { Diff } from '../utils/json';
@ -749,9 +750,20 @@ class TransferEngine<
async beforeTransfer(): Promise<void> {
const runWithDiagnostic = async (provider: IProvider) => {
const context: AssetsBackupErrorHandlerContext = {};
try {
await provider.beforeTransfer?.();
} catch (error) {
await utils.middleware.runMiddleware<AssetsBackupErrorHandlerContext>(
context,
this.#handlers.assetsBackupError
);
console.log('context', context);
if (context.ignore) {
console.log('Entering here');
return;
}
// Error happening during the before transfer step should be considered fatal errors
if (error instanceof Error) {
this.panic(error);

View File

@ -18,7 +18,11 @@ export type SchemaDiffHandlerContext = {
};
export type SchemaDiffHandler = Middleware<SchemaDiffHandlerContext>;
export type AssetsBackupErrorHandler = Middleware;
export type AssetsBackupErrorHandlerContext = {
ignore?: boolean;
};
export type AssetsBackupErrorHandler = Middleware<AssetsBackupErrorHandlerContext>;
/**
* Defines the capabilities and properties of the transfer engine

View File

@ -349,16 +349,19 @@ const getAssetsBackupHandler = (engine, { force, action }) => {
exitWith(1, exitMessageText(action, true));
});
await confirmMessage(
'There are differences in schema between the source and destination, and the data listed above will be lost. Are you sure you want to continue?',
const confirmed = await confirmMessage(
'The backup folder for the assets could not be created inside the public folder. Maybe Strapi does not have write permissions on the public directory. Do you want to continue without the backup?',
{
force,
}
);
if (confirmed) {
context.ignore = true;
}
// reset handler back to normal
setSignalHandler(() => abortTransfer({ engine, strapi }));
return next(context);
};
};