mirror of
https://github.com/gethomepage/homepage.git
synced 2026-02-07 16:30:52 +08:00
Use a separate custom proxy for jellyfin, sadly
This commit is contained in:
@@ -123,8 +123,6 @@ export default async function credentialedProxyHandler(req, res, map) {
|
||||
// v1 does not require a key
|
||||
headers.Authorization = `Bearer ${widget.key}`;
|
||||
}
|
||||
} else if (widget.type === "jellyfin") {
|
||||
headers["Authorization"] = `MediaBrowser Token=${widget.key}`;
|
||||
} else {
|
||||
headers["X-API-Key"] = `${widget.key}`;
|
||||
}
|
||||
|
||||
66
src/widgets/jellyfin/proxy.js
Normal file
66
src/widgets/jellyfin/proxy.js
Normal file
@@ -0,0 +1,66 @@
|
||||
import getServiceWidget from "utils/config/service-helpers";
|
||||
import createLogger from "utils/logger";
|
||||
import { formatApiCall, sanitizeErrorURL } from "utils/proxy/api-helpers";
|
||||
import { httpProxy } from "utils/proxy/http";
|
||||
import validateWidgetData from "utils/proxy/validate-widget-data";
|
||||
import widgets from "widgets/widgets";
|
||||
|
||||
const logger = createLogger("jellyfinProxyHandler");
|
||||
|
||||
export default async function jellyfinProxyHandler(req, res, map) {
|
||||
const { group, service, endpoint, index } = req.query;
|
||||
|
||||
if (!group || !service) {
|
||||
logger.debug("Invalid or missing proxy service type '%s' in group '%s'", service, group);
|
||||
return res.status(400).json({ error: "Invalid proxy service type" });
|
||||
}
|
||||
|
||||
const widget = await getServiceWidget(group, service, index);
|
||||
|
||||
if (!widget || !widgets?.[widget.type]?.api) {
|
||||
logger.debug("Invalid or missing proxy service type '%s' in group '%s'", service, group);
|
||||
return res.status(403).json({ error: "Service does not support API calls" });
|
||||
}
|
||||
|
||||
const url = new URL(formatApiCall(widgets[widget.type].api, { endpoint, ...widget }));
|
||||
|
||||
const headers = {
|
||||
Authorization: `MediaBrowser Token=${widget.key}`,
|
||||
"Content-Type": "application/json",
|
||||
"X-Emby-Token": widget.key,
|
||||
"X-MediaBrowser-Token": widget.key,
|
||||
};
|
||||
|
||||
const params = {
|
||||
method: req.method,
|
||||
withCredentials: true,
|
||||
credentials: "include",
|
||||
headers,
|
||||
};
|
||||
|
||||
const [status, contentType, data] = await httpProxy(url, params);
|
||||
|
||||
let resultData = data;
|
||||
|
||||
if (resultData.error?.url) {
|
||||
resultData.error.url = sanitizeErrorURL(url);
|
||||
}
|
||||
|
||||
if (status === 204 || status === 304) {
|
||||
return res.status(status).end();
|
||||
}
|
||||
|
||||
if (status >= 400) {
|
||||
logger.error("HTTP Error %d calling %s", status, url.toString());
|
||||
}
|
||||
|
||||
if (status === 200) {
|
||||
if (!validateWidgetData(widget, endpoint, resultData)) {
|
||||
return res.status(500).json({ error: { message: "Invalid data", url: sanitizeErrorURL(url), data: resultData } });
|
||||
}
|
||||
if (map) resultData = map(resultData);
|
||||
}
|
||||
|
||||
if (contentType) res.setHeader("Content-Type", contentType);
|
||||
return res.status(status).send(resultData);
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
import credentialedProxyHandler from "utils/proxy/handlers/credentialed";
|
||||
import jellyfinProxyHandler from "./proxy";
|
||||
|
||||
const widget = {
|
||||
api: "{url}/{endpoint}",
|
||||
proxyHandler: credentialedProxyHandler,
|
||||
proxyHandler: jellyfinProxyHandler,
|
||||
mappings: {
|
||||
Sessions: {
|
||||
endpoint: "emby/Sessions?api_key={key}",
|
||||
@@ -20,6 +20,7 @@ const widget = {
|
||||
endpoint: "emby/Sessions/{sessionId}/Playing/Pause?api_key={key}",
|
||||
segments: ["sessionId"],
|
||||
},
|
||||
// V2 Endpoints
|
||||
SessionsV2: {
|
||||
endpoint: "Sessions",
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user