mirror of
https://github.com/siteboon/claudecodeui.git
synced 2025-12-09 10:59:47 +00:00
Enhance project directory handling by integrating extractProjectDirectory and clearProjectDirectoryCache functions. Adjust git route handlers to utilize the new directory extraction logic for improved project path resolution.
This commit is contained in:
@@ -30,7 +30,7 @@ const os = require('os');
|
||||
const pty = require('node-pty');
|
||||
const fetch = require('node-fetch');
|
||||
|
||||
const { getProjects, getSessions, getSessionMessages, renameProject, deleteSession, deleteProject, addProjectManually } = require('./projects');
|
||||
const { getProjects, getSessions, getSessionMessages, renameProject, deleteSession, deleteProject, addProjectManually, extractProjectDirectory, clearProjectDirectoryCache } = require('./projects');
|
||||
const { spawnClaude, abortClaudeSession } = require('./claude-cli');
|
||||
const gitRoutes = require('./routes/git');
|
||||
|
||||
@@ -76,6 +76,9 @@ function setupProjectsWatcher() {
|
||||
debounceTimer = setTimeout(async () => {
|
||||
try {
|
||||
|
||||
// Clear project directory cache when files change
|
||||
clearProjectDirectoryCache();
|
||||
|
||||
// Get updated projects list
|
||||
const updatedProjects = await getProjects();
|
||||
|
||||
@@ -372,47 +375,15 @@ app.get('/api/projects/:projectName/files', async (req, res) => {
|
||||
try {
|
||||
|
||||
const fs = require('fs').promises;
|
||||
const projectPath = path.join(process.env.HOME, '.claude', 'projects', req.params.projectName);
|
||||
|
||||
// Try different methods to get the actual project path
|
||||
let actualPath = projectPath;
|
||||
|
||||
// Use extractProjectDirectory to get the actual project path
|
||||
let actualPath;
|
||||
try {
|
||||
// First try to read metadata.json
|
||||
const metadataPath = path.join(projectPath, 'metadata.json');
|
||||
const metadata = JSON.parse(await fs.readFile(metadataPath, 'utf8'));
|
||||
actualPath = metadata.path || metadata.cwd;
|
||||
} catch (e) {
|
||||
// Fallback: try to find the actual path by testing different dash interpretations
|
||||
let testPath = req.params.projectName;
|
||||
if (testPath.startsWith('-')) {
|
||||
testPath = testPath.substring(1);
|
||||
}
|
||||
|
||||
// Try to intelligently decode the path by testing which directories exist
|
||||
const pathParts = testPath.split('-');
|
||||
actualPath = '/' + pathParts.join('/');
|
||||
|
||||
// If the simple replacement doesn't work, try to find the correct path
|
||||
// by testing combinations where some dashes might be part of directory names
|
||||
if (!require('fs').existsSync(actualPath)) {
|
||||
// Try different combinations of dash vs slash
|
||||
for (let i = pathParts.length - 1; i >= 0; i--) {
|
||||
let testParts = [...pathParts];
|
||||
// Try joining some parts with dashes instead of slashes
|
||||
for (let j = i; j < testParts.length - 1; j++) {
|
||||
testParts[j] = testParts[j] + '-' + testParts[j + 1];
|
||||
testParts.splice(j + 1, 1);
|
||||
let testActualPath = '/' + testParts.join('/');
|
||||
if (require('fs').existsSync(testActualPath)) {
|
||||
actualPath = testActualPath;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (require('fs').existsSync(actualPath)) break;
|
||||
}
|
||||
}
|
||||
|
||||
actualPath = await extractProjectDirectory(req.params.projectName);
|
||||
} catch (error) {
|
||||
console.error('Error extracting project directory:', error);
|
||||
// Fallback to simple dash replacement
|
||||
actualPath = req.params.projectName.replace(/-/g, '/');
|
||||
}
|
||||
|
||||
// Check if path exists
|
||||
|
||||
Reference in New Issue
Block a user