diff --git a/src/common/util.ts b/src/common/util.ts index 7b7bf76..f69fd0b 100644 --- a/src/common/util.ts +++ b/src/common/util.ts @@ -93,6 +93,7 @@ export function restoreFileName(name: string) { // 移除文件名的非法字符 export function fixFileName(name: string) { + if (!name) return name return name.replace(/[\\/:*?"<>|]/g, '_') } diff --git a/src/renderer/store/task/DownloadTask.ts b/src/renderer/store/task/DownloadTask.ts index 301cee7..ff83304 100644 --- a/src/renderer/store/task/DownloadTask.ts +++ b/src/renderer/store/task/DownloadTask.ts @@ -65,6 +65,9 @@ export class DownloadTask implements BaseTask { }) // Object.assign(this, {uid: `${Date.now()}`}, props) Object.assign(this, props) + if (props.name) { + this.name = fixFileName(props.name) + } } get total() { @@ -110,7 +113,6 @@ export class DownloadTask implements BaseTask { if (!this.name) { this.name = name } - this.name = fixFileName(this.name) if (this.urlType === URLType.file && isSpecificFile(name)) { this.name = restoreFileName(this.name) }