mirror of
https://github.com/DI0IK/homepage-plus.git
synced 2025-07-08 14:38:47 +00:00
Add Pyload widget
This commit is contained in:
parent
49a764e864
commit
5b21444c2e
7 changed files with 88 additions and 0 deletions
38
src/widgets/pyload/proxy.js
Normal file
38
src/widgets/pyload/proxy.js
Normal file
|
@ -0,0 +1,38 @@
|
|||
import getServiceWidget from "utils/config/service-helpers";
|
||||
import { formatApiCall } from "utils/proxy/api-helpers";
|
||||
import widgets from "widgets/widgets";
|
||||
|
||||
export default async function pyloadProxyHandler(req, res) {
|
||||
const { group, service, endpoint } = req.query;
|
||||
|
||||
if (group && service) {
|
||||
const widget = await getServiceWidget(group, service);
|
||||
|
||||
if (widget) {
|
||||
const url = new URL(formatApiCall(widgets[widget.type].api, { endpoint, ...widget }));
|
||||
const loginUrl = `${widget.url}/api/login`;
|
||||
|
||||
// Pyload api does not support argument passing as JSON.
|
||||
const sessionId = await fetch(loginUrl, {
|
||||
method: "POST",
|
||||
// Empty passwords are supported.
|
||||
body: `username=${widget.username}&password=${widget.password ?? ''}`,
|
||||
headers: {
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
},
|
||||
}).then((response) => response.json());
|
||||
|
||||
const apiResponse = await fetch(url, {
|
||||
method: "POST",
|
||||
body: `session=${sessionId}`,
|
||||
headers: {
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
},
|
||||
}).then((response) => response.json());
|
||||
|
||||
return res.send(apiResponse);
|
||||
}
|
||||
}
|
||||
|
||||
return res.status(400).json({ error: "Invalid proxy service type" });
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue