@@ -13,6 +13,7 @@ import { SteamAPI } from './api/apis/SteamAPI';
13
13
import { WikipediaAPI } from './api/apis/WikipediaAPI' ;
14
14
import { ComicVineAPI } from './api/apis/ComicVineAPI' ;
15
15
import { MediaDbFolderImportModal } from './modals/MediaDbFolderImportModal' ;
16
+ import { ConfirmOverwriteModal } from './modals/ConfirmOverwriteModal' ;
16
17
import type { MediaTypeModel } from './models/MediaTypeModel' ;
17
18
import { PropertyMapper } from './settings/PropertyMapper' ;
18
19
import { PropertyMapping , PropertyMappingModel } from './settings/PropertyMapping' ;
@@ -508,17 +509,25 @@ export default class MediaDbPlugin extends Plugin {
508
509
fileName = replaceIllegalFileNameCharactersInString ( fileName ) ;
509
510
const filePath = `${ folder . path } /${ fileName } .md` ;
510
511
511
- // find and delete file with the same name
512
+ // look if file already exists and ask if it should be overwritten
512
513
const file = this . app . vault . getAbstractFileByPath ( filePath ) ;
513
514
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
+
514
523
await this . app . vault . delete ( file ) ;
515
524
}
516
525
517
526
// create the file
518
527
const targetFile = await this . app . vault . create ( filePath , fileContent ) ;
519
528
console . debug ( `MDB | created new file at ${ filePath } ` ) ;
520
529
521
- // open newly crated file
530
+ // open newly created file
522
531
if ( options . openNote ) {
523
532
const activeLeaf = this . app . workspace . getUnpinnedLeaf ( ) ;
524
533
if ( ! activeLeaf ) {
0 commit comments