mirror of
https://github.com/ajnart/homarr.git
synced 2025-11-11 16:05:47 +01:00
@@ -1,16 +1,38 @@
|
||||
import { Deluge } from '@ctrl/deluge';
|
||||
import { QBittorrent } from '@ctrl/qbittorrent';
|
||||
import { NextApiRequest, NextApiResponse } from 'next';
|
||||
|
||||
async function Post(req: NextApiRequest, res: NextApiResponse) {
|
||||
// Get the body
|
||||
// Get the type of service from the request url
|
||||
const { dlclient } = req.query;
|
||||
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,
|
||||
});
|
||||
if (!dlclient || (!username && !password) || !url) {
|
||||
return res.status(400).json({
|
||||
error: 'Wrong request',
|
||||
});
|
||||
}
|
||||
let client: Deluge | QBittorrent;
|
||||
switch (dlclient) {
|
||||
case 'qbit':
|
||||
client = new QBittorrent({
|
||||
baseUrl: new URL(url).origin,
|
||||
username,
|
||||
password,
|
||||
});
|
||||
break;
|
||||
case 'deluge':
|
||||
client = new Deluge({
|
||||
baseUrl: new URL(url).origin,
|
||||
password,
|
||||
});
|
||||
break;
|
||||
default:
|
||||
return res.status(400).json({
|
||||
error: 'Wrong request',
|
||||
});
|
||||
}
|
||||
const data = await client.getAllData();
|
||||
res.status(200).json({
|
||||
torrents: data.torrents,
|
||||
|
||||
Reference in New Issue
Block a user