Problem
30+ files across server/ and collector/ use the pattern:
process.env.STORAGE_DIR
? path.resolve(process.env.STORAGE_DIR, `some/subdir`)
: path.resolve(__dirname, `../../storage/some/subdir`)
The fallback logic is inconsistent — some files crash if STORAGE_DIR is undefined, others fall back to different default paths. This is a code smell and a deployment risk.
Scope
Files to migrate (server side)
server/endpoints/api/document/index.js (line 21)
server/endpoints/api/reports/index.js (line 32)
server/endpoints/utils.js (lines 148-149, 173)
server/utils/EmbeddingEngines/native/index.js (lines 38-39, 118-119)
server/utils/DocumentManager/index.js (line 6)
server/utils/agents/aibitat/plugins/create-files/lib.js (line 22)
server/utils/agents/aibitat/plugins/filesystem/lib.js (line 55)
server/utils/agents/imported.js (line 8)
server/utils/MCP/hypervisor/index.js (line 76)
server/utils/agentFlows/index.js (lines 19-20)
server/utils/vectorDbProviders/lance/index.js (lines 24-25)
server/utils/comKey/index.js (line 9)
server/utils/AiProviders/{fireworksAi,togetherAi,gemini,openRouter,dockerModelRunner,novita,apipie,modelMap,ppio,giteeai,cometapi}/index.js
server/utils/files/{index,pfp,logo,multer}.js
server/utils/PushNotifications/index.js (line 77)
server/utils/reports/index.js (line 17)
server/utils/EmbeddingRerankers/native/index.js (lines 21-22)
server/jobs/helpers/index.js (line 13)
Files to migrate (collector side)
collector/utils/OCRLoader/index.js (lines 27-28)
collector/utils/extensions/RepoLoader/{GithubRepo,GitlabRepo}/index.js (line 50)
collector/utils/extensions/Confluence/index.js (line 92)
collector/utils/comKey/index.js (line 9)
collector/utils/WhisperProviders/localWhisper.js (lines 16-17)
collector/utils/files/index.js (lines 13, 23)
Test files — DO NOT MIGRATE
collector/__tests__/utils/url/index.test.js
collector/__tests__/utils/extensions/Confluence/ConfluenceLoader.test.js
collector/__tests__/utils/WhisperProviders/ffmpeg/index.test.js
server/__tests__/endpoints/api/reports.test.js
server/__tests__/utils/agents/defaults.test.js
server/__tests__/utils/files/isWithin.test.js
server/__tests__/utils/reports/index.test.js
Proposed Solution
- Create
server/utils/paths.js:
const path = require("path");
function getStoragePath(...subdirs) {
const base = process.env.STORAGE_DIR || path.resolve(__dirname, "../../storage");
return subdirs.length > 0 ? path.resolve(base, ...subdirs) : base;
}
module.exports = { getStoragePath };
-
Create collector/utils/paths.js (same logic, different relative path)
-
Migrate all 30+ files to use getStoragePath(...subdirs)
-
Bug 1 fix: collector/utils/comKey/index.js:29 — replace hardcoded /app/server/ path with STORAGE_DIR reference
-
Bug 3 fix: docker/docker-entrypoint.sh:28 — add comment about Bash 4.3+ requirement for wait -n
Migration Pattern
BEFORE:
const storageDir = process.env.STORAGE_DIR || path.resolve(__dirname, "../../storage");
const modelPath = storageDir ? path.resolve(storageDir, "models", "gemini") : path.resolve(__dirname, "../../storage/models/gemini");
AFTER:
const { getStoragePath } = require("../paths");
const modelPath = getStoragePath("models", "gemini");
Acceptance Criteria
Aufwand
~1-2h (mechanical refactor)
Related
Status
No work done yet. Waiting on #87 to be fixed first (Docker build broken).
Problem
30+ files across
server/andcollector/use the pattern:The fallback logic is inconsistent — some files crash if
STORAGE_DIRis undefined, others fall back to different default paths. This is a code smell and a deployment risk.Scope
Files to migrate (server side)
server/endpoints/api/document/index.js(line 21)server/endpoints/api/reports/index.js(line 32)server/endpoints/utils.js(lines 148-149, 173)server/utils/EmbeddingEngines/native/index.js(lines 38-39, 118-119)server/utils/DocumentManager/index.js(line 6)server/utils/agents/aibitat/plugins/create-files/lib.js(line 22)server/utils/agents/aibitat/plugins/filesystem/lib.js(line 55)server/utils/agents/imported.js(line 8)server/utils/MCP/hypervisor/index.js(line 76)server/utils/agentFlows/index.js(lines 19-20)server/utils/vectorDbProviders/lance/index.js(lines 24-25)server/utils/comKey/index.js(line 9)server/utils/AiProviders/{fireworksAi,togetherAi,gemini,openRouter,dockerModelRunner,novita,apipie,modelMap,ppio,giteeai,cometapi}/index.jsserver/utils/files/{index,pfp,logo,multer}.jsserver/utils/PushNotifications/index.js(line 77)server/utils/reports/index.js(line 17)server/utils/EmbeddingRerankers/native/index.js(lines 21-22)server/jobs/helpers/index.js(line 13)Files to migrate (collector side)
collector/utils/OCRLoader/index.js(lines 27-28)collector/utils/extensions/RepoLoader/{GithubRepo,GitlabRepo}/index.js(line 50)collector/utils/extensions/Confluence/index.js(line 92)collector/utils/comKey/index.js(line 9)collector/utils/WhisperProviders/localWhisper.js(lines 16-17)collector/utils/files/index.js(lines 13, 23)Test files — DO NOT MIGRATE
collector/__tests__/utils/url/index.test.jscollector/__tests__/utils/extensions/Confluence/ConfluenceLoader.test.jscollector/__tests__/utils/WhisperProviders/ffmpeg/index.test.jsserver/__tests__/endpoints/api/reports.test.jsserver/__tests__/utils/agents/defaults.test.jsserver/__tests__/utils/files/isWithin.test.jsserver/__tests__/utils/reports/index.test.jsProposed Solution
server/utils/paths.js:Create
collector/utils/paths.js(same logic, different relative path)Migrate all 30+ files to use
getStoragePath(...subdirs)Bug 1 fix:
collector/utils/comKey/index.js:29— replace hardcoded/app/server/path withSTORAGE_DIRreferenceBug 3 fix:
docker/docker-entrypoint.sh:28— add comment about Bash 4.3+ requirement forwait -nMigration Pattern
BEFORE:
AFTER:
Acceptance Criteria
server/utils/paths.jsandcollector/utils/paths.jsexist withgetStoragePath()helpergrep -rn 'process\.env\.STORAGE_DIR' server/ collector/ --include="*.js" | grep -v __tests__ | grep -v paths.js→ 0 resultscd server && npx jest --ci --passWithNoTestscd frontend && npx vitest runcollector/utils/comKey/index.js:29comment fixed (no hardcoded/app/server/)docker/docker-entrypoint.sh:28has Bash 4.3+ commentAufwand
~1-2h (mechanical refactor)
Related
Status
No work done yet. Waiting on #87 to be fixed first (Docker build broken).