mirror of
https://github.com/DI0IK/homepage-plus.git
synced 2025-07-12 07:58:49 +00:00
Merge branch 'main' into kubernetes
This commit is contained in:
commit
b6e8b64a2e
10 changed files with 700 additions and 250 deletions
|
@ -13,22 +13,23 @@ const textSizes = {
|
|||
};
|
||||
|
||||
export default function DateTime({ options }) {
|
||||
const { text_size: textSize, format } = options;
|
||||
const { text_size: textSize, locale, format } = options;
|
||||
const { i18n } = useTranslation();
|
||||
const [date, setDate] = useState("");
|
||||
const dateLocale = locale ?? i18n.language;
|
||||
|
||||
useEffect(() => {
|
||||
const dateFormat = new Intl.DateTimeFormat(i18n.language, { ...format });
|
||||
const dateFormat = new Intl.DateTimeFormat(dateLocale, { ...format });
|
||||
const interval = setInterval(() => {
|
||||
setDate(dateFormat.format(new Date()));
|
||||
}, 1000);
|
||||
return () => clearInterval(interval);
|
||||
}, [date, setDate, i18n.language, format]);
|
||||
}, [date, setDate, dateLocale, format]);
|
||||
|
||||
return (
|
||||
<div className="flex flex-col justify-center first:ml-0 ml-4">
|
||||
<div className="flex flex-row items-center grow justify-end">
|
||||
<span className={`text-theme-800 dark:text-theme-200 ${textSizes[textSize || "lg"]}`}>
|
||||
<span className={`text-theme-800 dark:text-theme-200 tabular-nums ${textSizes[textSize || "lg"]}`}>
|
||||
{date}
|
||||
</span>
|
||||
</div>
|
||||
|
|
|
@ -30,6 +30,8 @@ export default async function credentialedProxyHandler(req, res, map) {
|
|||
headers["X-gotify-Key"] = `${widget.key}`;
|
||||
} else if (widget.type === "authentik") {
|
||||
headers.Authorization = `Bearer ${widget.key}`;
|
||||
} else if (widget.type === "truenas") {
|
||||
headers.Authorization = `Bearer ${widget.key}`;
|
||||
} else if (widget.type === "proxmox") {
|
||||
headers.Authorization = `PVEAPIToken=${widget.username}=${widget.password}`;
|
||||
} else if (widget.type === "autobrr") {
|
||||
|
|
|
@ -4,8 +4,8 @@ import { formatProxyUrl } from "./api-helpers";
|
|||
|
||||
export default function useWidgetAPI(widget, ...options) {
|
||||
const config = {};
|
||||
if (options?.refreshInterval) {
|
||||
config.refreshInterval = options.refreshInterval;
|
||||
if (options && options[1]?.refreshInterval) {
|
||||
config.refreshInterval = options[1].refreshInterval;
|
||||
}
|
||||
const { data, error } = useSWR(formatProxyUrl(widget, ...options), config);
|
||||
// make the data error the top-level error
|
||||
|
|
|
@ -5,10 +5,8 @@ import widgets from "widgets/widgets";
|
|||
import getServiceWidget from "utils/config/service-helpers";
|
||||
|
||||
const logger = createLogger("downloadstationProxyHandler");
|
||||
const authApi = "{url}/webapi/auth.cgi?api=SYNO.API.Auth&version=2&method=login&account={username}&passwd={password}&session=DownloadStation&format=cookie"
|
||||
|
||||
async function login(widget) {
|
||||
const loginUrl = formatApiCall(authApi, widget);
|
||||
async function login(loginUrl) {
|
||||
const [status, contentType, data] = await httpProxy(loginUrl);
|
||||
if (status !== 200) {
|
||||
return [status, contentType, data];
|
||||
|
@ -56,8 +54,28 @@ export default async function downloadstationProxyHandler(req, res) {
|
|||
|
||||
const json = JSON.parse(data.toString());
|
||||
if (json?.success !== true) {
|
||||
logger.debug("Logging in to DownloadStation");
|
||||
[status, contentType, data] = await login(widget);
|
||||
logger.debug("Attempting login to DownloadStation");
|
||||
|
||||
const apiInfoUrl = formatApiCall("{url}/webapi/query.cgi?api=SYNO.API.Info&version=1&method=query", widget);
|
||||
let path = "entry.cgi";
|
||||
let maxVersion = 7;
|
||||
[status, contentType, data] = await httpProxy(apiInfoUrl);
|
||||
if (status === 200) {
|
||||
try {
|
||||
const apiAuthInfo = JSON.parse(data.toString()).data['SYNO.API.Auth'];
|
||||
if (apiAuthInfo) {
|
||||
path = apiAuthInfo.path;
|
||||
maxVersion = apiAuthInfo.maxVersion;
|
||||
logger.debug(`Deteceted Downloadstation auth API path: ${path} and maxVersion: ${maxVersion}`);
|
||||
}
|
||||
} catch {
|
||||
logger.debug(`Error ${status} obtaining DownloadStation API info`);
|
||||
}
|
||||
}
|
||||
|
||||
const authApi = `{url}/webapi/${path}?api=SYNO.API.Auth&version=${maxVersion}&method=login&account={username}&passwd={password}&session=DownloadStation&format=cookie`
|
||||
const loginUrl = formatApiCall(authApi, widget);
|
||||
[status, contentType, data] = await login(loginUrl);
|
||||
if (status !== 200) {
|
||||
return res.status(status).end(data)
|
||||
}
|
||||
|
|
|
@ -1,9 +1,31 @@
|
|||
import { jsonArrayFilter } from "utils/proxy/api-helpers";
|
||||
import credentialedProxyHandler from "utils/proxy/handlers/credentialed";
|
||||
import genericProxyHandler from "utils/proxy/handlers/generic";
|
||||
import getServiceWidget from "utils/config/service-helpers";
|
||||
|
||||
const widget = {
|
||||
api: "{url}/api/v2.0/{endpoint}",
|
||||
proxyHandler: genericProxyHandler,
|
||||
proxyHandler: async (req, res, map) => { // choose proxy handler based on widget settings
|
||||
const { group, service } = req.query;
|
||||
|
||||
if (group && service) {
|
||||
const widgetOpts = await getServiceWidget(group, service);
|
||||
let handler;
|
||||
if (widgetOpts.username && widgetOpts.password) {
|
||||
handler = genericProxyHandler;
|
||||
} else if (widgetOpts.key) {
|
||||
handler = credentialedProxyHandler;
|
||||
}
|
||||
|
||||
if (handler) {
|
||||
return handler(req, res, map);
|
||||
}
|
||||
|
||||
return res.status(500).json({ error: "Username / password or API key required" });
|
||||
}
|
||||
|
||||
return res.status(500).json({ error: "Error parsing widget request" });
|
||||
},
|
||||
|
||||
mappings: {
|
||||
alerts: {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue