Merge branch 'main' into add-qbittorrent
This commit is contained in:
commit
6c01a85077
4 changed files with 45 additions and 3 deletions
19
.vscode/launch.json
vendored
Normal file
19
.vscode/launch.json
vendored
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
{
|
||||||
|
// Use IntelliSense to learn about possible attributes.
|
||||||
|
// Hover to view descriptions of existing attributes.
|
||||||
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "Next.js: debug full stack",
|
||||||
|
"type": "node",
|
||||||
|
"request": "launch",
|
||||||
|
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/next",
|
||||||
|
"serverReadyAction": {
|
||||||
|
"pattern": "started server on .+, url: (https?://.+)",
|
||||||
|
"uriFormat": "%s",
|
||||||
|
"action": "debugWithChrome"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
|
@ -6,6 +6,16 @@ import npmProxyHandler from "utils/proxies/npm";
|
||||||
import transmissionProxyHandler from "utils/proxies/transmission";
|
import transmissionProxyHandler from "utils/proxies/transmission";
|
||||||
import qbittorrentProxyHandler from "utils/proxies/qbittorrent";
|
import qbittorrentProxyHandler from "utils/proxies/qbittorrent";
|
||||||
|
|
||||||
|
function jsonArrayMapper(data, map) {
|
||||||
|
if (data?.length > 0) {
|
||||||
|
const json = JSON.parse(data.toString());
|
||||||
|
if (json instanceof Array) {
|
||||||
|
return json.map(map);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
const serviceProxyHandlers = {
|
const serviceProxyHandlers = {
|
||||||
// uses query param auth
|
// uses query param auth
|
||||||
emby: genericProxyHandler,
|
emby: genericProxyHandler,
|
||||||
|
@ -44,7 +54,14 @@ export default async function handler(req, res) {
|
||||||
const serviceProxyHandler = serviceProxyHandlers[type];
|
const serviceProxyHandler = serviceProxyHandlers[type];
|
||||||
|
|
||||||
if (serviceProxyHandler) {
|
if (serviceProxyHandler) {
|
||||||
return serviceProxyHandler(req, res);
|
if (serviceProxyHandler instanceof Function) {
|
||||||
|
return serviceProxyHandler(req, res);
|
||||||
|
}
|
||||||
|
|
||||||
|
const { proxy, maps } = serviceProxyHandler;
|
||||||
|
if (proxy) {
|
||||||
|
return proxy(req, res, maps);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return res.status(403).json({ error: "Unkown proxy service type" });
|
return res.status(403).json({ error: "Unkown proxy service type" });
|
||||||
|
|
|
@ -46,6 +46,7 @@ export default function Home({ settings }) {
|
||||||
if (settings.background) {
|
if (settings.background) {
|
||||||
wrappedStyle.backgroundImage = `url(${settings.background})`;
|
wrappedStyle.backgroundImage = `url(${settings.background})`;
|
||||||
wrappedStyle.backgroundSize = "cover";
|
wrappedStyle.backgroundSize = "cover";
|
||||||
|
wrappedStyle.opacity = settings.backgroundOpacity ?? 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
|
@ -2,7 +2,7 @@ import getServiceWidget from "utils/service-helpers";
|
||||||
import { formatApiCall } from "utils/api-helpers";
|
import { formatApiCall } from "utils/api-helpers";
|
||||||
import { httpProxy } from "utils/http";
|
import { httpProxy } from "utils/http";
|
||||||
|
|
||||||
export default async function genericProxyHandler(req, res) {
|
export default async function genericProxyHandler(req, res, maps) {
|
||||||
const { group, service, endpoint } = req.query;
|
const { group, service, endpoint } = req.query;
|
||||||
|
|
||||||
if (group && service) {
|
if (group && service) {
|
||||||
|
@ -23,13 +23,18 @@ export default async function genericProxyHandler(req, res) {
|
||||||
headers,
|
headers,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let resultData = data;
|
||||||
|
if (maps?.[endpoint]) {
|
||||||
|
resultData = maps[endpoint](data);
|
||||||
|
}
|
||||||
|
|
||||||
if (contentType) res.setHeader("Content-Type", contentType);
|
if (contentType) res.setHeader("Content-Type", contentType);
|
||||||
|
|
||||||
if (status === 204 || status === 304) {
|
if (status === 204 || status === 304) {
|
||||||
return res.status(status).end();
|
return res.status(status).end();
|
||||||
}
|
}
|
||||||
|
|
||||||
return res.status(status).send(data);
|
return res.status(status).send(resultData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue