refactor: directly use getProjectPathById from projectsDb

This commit is contained in:
Haileyesus
2026-04-29 18:40:21 +03:00
parent 5352582fe5
commit c7d4fa915e
5 changed files with 17 additions and 51 deletions

View File

@@ -18,9 +18,6 @@ import { createWebSocketServer } from '@/modules/websocket/index.js';
import { getConnectableHost } from '../shared/networkHosts.js'; import { getConnectableHost } from '../shared/networkHosts.js';
import { findAppRoot, getModuleDir } from './utils/runtime-paths.js'; import { findAppRoot, getModuleDir } from './utils/runtime-paths.js';
import {
getProjectPathById,
} from './projects.js';
import { import {
queryClaudeSDK, queryClaudeSDK,
abortClaudeSDKSession, abortClaudeSDKSession,
@@ -69,7 +66,7 @@ import geminiRoutes from './routes/gemini.js';
import pluginsRoutes from './routes/plugins.js'; import pluginsRoutes from './routes/plugins.js';
import providerRoutes from './modules/providers/provider.routes.js'; import providerRoutes from './modules/providers/provider.routes.js';
import { startEnabledPluginServers, stopAllPlugins, getPluginPort } from './utils/plugin-process-manager.js'; import { startEnabledPluginServers, stopAllPlugins, getPluginPort } from './utils/plugin-process-manager.js';
import { initializeDatabase } from './modules/database/index.js'; import { initializeDatabase, projectsDb } from './modules/database/index.js';
import { configureWebPush } from './services/vapid-keys.js'; import { configureWebPush } from './services/vapid-keys.js';
import { validateApiKey, authenticateToken, authenticateWebSocket } from './middleware/auth.js'; import { validateApiKey, authenticateToken, authenticateWebSocket } from './middleware/auth.js';
import { IS_PLATFORM } from './constants/config.js'; import { IS_PLATFORM } from './constants/config.js';
@@ -434,7 +431,7 @@ app.get('/api/projects/:projectId/file', authenticateToken, async (req, res) =>
// Resolve the absolute project root via the DB-backed helper; the // Resolve the absolute project root via the DB-backed helper; the
// caller passes the DB-assigned `projectId`, not a folder name. // caller passes the DB-assigned `projectId`, not a folder name.
const projectRoot = await getProjectPathById(projectId); const projectRoot = await projectsDb.getProjectPathById(projectId);
if (!projectRoot) { if (!projectRoot) {
return res.status(404).json({ error: 'Project not found' }); return res.status(404).json({ error: 'Project not found' });
} }
@@ -475,7 +472,7 @@ app.get('/api/projects/:projectId/files/content', authenticateToken, async (req,
} }
// Projects are now addressed by DB `projectId`, resolved to their path here. // Projects are now addressed by DB `projectId`, resolved to their path here.
const projectRoot = await getProjectPathById(projectId); const projectRoot = await projectsDb.getProjectPathById(projectId);
if (!projectRoot) { if (!projectRoot) {
return res.status(404).json({ error: 'Project not found' }); return res.status(404).json({ error: 'Project not found' });
} }
@@ -537,7 +534,7 @@ app.put('/api/projects/:projectId/file', authenticateToken, async (req, res) =>
} }
// Projects are now addressed by DB `projectId`, resolved to their path here. // Projects are now addressed by DB `projectId`, resolved to their path here.
const projectRoot = await getProjectPathById(projectId); const projectRoot = await projectsDb.getProjectPathById(projectId);
if (!projectRoot) { if (!projectRoot) {
return res.status(404).json({ error: 'Project not found' }); return res.status(404).json({ error: 'Project not found' });
} }
@@ -578,7 +575,7 @@ app.get('/api/projects/:projectId/files', authenticateToken, async (req, res) =>
// Resolve the project's absolute path through the DB (projectId is the // Resolve the project's absolute path through the DB (projectId is the
// primary key of the `projects` table after the identifier migration). // primary key of the `projects` table after the identifier migration).
const actualPath = await getProjectPathById(req.params.projectId); const actualPath = await projectsDb.getProjectPathById(req.params.projectId);
if (!actualPath) { if (!actualPath) {
return res.status(404).json({ error: 'Project not found' }); return res.status(404).json({ error: 'Project not found' });
} }
@@ -666,7 +663,7 @@ app.post('/api/projects/:projectId/files/create', authenticateToken, async (req,
} }
// Resolve the project directory through the DB using the new projectId. // Resolve the project directory through the DB using the new projectId.
const projectRoot = await getProjectPathById(projectId); const projectRoot = await projectsDb.getProjectPathById(projectId);
if (!projectRoot) { if (!projectRoot) {
return res.status(404).json({ error: 'Project not found' }); return res.status(404).json({ error: 'Project not found' });
} }
@@ -739,7 +736,7 @@ app.put('/api/projects/:projectId/files/rename', authenticateToken, async (req,
} }
// Resolve the project directory through the DB using the new projectId. // Resolve the project directory through the DB using the new projectId.
const projectRoot = await getProjectPathById(projectId); const projectRoot = await projectsDb.getProjectPathById(projectId);
if (!projectRoot) { if (!projectRoot) {
return res.status(404).json({ error: 'Project not found' }); return res.status(404).json({ error: 'Project not found' });
} }
@@ -811,7 +808,7 @@ app.delete('/api/projects/:projectId/files', authenticateToken, async (req, res)
} }
// Resolve the project directory through the DB using the new projectId. // Resolve the project directory through the DB using the new projectId.
const projectRoot = await getProjectPathById(projectId); const projectRoot = await projectsDb.getProjectPathById(projectId);
if (!projectRoot) { if (!projectRoot) {
return res.status(404).json({ error: 'Project not found' }); return res.status(404).json({ error: 'Project not found' });
} }
@@ -929,7 +926,7 @@ const uploadFilesHandler = async (req, res) => {
} }
// Resolve the project directory through the DB using the new projectId. // Resolve the project directory through the DB using the new projectId.
const projectRoot = await getProjectPathById(projectId); const projectRoot = await projectsDb.getProjectPathById(projectId);
if (!projectRoot) { if (!projectRoot) {
return res.status(404).json({ error: 'Project not found' }); return res.status(404).json({ error: 'Project not found' });
} }
@@ -1227,7 +1224,7 @@ app.get('/api/projects/:projectId/sessions/:sessionId/token-usage', authenticate
// `projectId`. Legacy code here called extractProjectDirectory with a // `projectId`. Legacy code here called extractProjectDirectory with a
// folder-encoded project name; the migration centralizes that lookup // folder-encoded project name; the migration centralizes that lookup
// in the projects table. // in the projects table.
const projectPath = await getProjectPathById(projectId); const projectPath = await projectsDb.getProjectPathById(projectId);
if (!projectPath) { if (!projectPath) {
return res.status(404).json({ error: 'Project not found' }); return res.status(404).json({ error: 'Project not found' });
} }

View File

@@ -194,10 +194,6 @@ async function onUpdate(
return; return;
} }
console.log(`Session synchronization triggered by ${eventType} event for provider "${provider}"`, {
filePath,
sessionId: result.sessionId,
});
queuePendingWatcherUpdate(eventType, provider, result.sessionId); queuePendingWatcherUpdate(eventType, provider, result.sessionId);
} catch (error) { } catch (error) {
const message = error instanceof Error ? error.message : String(error); const message = error instanceof Error ? error.message : String(error);

View File

@@ -1,27 +0,0 @@
/**
* PROJECT PATH RESOLUTION
* =======================
*
* Routes address projects by DB `projectId` and resolve their absolute
* workspace path through this module.
*/
import { projectsDb } from './modules/database/index.js';
/**
* Resolve the absolute project path for a database `projectId`.
*
* Returns `null` when the id doesn't match any row so callers can respond
* with a 404.
*/
async function getProjectPathById(projectId) {
if (!projectId) {
return null;
}
return projectsDb.getProjectPathById(projectId);
}
export {
getProjectPathById
};

View File

@@ -2,7 +2,7 @@ import express from 'express';
import { spawn } from 'child_process'; import { spawn } from 'child_process';
import path from 'path'; import path from 'path';
import { promises as fs } from 'fs'; import { promises as fs } from 'fs';
import { getProjectPathById } from '../projects.js'; import { projectsDb } from '../modules/database/index.js';
import { queryClaudeSDK } from '../claude-sdk.js'; import { queryClaudeSDK } from '../claude-sdk.js';
import { spawnCursor } from '../cursor-cli.js'; import { spawnCursor } from '../cursor-cli.js';
@@ -111,7 +111,7 @@ function validateProjectPath(projectPath) {
* by `validateProjectPath` before any `git` command runs against it. * by `validateProjectPath` before any `git` command runs against it.
*/ */
async function getActualProjectPath(projectId) { async function getActualProjectPath(projectId) {
const projectPath = await getProjectPathById(projectId); const projectPath = await projectsDb.getProjectPathById(projectId);
if (!projectPath) { if (!projectPath) {
throw new Error(`Unable to resolve project path for "${projectId}"`); throw new Error(`Unable to resolve project path for "${projectId}"`);
} }

View File

@@ -13,7 +13,7 @@ import fs from 'fs';
import path from 'path'; import path from 'path';
import { promises as fsPromises } from 'fs'; import { promises as fsPromises } from 'fs';
import { spawn } from 'child_process'; import { spawn } from 'child_process';
import { getProjectPathById } from '../projects.js'; import { projectsDb } from '../modules/database/index.js';
import { detectTaskMasterMCPServer } from '../utils/mcp-detector.js'; import { detectTaskMasterMCPServer } from '../utils/mcp-detector.js';
import { broadcastTaskMasterProjectUpdate, broadcastTaskMasterTasksUpdate } from '../utils/taskmaster-websocket.js'; import { broadcastTaskMasterProjectUpdate, broadcastTaskMasterTasksUpdate } from '../utils/taskmaster-websocket.js';
@@ -26,10 +26,10 @@ import { broadcastTaskMasterProjectUpdate, broadcastTaskMasterTasksUpdate } from
* every handler calls this helper and 404s when the id is unknown. * every handler calls this helper and 404s when the id is unknown.
*/ */
async function resolveProjectPathFromId(projectId) { async function resolveProjectPathFromId(projectId) {
if (!projectId) { if (!projectId) {
return null; return null;
} }
return getProjectPathById(projectId); return projectsDb.getProjectPathById(projectId);
} }
const router = express.Router(); const router = express.Router();