0
0

修复了拉取出现的bug,完善了改名功能

This commit is contained in:
xubing
2025-12-06 18:05:35 +08:00
parent 46c184b920
commit 11c405f79a
10 changed files with 650 additions and 98 deletions

View File

@@ -100,6 +100,9 @@ class ProjectService {
getAircraftsByProject(projectId) {
return this.aircrafts.filter(a => a.projectId === projectId);
}
getAircraft(aircraftId) {
return this.aircrafts.find(a => a.id === aircraftId);
}
async createAircraft(name, projectId) {
const newId = this.generateUniqueId('a', this.aircrafts);
const newAircraft = {
@@ -182,6 +185,9 @@ class ProjectService {
getContainersByAircraft(aircraftId) {
return this.containers.filter(c => c.aircraftId === aircraftId);
}
getContainer(containerId) {
return this.containers.find(c => c.id === containerId);
}
async createContainer(name, aircraftId) {
const newId = this.generateUniqueId('c', this.containers);
const newContainer = {
@@ -216,10 +222,10 @@ class ProjectService {
* 从已存在的磁盘目录导入容器
*
* ✅ 你的最新需求:
* - 不创建“默认两个配置”
* - 自动扫描容器目录下的『子文件夹』
* - 每个子文件夹创建一个 ModuleFoldertype: 'local'
* - 排除 `.git` 子文件夹
* - 不创建“默认两个配置”
* - 自动扫描容器目录下的『子文件夹』
* - 每个子文件夹创建一个 ModuleFoldertype: 'local'
* - 排除 `.git` 子文件夹
*/
async importContainerFromExistingFolder(aircraftId, containerName) {
if (containerName === '.git') {
@@ -348,7 +354,120 @@ class ProjectService {
folder.localPath = folder.localPath.replace(/\/[^/]+$/, '/' + newName);
return true;
}
// =============== 文件系统操作 ===============
// =============== 文件系统操作 (新增/修改) ===============
/**
* 获取项目目录重命名所需的旧路径和新路径(新增)
*/
getProjectOldAndNewPaths(projectId, newName) {
const project = this.projects.find(p => p.id === projectId);
const oldPath = this.projectPaths.get(projectId);
if (!project || !oldPath)
return null;
const parentDir = path.dirname(oldPath);
// 新路径使用新的项目名称作为文件夹名
const newPath = path.join(parentDir, newName);
return { oldPath, newPath };
}
/**
* 获取飞行器目录的完整路径
*/
getAircraftDirectoryPath(aircraftId) {
const aircraft = this.getAircraft(aircraftId);
if (!aircraft)
return null;
const projectPath = this.projectPaths.get(aircraft.projectId);
if (!projectPath)
return null;
return path.join(projectPath, aircraft.name);
}
/**
* 获取飞行器目录重命名所需的旧路径和新路径(新增)
* 注意oldPath使用内存中当前的名称newPath使用将要更新的新名称
*/
getAircraftOldAndNewPaths(aircraftId, newName) {
const aircraft = this.aircrafts.find(a => a.id === aircraftId);
if (!aircraft)
return null;
const projectPath = this.projectPaths.get(aircraft.projectId);
if (!projectPath)
return null;
const oldPath = path.join(projectPath, aircraft.name);
const newPath = path.join(projectPath, newName);
return { oldPath, newPath };
}
/**
* 获取容器目录的完整路径
*/
getContainerDirectoryPath(containerId) {
const container = this.getContainer(containerId);
if (!container)
return null;
const aircraft = this.getAircraft(container.aircraftId);
if (!aircraft)
return null;
const projectPath = this.projectPaths.get(aircraft.projectId);
if (!projectPath)
return null;
return path.join(projectPath, aircraft.name, container.name);
}
/**
* 获取容器目录重命名所需的旧路径和新路径(新增)
* 注意oldPath使用内存中当前的名称newPath使用将要更新的新名称
*/
getContainerOldAndNewPaths(containerId, newName) {
const container = this.containers.find(c => c.id === containerId);
if (!container)
return null;
const aircraft = this.aircrafts.find(a => a.id === container.aircraftId);
if (!aircraft)
return null;
const projectPath = this.projectPaths.get(aircraft.projectId);
if (!projectPath)
return null;
const aircraftDir = path.join(projectPath, aircraft.name);
const oldPath = path.join(aircraftDir, container.name);
const newPath = path.join(aircraftDir, newName);
return { oldPath, newPath };
}
/**
* 递归删除目录
*/
async deleteDirectoryFromDisk(directoryPath) {
if (!directoryPath)
return false;
try {
if (fs.existsSync(directoryPath)) {
await fs.promises.rm(directoryPath, { recursive: true, force: true });
console.log(`✅ 已删除目录: ${directoryPath}`);
return true;
}
return false;
}
catch (error) {
console.error(`删除目录失败: ${error}`);
throw error; // Re-throw to be handled by ConfigPanel
}
}
/**
* 重命名磁盘上的目录(新增)
*/
async renameDirectoryOnDisk(oldPath, newPath) {
if (!oldPath || !newPath)
return false;
try {
if (fs.existsSync(oldPath)) {
await fs.promises.rename(oldPath, newPath);
console.log(`✅ 已重命名目录: ${oldPath} -> ${newPath}`);
return true;
}
console.warn(`目录不存在,跳过重命名: ${oldPath}`);
return false;
}
catch (error) {
console.error(`重命名目录失败: ${error}`);
throw error; // Re-throw to be handled by ConfigPanel
}
}
async createAircraftDirectory(aircraft) {
try {
const projectPath = this.projectPaths.get(aircraft.projectId);