diff --git a/index.d.ts b/index.d.ts index 224171e..bc9931b 100644 --- a/index.d.ts +++ b/index.d.ts @@ -100,6 +100,15 @@ declare namespace electronDl { @default true */ readonly showBadge?: boolean; + + /** + Allow downloaded files to overwrite files with the same name in the directory they are saved to. + + The default behavior is to append a number to the filename. + + @default false + */ + readonly overwrite?: boolean; } } diff --git a/index.js b/index.js index f8d3b24..d7f3385 100644 --- a/index.js +++ b/index.js @@ -74,7 +74,12 @@ function registerListener(session, options, callback = () => {}) { } else { const filename = item.getFilename(); const name = path.extname(filename) ? filename : getFilenameFromMime(filename, item.getMimeType()); - filePath = unusedFilename.sync(path.join(directory, name)); + + if (options.overwrite) { + filePath = path.join(directory, name); + } else { + filePath = unusedFilename.sync(path.join(directory, name)); + } } const errorMessage = options.errorMessage || 'The download of {filename} was interrupted'; diff --git a/readme.md b/readme.md index 25c30b7..86f69ac 100644 --- a/readme.md +++ b/readme.md @@ -195,6 +195,15 @@ Default: `true` Shows the file count badge on macOS/Linux dock icons when download is in progress. +#### overwrite + +Type: `boolean`\ +Default: `false` + +Allow downloaded files to overwrite files with the same name in the directory they are saved to. + +The default behavior is to append a number to the filename. + ## Development After making changes, run the automated tests: