From 99db32ba2cc742b891d3699113b535ff9d6904ee Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Sat, 26 Oct 2024 05:47:49 +0530 Subject: [PATCH] feat: delete proxy config --- server/src/routes/proxy.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/server/src/routes/proxy.ts b/server/src/routes/proxy.ts index 8318b9be..99141f0e 100644 --- a/server/src/routes/proxy.ts +++ b/server/src/routes/proxy.ts @@ -116,6 +116,29 @@ router.get('/config', requireSignIn, async (req: AuthenticatedRequest, res: Resp }); }); +// delete proxy configuration +router.delete('/config', requireSignIn, async (req: AuthenticatedRequest, res: Response) => { + if (!req.user) { + return res.status(401).json({ ok: false, error: 'Unauthorized' }); + } + + const user = await User.findByPk(req.user.id, { + attributes: ['proxy_url', 'proxy_username', 'proxy_password'], + }); + + if (!user) { + return res.status(404).json({ message: 'User not found' }); + } + + user.proxy_url = null; + user.proxy_username = null; + user.proxy_password = null; + + await user.save(); + + res.status(200).json({ message: 'Proxy configuration deleted successfully' }); +}); + const maskProxyUrl = (url: string) => { const urlWithoutProtocol = url.replace(/^https?:\/\//, '').replace(/^socks5?:\/\//, ''); // Remove protocols const [domain, port] = urlWithoutProtocol.split(':');