|
1 |
| -import { MessageOptions, ProgressLocation, window } from 'vscode'; |
| 1 | +import fs from 'fs'; |
| 2 | +import { MessageOptions, ProgressLocation, window, Uri, workspace } from 'vscode'; |
2 | 3 | import { PostCategory } from '../../models/post-category';
|
3 | 4 | import { postCategoryService } from '../../services/post-category.service';
|
4 | 5 | import { extensionViews } from '../../tree-view-providers/tree-view-registration';
|
5 | 6 | import { inputPostCategory } from './input-post-category';
|
6 | 7 | import { refreshPostCategoriesList } from './refresh-post-categories-list';
|
| 8 | +import { Settings } from '../../services/settings.service'; |
7 | 9 |
|
8 | 10 | export const updatePostCategory = async (category?: PostCategory) => {
|
9 | 11 | if (!category) {
|
@@ -32,9 +34,19 @@ export const updatePostCategory = async (category?: PostCategory) => {
|
32 | 34 | try {
|
33 | 35 | await postCategoryService.updateCategory(updateDto);
|
34 | 36 | refreshPostCategoriesList();
|
| 37 | + // 如果选择了createLocalPostFileWithCategory模式且本地有该目录,则重命名该目录 |
| 38 | + const workspaceUri = Settings.workspaceUri; |
| 39 | + const createLocalPostFileWithCategory = Settings.createLocalPostFileWithCategory; |
| 40 | + const uri = Uri.joinPath(workspaceUri, category.title).fsPath; |
| 41 | + const isFileExist = fs.existsSync(uri); |
| 42 | + if (createLocalPostFileWithCategory && isFileExist) { |
| 43 | + const oldUri = Uri.joinPath(workspaceUri, category.title); |
| 44 | + const newUri = Uri.joinPath(workspaceUri, addDto.title); |
| 45 | + await workspace.fs.rename(oldUri, newUri); |
| 46 | + } |
35 | 47 | } catch (err) {
|
36 | 48 | void window.showErrorMessage('更新博文分类失败', {
|
37 |
| - detail: `服务器反回了错误, ${err instanceof Error ? err.message : JSON.stringify(err)}`, |
| 49 | + detail: `服务器返回了错误, ${err instanceof Error ? err.message : JSON.stringify(err)}`, |
38 | 50 | modal: true,
|
39 | 51 | } as MessageOptions);
|
40 | 52 | } finally {
|
|
0 commit comments