mirror of
https://github.com/DI0IK/homepage-plus.git
synced 2025-07-10 07:18:47 +00:00
Add Transmission widget
- Update http.js to support writing request bodies - Update http.js to support returning all response headers resolves: #104
This commit is contained in:
parent
406358aae9
commit
b3db549a65
8 changed files with 148 additions and 4 deletions
|
@ -9,6 +9,7 @@ const formats = {
|
|||
traefik: `{url}/api/{endpoint}`,
|
||||
portainer: `{url}/api/endpoints/{env}/{endpoint}`,
|
||||
rutorrent: `{url}/plugins/httprpc/action.php`,
|
||||
transmission: `{url}/transmission/rpc`,
|
||||
jellyseerr: `{url}/api/v1/{endpoint}`,
|
||||
overseerr: `{url}/api/v1/{endpoint}`,
|
||||
ombi: `{url}/api/v1/{endpoint}`,
|
||||
|
|
|
@ -12,7 +12,7 @@ export function httpsRequest(url, params) {
|
|||
});
|
||||
|
||||
response.on("end", () => {
|
||||
resolve([response.statusCode, response.headers["content-type"], Buffer.concat(data)]);
|
||||
resolve([response.statusCode, response.headers["content-type"], Buffer.concat(data), response.headers]);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -20,6 +20,10 @@ export function httpsRequest(url, params) {
|
|||
reject([500, error]);
|
||||
});
|
||||
|
||||
if (params.body) {
|
||||
request.write(params.body);
|
||||
}
|
||||
|
||||
request.end();
|
||||
});
|
||||
}
|
||||
|
@ -34,7 +38,7 @@ export function httpRequest(url, params) {
|
|||
});
|
||||
|
||||
response.on("end", () => {
|
||||
resolve([response.statusCode, response.headers["content-type"], Buffer.concat(data)]);
|
||||
resolve([response.statusCode, response.headers["content-type"], Buffer.concat(data), response.headers]);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -42,6 +46,10 @@ export function httpRequest(url, params) {
|
|||
reject([500, error]);
|
||||
});
|
||||
|
||||
if (params.body) {
|
||||
request.write(params.body);
|
||||
}
|
||||
|
||||
request.end();
|
||||
});
|
||||
}
|
||||
|
|
56
src/utils/proxies/transmission.js
Normal file
56
src/utils/proxies/transmission.js
Normal file
|
@ -0,0 +1,56 @@
|
|||
import { httpProxy } from "utils/http";
|
||||
import { formatApiCall } from "utils/api-helpers";
|
||||
|
||||
import getServiceWidget from "utils/service-helpers";
|
||||
|
||||
export default async function transmissionProxyHandler(req, res) {
|
||||
const { group, service, endpoint } = req.query;
|
||||
|
||||
if (!group || !service) {
|
||||
return res.status(400).json({ error: "Invalid proxy service type" });
|
||||
}
|
||||
|
||||
const widget = await getServiceWidget(group, service);
|
||||
|
||||
if (!widget) {
|
||||
return res.status(400).json({ error: "Invalid proxy service type" });
|
||||
}
|
||||
|
||||
const url = new URL(formatApiCall(widget.type, { endpoint, ...widget }));
|
||||
const csrfHeaderName = "x-transmission-session-id";
|
||||
|
||||
const method = "POST";
|
||||
const body = JSON.stringify({
|
||||
method: "torrent-get",
|
||||
arguments: {
|
||||
fields: ["percentDone", "status", "rateDownload", "rateUpload"]
|
||||
}
|
||||
});
|
||||
|
||||
const reqHeaders = {
|
||||
"content-type": "application/json",
|
||||
};
|
||||
|
||||
let [status, contentType, data, responseHeaders] = await httpProxy(url, {
|
||||
method: method,
|
||||
auth: `${widget.username}:${widget.password}`,
|
||||
body: body,
|
||||
headers: reqHeaders,
|
||||
});
|
||||
|
||||
if (status === 409) {
|
||||
// Transmission is rejecting the request, but returning a CSRF token
|
||||
reqHeaders[csrfHeaderName] = responseHeaders[csrfHeaderName];
|
||||
|
||||
// retry the request, now with the CSRF token
|
||||
[status, contentType, data] = await httpProxy(url, {
|
||||
method: method,
|
||||
auth: `${widget.username}:${widget.password}`,
|
||||
body: body,
|
||||
headers: reqHeaders,
|
||||
});
|
||||
}
|
||||
|
||||
if (contentType) res.setHeader("Content-Type", contentType);
|
||||
return res.status(status).send(data);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue