修复大小写bug
This commit is contained in:
@@ -49,15 +49,15 @@ class ProjectService {
|
||||
return `${prefix}${randomPart}`;
|
||||
}
|
||||
/**
|
||||
* [新增] 文件名/文件夹名净化:只允许中文、字母、数字、-、_
|
||||
* 文件名/文件夹名净化:保留大小写,允许中文、字母、数字、-、_、.
|
||||
*/
|
||||
sanitizeFileName(name) {
|
||||
// 允许中文、字母、数字、-、_
|
||||
let fileName = name.trim().toLowerCase();
|
||||
let fileName = name.trim(); // 移除 .toLowerCase() 以保留大小写
|
||||
// 1. 替换所有空格为下划线
|
||||
fileName = fileName.replace(/\s+/g, '_');
|
||||
// 2. 移除所有不被允许的特殊字符(只保留中文、字母、数字、-、_)
|
||||
fileName = fileName.replace(/[^\u4e00-\u9fa5a-z0-9_-]/g, '');
|
||||
// 2. 移除特殊字符
|
||||
// 在正则中增加了 A-Z 以及 \. (注意:\u4e00-\u9fa5 匹配中文)
|
||||
fileName = fileName.replace(/[^\u4e00-\u9fa5a-zA-Z0-9_\-\.]/g, '');
|
||||
// 3. 确保不为空
|
||||
if (fileName.length === 0) {
|
||||
return 'config_file';
|
||||
@@ -308,9 +308,10 @@ class ProjectService {
|
||||
getConfig(configId) {
|
||||
return this.configs.find(c => c.id === configId);
|
||||
}
|
||||
// src/panels/services/ProjectService.ts
|
||||
async createConfig(name, containerId) {
|
||||
const newId = this.generateUniqueId('cfg', this.configs);
|
||||
// 使用新增的 sanitizeFileName 方法来处理文件名
|
||||
// 使用净化后的文件名
|
||||
const newFileName = this.sanitizeFileName(name);
|
||||
const newConfig = {
|
||||
id: newId,
|
||||
@@ -319,7 +320,22 @@ class ProjectService {
|
||||
containerId: containerId
|
||||
};
|
||||
this.configs.push(newConfig);
|
||||
// 1. 首先确保父级容器目录存在
|
||||
await this.ensureContainerDirectoryExists(containerId);
|
||||
// 2. 获取文件的完整磁盘路径
|
||||
const filePath = this.getConfigFilePath(newId);
|
||||
if (filePath) {
|
||||
try {
|
||||
const fileUri = vscode.Uri.file(filePath);
|
||||
// 3. 真实创建文件:写入一个空的 Uint8Array 即可创建一个空文件
|
||||
// 如果你希望有默认内容,可以在这里自定义 TextEncoder().encode("...")
|
||||
await vscode.workspace.fs.writeFile(fileUri, new Uint8Array());
|
||||
console.log(`✅ 磁盘文件已真实创建: ${filePath}`);
|
||||
}
|
||||
catch (error) {
|
||||
console.error(`❌ 磁盘文件创建失败: ${error}`);
|
||||
}
|
||||
}
|
||||
return newId;
|
||||
}
|
||||
/**
|
||||
@@ -399,17 +415,6 @@ class ProjectService {
|
||||
this.moduleFolders = this.moduleFolders.filter(f => f.id !== folderId);
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* [删除] 此方法已被 ConfigPanel 中的 updateModuleFolder 替换,以支持同步磁盘操作。
|
||||
*/
|
||||
// renameModuleFolder(folderId: string, newName: string): boolean {
|
||||
// const folder = this.moduleFolders.find(f => f.id === folderId);
|
||||
// if (!folder) return false;
|
||||
//
|
||||
// const oldName = folder.localPath.split('/').pop() || '';
|
||||
// folder.localPath = folder.localPath.replace(/\/[^/]+$/, '/' + newName);
|
||||
// return true;
|
||||
// }
|
||||
// =============== 文件系统操作 (新增/修改) ===============
|
||||
/**
|
||||
* 获取项目目录重命名所需的旧路径和新路径(新增)
|
||||
|
||||
Reference in New Issue
Block a user