Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions src/commands/blog-export/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ export class DeleteCommandHandler extends TreeViewCommandHandler<DownloadedExpor

private confirm(
itemName: string,
hasLocalFile = true
hasLocalFile = true,
detail: string | undefined | null = '数据可能无法恢复, 请谨慎操作!'
): Thenable<null | { shouldDeleteLocal: boolean } | undefined> {
const options: (MessageItem & {
result: ReturnType<DeleteCommandHandler['confirm']> extends Thenable<infer R> ? R : never;
Expand All @@ -42,7 +43,7 @@ export class DeleteCommandHandler extends TreeViewCommandHandler<DownloadedExpor
return window
.showInformationMessage(
`确定要删除 ${itemName} 吗?`,
{ modal: true, detail: '数据可能无法恢复, 请谨慎操作!' },
{ modal: true, detail: detail ? detail : undefined },
...options
)
.then(
Expand All @@ -55,19 +56,15 @@ export class DeleteCommandHandler extends TreeViewCommandHandler<DownloadedExpor
item: DownloadedExportTreeItem,
{ hasConfirmed = false } = {}
): Promise<void> {
const parent = item.parent;
const isChildOfRecord = parent instanceof BlogExportRecordTreeItem;
const result = hasConfirmed
? { shouldDeleteLocal: true }
: await this.confirm(`博客备份-${path.basename(item.downloadedExport.filePath)}`, !isChildOfRecord);
: await this.confirm(`博客备份-${path.basename(item.downloadedExport.filePath)}`, false, null);
if (result == null) return;

let { shouldDeleteLocal } = result;
shouldDeleteLocal = shouldDeleteLocal || isChildOfRecord;
await this.removeDownloadedBlogExport(item.downloadedExport, { shouldDeleteLocal });
await this.removeDownloadedBlogExport(item.downloadedExport, { shouldDeleteLocal: true });

if (shouldDeleteLocal) await BlogExportProvider.optionalInstance?.refreshRecords({ force: false });
else await BlogExportProvider.optionalInstance?.refreshDownloadedExports();
await BlogExportProvider.optionalInstance?.refreshRecords({ force: false });
await BlogExportProvider.optionalInstance?.refreshDownloadedExports();
}

private async deleteExportRecordItem(item: BlogExportRecordTreeItem) {
Expand Down