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