@@ -13,6 +13,7 @@ import { SteamAPI } from './api/apis/SteamAPI';
1313import { WikipediaAPI } from './api/apis/WikipediaAPI' ;
1414import { ComicVineAPI } from './api/apis/ComicVineAPI' ;
1515import { MediaDbFolderImportModal } from './modals/MediaDbFolderImportModal' ;
16+ import { ConfirmOverwriteModal } from './modals/ConfirmOverwriteModal' ;
1617import type { MediaTypeModel } from './models/MediaTypeModel' ;
1718import { PropertyMapper } from './settings/PropertyMapper' ;
1819import { PropertyMapping , PropertyMappingModel } from './settings/PropertyMapping' ;
@@ -508,17 +509,25 @@ export default class MediaDbPlugin extends Plugin {
508509 fileName = replaceIllegalFileNameCharactersInString ( fileName ) ;
509510 const filePath = `${ folder . path } /${ fileName } .md` ;
510511
511- // find and delete file with the same name
512+ // look if file already exists and ask if it should be overwritten
512513 const file = this . app . vault . getAbstractFileByPath ( filePath ) ;
513514 if ( file ) {
515+ const shouldOverwrite = await new Promise < boolean > ( resolve => {
516+ new ConfirmOverwriteModal ( this . app , fileName , resolve ) . open ( ) ;
517+ } ) ;
518+
519+ if ( ! shouldOverwrite ) {
520+ throw new Error ( 'MDB | file creation cancelled by user' ) ;
521+ }
522+
514523 await this . app . vault . delete ( file ) ;
515524 }
516525
517526 // create the file
518527 const targetFile = await this . app . vault . create ( filePath , fileContent ) ;
519528 console . debug ( `MDB | created new file at ${ filePath } ` ) ;
520529
521- // open newly crated file
530+ // open newly created file
522531 if ( options . openNote ) {
523532 const activeLeaf = this . app . workspace . getUnpinnedLeaf ( ) ;
524533 if ( ! activeLeaf ) {
0 commit comments