From a6875abfe339b8c75c03c71931e253d1e4baed30 Mon Sep 17 00:00:00 2001 From: ajnart Date: Thu, 26 May 2022 18:18:30 +0200 Subject: [PATCH] :speech_balloon: Update API to support getting downloads --- src/pages/api/modules/downloads.ts | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/pages/api/modules/downloads.ts diff --git a/src/pages/api/modules/downloads.ts b/src/pages/api/modules/downloads.ts new file mode 100644 index 000000000..46edc5a80 --- /dev/null +++ b/src/pages/api/modules/downloads.ts @@ -0,0 +1,29 @@ +import { QBittorrent } from '@ctrl/qbittorrent'; +import { NextApiRequest, NextApiResponse } from 'next'; + +async function Post(req: NextApiRequest, res: NextApiResponse) { + // Get the body + const { body } = req; + // Get login, password and url from the body + const { username, password, url } = body; + const client = new QBittorrent({ + baseUrl: new URL(url).origin, + username, + password, + }); + const data = await client.getAllData(); + res.status(200).json({ + torrents: data.torrents, + }); +} + +export default async (req: NextApiRequest, res: NextApiResponse) => { + // Filter out if the reuqest is a POST or a GET + if (req.method === 'POST') { + return Post(req, res); + } + return res.status(405).json({ + statusCode: 405, + message: 'Method not allowed', + }); +};