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, SchemaDiffHandler,
SchemaDiffHandlerContext, SchemaDiffHandlerContext,
AssetsBackupErrorHandler, AssetsBackupErrorHandler,
AssetsBackupErrorHandlerContext,
} from '../../types'; } from '../../types';
import type { Diff } from '../utils/json'; import type { Diff } from '../utils/json';
@ -749,9 +750,20 @@ class TransferEngine<
async beforeTransfer(): Promise<void> { async beforeTransfer(): Promise<void> {
const runWithDiagnostic = async (provider: IProvider) => { const runWithDiagnostic = async (provider: IProvider) => {
const context: AssetsBackupErrorHandlerContext = {};
try { try {
await provider.beforeTransfer?.(); await provider.beforeTransfer?.();
} catch (error) { } 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 // Error happening during the before transfer step should be considered fatal errors
if (error instanceof Error) { if (error instanceof Error) {
this.panic(error); this.panic(error);

View File

@ -18,7 +18,11 @@ export type SchemaDiffHandlerContext = {
}; };
export type SchemaDiffHandler = Middleware<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 * 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)); exitWith(1, exitMessageText(action, true));
}); });
await confirmMessage( const confirmed = 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?', '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, force,
} }
); );
if (confirmed) {
context.ignore = true;
}
// reset handler back to normal // reset handler back to normal
setSignalHandler(() => abortTransfer({ engine, strapi })); setSignalHandler(() => abortTransfer({ engine, strapi }));
return next(context); return next(context);
}; };
}; };