minor code cleanup
This commit is contained in:
parent
8149a1a9f6
commit
ee042f6f13
@ -13,5 +13,5 @@ Allowed fields: `["configured", "errored"]`.
|
||||
widget:
|
||||
type: jackett
|
||||
url: http://jackett.host.or.ip
|
||||
password: JackettAdminPassword
|
||||
password: jackettadminpassword # optional
|
||||
```
|
||||
|
||||
@ -6,24 +6,22 @@ import widgets from "widgets/widgets";
|
||||
|
||||
const logger = createLogger("jackettProxyHandler");
|
||||
|
||||
// Fetches the Jackett cookie; assumes implementation is similar to the previous discussion
|
||||
async function fetchJackettCookie(widget, loginURL) {
|
||||
const url = new URL(formatApiCall(loginURL, widget));
|
||||
const loginData = `password=${encodeURIComponent(widget.password)}`;
|
||||
const [status, , , , params] = await httpProxy(url, {
|
||||
method: 'POST',
|
||||
method: "POST",
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded'
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
},
|
||||
body: loginData,
|
||||
});
|
||||
|
||||
if (!(status === 200) || !params || !params.headers || !params.headers.Cookie) {
|
||||
if (!(status === 200) || !params?.headers?.Cookie) {
|
||||
logger.error("Failed to fetch Jackett cookie, status: %d", status);
|
||||
return null;
|
||||
}
|
||||
const cookieValue = params.headers.Cookie;
|
||||
return cookieValue;
|
||||
return params.headers.Cookie;
|
||||
}
|
||||
|
||||
export default async function jackettProxyHandler(req, res) {
|
||||
@ -49,11 +47,10 @@ export default async function jackettProxyHandler(req, res) {
|
||||
widget.headers = { ...widget.headers, Cookie: jackettCookie };
|
||||
}
|
||||
|
||||
// Construct the API call to Jackett
|
||||
const url = new URL(formatApiCall(widgets[widget.type].api, { endpoint, ...widget }));
|
||||
|
||||
try {
|
||||
const [status, contentType, data] = await httpProxy(url.toString(), {
|
||||
const [status, , data] = await httpProxy(url, {
|
||||
method: "GET",
|
||||
headers: widget.headers,
|
||||
});
|
||||
@ -63,9 +60,6 @@ export default async function jackettProxyHandler(req, res) {
|
||||
return res.status(status).json({ error: "Failed to call Jackett API", data });
|
||||
}
|
||||
|
||||
if (contentType) {
|
||||
res.setHeader("Content-Type", contentType);
|
||||
}
|
||||
return res.status(status).send(data);
|
||||
} catch (error) {
|
||||
logger.error("Exception calling Jackett API: %s", error.message);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user