@@ -137,7 +137,7 @@ ipcMain.handle('send-http-request', async (_event, opts: {
137137ipcMain . handle ( 'test-db-connection' , async ( _event , url : string ) => {
138138 if ( url . startsWith ( 'mysql://' ) ) {
139139 try {
140- const conn = await mysql . createConnection ( url )
140+ const conn = await mysql . createConnection ( { uri : url , connectTimeout : 10000 } )
141141 await conn . ping ( )
142142 await conn . end ( )
143143 return { success : true }
@@ -146,7 +146,7 @@ ipcMain.handle('test-db-connection', async (_event, url: string) => {
146146 }
147147 } else if ( url . startsWith ( 'postgres://' ) || url . startsWith ( 'postgresql://' ) ) {
148148 try {
149- const client = new pg . Client ( { connectionString : url , ssl : { rejectUnauthorized : false } } )
149+ const client = new pg . Client ( { connectionString : url , connectionTimeoutMillis : 10000 , ssl : { rejectUnauthorized : false } } )
150150 await client . connect ( )
151151 await client . end ( )
152152 return { success : true }
@@ -173,7 +173,7 @@ ipcMain.handle('create-remote-tables', async (_event, url: string) => {
173173
174174 if ( url . startsWith ( 'mysql://' ) ) {
175175 try {
176- const conn = await mysql . createConnection ( { uri : url , multipleStatements : true } )
176+ const conn = await mysql . createConnection ( { uri : url , multipleStatements : true , connectTimeout : 10000 } )
177177 for ( const s of statements ) await conn . execute ( s )
178178 // Run migrations (ignoring errors if columns exist but ADD COLUMN IF NOT EXISTS isn't supported)
179179 for ( const m of migrations ) {
@@ -188,7 +188,7 @@ ipcMain.handle('create-remote-tables', async (_event, url: string) => {
188188 }
189189 } else if ( url . startsWith ( 'postgres://' ) || url . startsWith ( 'postgresql://' ) ) {
190190 try {
191- const client = new pg . Client ( { connectionString : url , ssl : { rejectUnauthorized : false } } )
191+ const client = new pg . Client ( { connectionString : url , connectionTimeoutMillis : 10000 , ssl : { rejectUnauthorized : false } } )
192192 await client . connect ( )
193193 for ( const s of statements ) await client . query ( s )
194194 // Run migrations
@@ -209,7 +209,7 @@ ipcMain.handle('create-remote-tables', async (_event, url: string) => {
209209ipcMain . handle ( 'create-rbac-user' , async ( _event , url : string , user : { id : string , email : string , token : string , allowedFolders : string [ ] , projectId : string , role : string } ) => {
210210 if ( url . startsWith ( 'mysql://' ) ) {
211211 try {
212- const conn = await mysql . createConnection ( url )
212+ const conn = await mysql . createConnection ( { uri : url , connectTimeout : 10000 } )
213213 await conn . execute (
214214 'INSERT INTO rbac_users (id, email, token, allowed_folders, project_id, role) VALUES (?, ?, ?, ?, ?, ?)' ,
215215 [ user . id , user . email , user . token , JSON . stringify ( user . allowedFolders ) , user . projectId , user . role ]
@@ -221,7 +221,7 @@ ipcMain.handle('create-rbac-user', async (_event, url: string, user: { id: strin
221221 }
222222 } else if ( url . startsWith ( 'postgres://' ) || url . startsWith ( 'postgresql://' ) ) {
223223 try {
224- const client = new pg . Client ( { connectionString : url , ssl : { rejectUnauthorized : false } } )
224+ const client = new pg . Client ( { connectionString : url , connectionTimeoutMillis : 10000 , ssl : { rejectUnauthorized : false } } )
225225 await client . connect ( )
226226 await client . query (
227227 'INSERT INTO rbac_users (id, email, token, allowed_folders, project_id, role) VALUES ($1, $2, $3, $4, $5, $6)' ,
@@ -239,7 +239,7 @@ ipcMain.handle('create-rbac-user', async (_event, url: string, user: { id: strin
239239ipcMain . handle ( 'get-rbac-users' , async ( _event , url : string , projectId : string ) => {
240240 if ( url . startsWith ( 'mysql://' ) ) {
241241 try {
242- const conn = await mysql . createConnection ( url )
242+ const conn = await mysql . createConnection ( { uri : url , connectTimeout : 10000 } )
243243 const [ rows ] : any = await conn . execute ( 'SELECT * FROM rbac_users WHERE project_id = ?' , [ projectId ] )
244244 await conn . end ( )
245245 return { success : true , users : rows }
@@ -248,7 +248,7 @@ ipcMain.handle('get-rbac-users', async (_event, url: string, projectId: string)
248248 }
249249 } else if ( url . startsWith ( 'postgres://' ) || url . startsWith ( 'postgresql://' ) ) {
250250 try {
251- const client = new pg . Client ( { connectionString : url , ssl : { rejectUnauthorized : false } } )
251+ const client = new pg . Client ( { connectionString : url , connectionTimeoutMillis : 10000 , ssl : { rejectUnauthorized : false } } )
252252 await client . connect ( )
253253 const res = await client . query ( 'SELECT * FROM rbac_users WHERE project_id = $1' , [ projectId ] )
254254 await client . end ( )
@@ -263,7 +263,7 @@ ipcMain.handle('get-rbac-users', async (_event, url: string, projectId: string)
263263ipcMain . handle ( 'update-rbac-user' , async ( _event , url : string , user : { id : string , email : string , allowedFolders : any , role : string } ) => {
264264 if ( url . startsWith ( 'mysql://' ) ) {
265265 try {
266- const conn = await mysql . createConnection ( url )
266+ const conn = await mysql . createConnection ( { uri : url , connectTimeout : 10000 } )
267267 await conn . execute (
268268 'UPDATE rbac_users SET email = ?, allowed_folders = ?, role = ? WHERE id = ?' ,
269269 [ user . email , JSON . stringify ( user . allowedFolders ) , user . role , user . id ]
@@ -275,7 +275,7 @@ ipcMain.handle('update-rbac-user', async (_event, url: string, user: { id: strin
275275 }
276276 } else if ( url . startsWith ( 'postgres://' ) || url . startsWith ( 'postgresql://' ) ) {
277277 try {
278- const client = new pg . Client ( { connectionString : url , ssl : { rejectUnauthorized : false } } )
278+ const client = new pg . Client ( { connectionString : url , connectionTimeoutMillis : 10000 , ssl : { rejectUnauthorized : false } } )
279279 await client . connect ( )
280280 await client . query (
281281 'UPDATE rbac_users SET email = $1, allowed_folders = $2, role = $3 WHERE id = $4' ,
@@ -293,7 +293,7 @@ ipcMain.handle('update-rbac-user', async (_event, url: string, user: { id: strin
293293ipcMain . handle ( 'delete-rbac-user' , async ( _event , url : string , userId : string ) => {
294294 if ( url . startsWith ( 'mysql://' ) ) {
295295 try {
296- const conn = await mysql . createConnection ( url )
296+ const conn = await mysql . createConnection ( { uri : url , connectTimeout : 10000 } )
297297 await conn . execute ( 'DELETE FROM rbac_users WHERE id = ?' , [ userId ] )
298298 await conn . end ( )
299299 return { success : true }
@@ -302,7 +302,7 @@ ipcMain.handle('delete-rbac-user', async (_event, url: string, userId: string) =
302302 }
303303 } else if ( url . startsWith ( 'postgres://' ) || url . startsWith ( 'postgresql://' ) ) {
304304 try {
305- const client = new pg . Client ( { connectionString : url , ssl : { rejectUnauthorized : false } } )
305+ const client = new pg . Client ( { connectionString : url , connectionTimeoutMillis : 10000 , ssl : { rejectUnauthorized : false } } )
306306 await client . connect ( )
307307 await client . query ( 'DELETE FROM rbac_users WHERE id = $1' , [ userId ] )
308308 await client . end ( )
@@ -319,7 +319,7 @@ ipcMain.handle('sync-direct', async (_event, url: string, entries: any[]) => {
319319
320320 if ( url . startsWith ( 'mysql://' ) ) {
321321 try {
322- const conn = await mysql . createConnection ( { uri : url , multipleStatements : true } )
322+ const conn = await mysql . createConnection ( { uri : url , multipleStatements : true , connectTimeout : 10000 } )
323323 for ( const entry of entries ) {
324324 const { tableName, operation, data } = entry
325325 const payload = typeof data === 'string' ? JSON . parse ( data ) : data
@@ -381,7 +381,7 @@ ipcMain.handle('sync-direct', async (_event, url: string, entries: any[]) => {
381381 }
382382 } else if ( url . startsWith ( 'postgres://' ) || url . startsWith ( 'postgresql://' ) ) {
383383 try {
384- const client = new pg . Client ( { connectionString : url , ssl : { rejectUnauthorized : false } } )
384+ const client = new pg . Client ( { connectionString : url , connectionTimeoutMillis : 10000 , ssl : { rejectUnauthorized : false } } )
385385 await client . connect ( )
386386 for ( const entry of entries ) {
387387 const { tableName, operation, data } = entry
@@ -441,7 +441,7 @@ ipcMain.handle('sync-direct', async (_event, url: string, entries: any[]) => {
441441ipcMain . handle ( 'fetch-remote-data' , async ( _event , url : string , projectId : string ) => {
442442 if ( url . startsWith ( 'mysql://' ) ) {
443443 try {
444- const conn = await mysql . createConnection ( url )
444+ const conn = await mysql . createConnection ( { uri : url , connectTimeout : 10000 } )
445445 const [ folders ] : any = await conn . execute ( 'SELECT * FROM folders WHERE project_id = ?' , [ projectId ] )
446446 const [ apis ] : any = await conn . execute ( 'SELECT * FROM api_collections WHERE project_id = ?' , [ projectId ] )
447447 await conn . end ( )
@@ -451,7 +451,7 @@ ipcMain.handle('fetch-remote-data', async (_event, url: string, projectId: strin
451451 }
452452 } else if ( url . startsWith ( 'postgres://' ) || url . startsWith ( 'postgresql://' ) ) {
453453 try {
454- const client = new pg . Client ( { connectionString : url , ssl : { rejectUnauthorized : false } } )
454+ const client = new pg . Client ( { connectionString : url , connectionTimeoutMillis : 10000 , ssl : { rejectUnauthorized : false } } )
455455 await client . connect ( )
456456 const foldersRes = await client . query ( 'SELECT * FROM folders WHERE project_id = $1' , [ projectId ] )
457457 const apisRes = await client . query ( 'SELECT * FROM api_collections WHERE project_id = $1' , [ projectId ] )
@@ -467,7 +467,7 @@ ipcMain.handle('fetch-remote-data', async (_event, url: string, projectId: strin
467467ipcMain . handle ( 'get-remote-projects' , async ( _event , url : string ) => {
468468 if ( url . startsWith ( 'mysql://' ) ) {
469469 try {
470- const conn = await mysql . createConnection ( url )
470+ const conn = await mysql . createConnection ( { uri : url , connectTimeout : 10000 } )
471471 const [ rows ] : any = await conn . execute ( 'SELECT id, name, created_at FROM projects ORDER BY created_at DESC' )
472472 await conn . end ( )
473473 return { success : true , projects : rows }
@@ -476,7 +476,7 @@ ipcMain.handle('get-remote-projects', async (_event, url: string) => {
476476 }
477477 } else if ( url . startsWith ( 'postgres://' ) || url . startsWith ( 'postgresql://' ) ) {
478478 try {
479- const client = new pg . Client ( { connectionString : url , ssl : { rejectUnauthorized : false } } )
479+ const client = new pg . Client ( { connectionString : url , connectionTimeoutMillis : 10000 , ssl : { rejectUnauthorized : false } } )
480480 await client . connect ( )
481481 const res = await client . query ( 'SELECT id, name, created_at FROM projects ORDER BY created_at DESC' )
482482 await client . end ( )
@@ -491,7 +491,7 @@ ipcMain.handle('get-remote-projects', async (_event, url: string) => {
491491ipcMain . handle ( 'delete-remote-project' , async ( _event , url : string , projectId : string ) => {
492492 if ( url . startsWith ( 'mysql://' ) ) {
493493 try {
494- const conn = await mysql . createConnection ( url )
494+ const conn = await mysql . createConnection ( { uri : url , connectTimeout : 10000 } )
495495 await conn . execute ( 'DELETE FROM api_collections WHERE project_id = ?' , [ projectId ] )
496496 await conn . execute ( 'DELETE FROM folders WHERE project_id = ?' , [ projectId ] )
497497 await conn . execute ( 'DELETE FROM rbac_users WHERE project_id = ?' , [ projectId ] )
@@ -503,7 +503,7 @@ ipcMain.handle('delete-remote-project', async (_event, url: string, projectId: s
503503 }
504504 } else if ( url . startsWith ( 'postgres://' ) || url . startsWith ( 'postgresql://' ) ) {
505505 try {
506- const client = new pg . Client ( { connectionString : url , ssl : { rejectUnauthorized : false } } )
506+ const client = new pg . Client ( { connectionString : url , connectionTimeoutMillis : 10000 , ssl : { rejectUnauthorized : false } } )
507507 await client . connect ( )
508508 await client . query ( 'DELETE FROM api_collections WHERE project_id = $1' , [ projectId ] )
509509 await client . query ( 'DELETE FROM folders WHERE project_id = $1' , [ projectId ] )
0 commit comments