mirror of
https://github.com/R0m1k3/CollectFlow.git
synced 2026-10-13 18:27:40 +02:00
fix: resolve EACCES permission issue and hydration error #418
This commit is contained in:
1 parent
0026e3134d
commit
4f4a0dbd62
4 files changed
+45
-13
No files matched your search
@@ -4,7 +4,8 @@ import { Pool } from "pg";
|
||||
import fs from "fs/promises";
|
||||
import path from "path";
|
||||
|
||||
const CONFIG_FILE = path.join(process.cwd(), ".db-config.json");
|
||||
const DATA_DIR = path.join(process.cwd(), "data");
|
||||
const CONFIG_FILE = path.join(DATA_DIR, ".db-config.json");
|
||||
|
||||
export interface DbConfig {
|
||||
url: string;
|
||||
@@ -22,9 +23,10 @@ export async function testDatabaseConnection(url: string) {
|
||||
await client.query("SELECT 1");
|
||||
client.release();
|
||||
return { success: true };
|
||||
} catch (error: any) {
|
||||
console.error("Database connection test failed:", error.message);
|
||||
return { success: false, error: error.message };
|
||||
} catch (error: unknown) {
|
||||
const errorMessage = error instanceof Error ? error.message : String(error);
|
||||
console.error("Database connection test failed:", errorMessage);
|
||||
return { success: false, error: errorMessage };
|
||||
} finally {
|
||||
await pool.end();
|
||||
}
|
||||
@@ -33,12 +35,17 @@ export async function testDatabaseConnection(url: string) {
|
||||
export async function saveDatabaseSettings(url: string) {
|
||||
try {
|
||||
const config: DbConfig = { url };
|
||||
|
||||
// S'assurer que le dossier data existe
|
||||
await fs.mkdir(DATA_DIR, { recursive: true });
|
||||
|
||||
await fs.writeFile(CONFIG_FILE, JSON.stringify(config, null, 2));
|
||||
console.log("Database configuration saved to:", CONFIG_FILE);
|
||||
return { success: true };
|
||||
} catch (error: any) {
|
||||
console.error("Failed to save database configuration:", error.message);
|
||||
return { success: false, error: error.message };
|
||||
} catch (error: unknown) {
|
||||
const errorMessage = error instanceof Error ? error.message : String(error);
|
||||
console.error("Failed to save database configuration:", errorMessage);
|
||||
return { success: false, error: errorMessage };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user