MCPcopy Index your code
hub / github.com/TechJeeper/Printventory / getDatabasePath

Function getDatabasePath

main.js:6784–6826  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

6782
6783// Update the database path handling
6784function getDatabasePath() {
6785 try {
6786 const envDb = process.env.PRINTVENTORY_DB_PATH?.trim();
6787 if (envDb) {
6788 const resolved = path.isAbsolute(envDb) ? envDb : path.resolve(process.cwd(), envDb);
6789 const dir = path.dirname(resolved);
6790 if (!fs.existsSync(dir)) {
6791 fs.mkdirSync(dir, { recursive: true });
6792 }
6793 debugLog('Using database path from PRINTVENTORY_DB_PATH:', resolved);
6794 return resolved;
6795 }
6796
6797 // Local dev (Electron .npm start): keep a single DB in the repo. Server/Docker/docker-entrypoint
6798 // runs unpackaged Electron which sets isDev, but we must still use userData so compose volumes work.
6799 if (isDev && !isServerMode) {
6800 return path.join(__dirname, 'printventory.db');
6801 }
6802
6803 // Handle different OS paths
6804 let userDataPath;
6805 if (process.platform === 'darwin') { // macOS
6806 userDataPath = path.join(app.getPath('userData'), 'data');
6807 } else if (process.platform === 'win32') { // Windows
6808 userDataPath = path.join(process.env.LOCALAPPDATA, 'Printventory', 'data');
6809 } else { // Linux and other Unix-like systems
6810 userDataPath = path.join(app.getPath('userData'), 'data');
6811 }
6812
6813 // Ensure the directory exists
6814 if (!fs.existsSync(userDataPath)) {
6815 fs.mkdirSync(userDataPath, { recursive: true });
6816 }
6817
6818 const dbPath = path.join(userDataPath, 'printventory.db');
6819 migrateLegacyServerDbIfNeeded(dbPath);
6820 debugLog('Using database path:', dbPath);
6821 return dbPath;
6822 } catch (error) {
6823 console.error('Error setting up database path:', error);
6824 throw error;
6825 }
6826}
6827
6828// Add these IPC handlers
6829// Helper: URL-only models (added by Chrome extension) have filePath "url::https://..."

Callers 4

startHttpServerFunction · 0.85
main.jsFile · 0.85
initializeDatabaseFunction · 0.85
purgeModelsHandlerFunction · 0.85

Calls 2

debugLogFunction · 0.70

Tested by

no test coverage detected