commit
174cb651b4
@ -0,0 +1,6 @@
|
||||
ARG VARIANT="16-buster"
|
||||
FROM mcr.microsoft.com/vscode/devcontainers/javascript-node:${VARIANT}
|
||||
|
||||
RUN npm install -g pnpm
|
||||
|
||||
ENV PATH="${PATH}:./node_modules/.bin"
|
@ -0,0 +1,27 @@
|
||||
{
|
||||
"name": "homepage",
|
||||
"build": {
|
||||
"dockerfile": "Dockerfile",
|
||||
"args": {
|
||||
"VARIANT": "18-buster"
|
||||
}
|
||||
},
|
||||
"customizations": {
|
||||
"vscode": {
|
||||
"extensions": [
|
||||
"dbaeumer.vscode-eslint",
|
||||
"mhutchie.git-graph",
|
||||
"streetsidesoftware.code-spell-checker",
|
||||
],
|
||||
"settings": {
|
||||
"eslint.format.enable": true,
|
||||
"eslint.lintTask.enable": true,
|
||||
"eslint.packageManager": "pnpm"
|
||||
}
|
||||
}
|
||||
},
|
||||
"postCreateCommand": ".devcontainer/setup.sh",
|
||||
"forwardPorts": [
|
||||
3000
|
||||
]
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Install Node packages
|
||||
pnpm install
|
||||
|
||||
# Copy in skeleton configuration if there is no existing configuration
|
||||
if [ ! -d "config/" ]; then
|
||||
echo "Adding skeleton config"
|
||||
mkdir config/
|
||||
cp -r src/skeleton/* config
|
||||
fi
|
@ -0,0 +1,365 @@
|
||||
{
|
||||
"widget": {
|
||||
"missing_type": "Missing Widget Type: {{type}}",
|
||||
"api_error": "API Error",
|
||||
"information": "Informo",
|
||||
"status": "Stato",
|
||||
"url": "URL",
|
||||
"raw_error": "Raw Error",
|
||||
"response_data": "Response Data"
|
||||
},
|
||||
"weather": {
|
||||
"current": "Aktuala loko",
|
||||
"allow": "Click to allow",
|
||||
"updating": "Updating",
|
||||
"wait": "Please wait"
|
||||
},
|
||||
"search": {
|
||||
"placeholder": "Serĉi…"
|
||||
},
|
||||
"resources": {
|
||||
"cpu": "Ĉefprocesoro",
|
||||
"total": "Totalo",
|
||||
"free": "Libera",
|
||||
"used": "Uzata",
|
||||
"load": "Ŝarĝo"
|
||||
},
|
||||
"unifi": {
|
||||
"users": "Uzantoj",
|
||||
"uptime": "System Uptime",
|
||||
"days": "Tagoj",
|
||||
"wan": "WAN",
|
||||
"lan": "LAN",
|
||||
"wlan": "WLAN",
|
||||
"devices": "Aparatoj",
|
||||
"lan_devices": "LAN Devices",
|
||||
"wlan_devices": "WLAN Devices",
|
||||
"lan_users": "LAN Users",
|
||||
"wlan_users": "WLAN Users",
|
||||
"up": "UP",
|
||||
"down": "DOWN",
|
||||
"wait": "Please wait"
|
||||
},
|
||||
"docker": {
|
||||
"rx": "RX",
|
||||
"tx": "TX",
|
||||
"mem": "Memoro",
|
||||
"cpu": "Ĉefprocesoro",
|
||||
"offline": "Offline",
|
||||
"error": "Eraro",
|
||||
"unknown": "Nekonata"
|
||||
},
|
||||
"ping": {
|
||||
"error": "Eraro",
|
||||
"ping": "Ping"
|
||||
},
|
||||
"emby": {
|
||||
"playing": "Ludante",
|
||||
"transcoding": "Transcoding",
|
||||
"bitrate": "Bitrate",
|
||||
"no_active": "No Active Streams"
|
||||
},
|
||||
"changedetectionio": {
|
||||
"totalObserved": "Total Observed",
|
||||
"diffsDetected": "Diffs Detected"
|
||||
},
|
||||
"tautulli": {
|
||||
"playing": "Playing",
|
||||
"transcoding": "Transcoding",
|
||||
"bitrate": "Bitrate",
|
||||
"no_active": "No Active Streams"
|
||||
},
|
||||
"nzbget": {
|
||||
"rate": "Rate",
|
||||
"remaining": "Remaining",
|
||||
"downloaded": "Downloaded"
|
||||
},
|
||||
"plex": {
|
||||
"streams": "Active Streams",
|
||||
"movies": "Filmoj",
|
||||
"tv": "Televidprogramoj"
|
||||
},
|
||||
"sabnzbd": {
|
||||
"rate": "Rate",
|
||||
"queue": "Queue",
|
||||
"timeleft": "Time Left"
|
||||
},
|
||||
"rutorrent": {
|
||||
"active": "Active",
|
||||
"upload": "Alŝuto",
|
||||
"download": "Elŝuto"
|
||||
},
|
||||
"transmission": {
|
||||
"download": "Elŝuto",
|
||||
"upload": "Alŝuto",
|
||||
"leech": "Leech",
|
||||
"seed": "Seed"
|
||||
},
|
||||
"qbittorrent": {
|
||||
"download": "Elŝuto",
|
||||
"upload": "Alŝuto",
|
||||
"leech": "Leech",
|
||||
"seed": "Seed"
|
||||
},
|
||||
"deluge": {
|
||||
"download": "Elŝuto",
|
||||
"upload": "Upload",
|
||||
"leech": "Leech",
|
||||
"seed": "Seed"
|
||||
},
|
||||
"sonarr": {
|
||||
"wanted": "Wanted",
|
||||
"queued": "Queued",
|
||||
"series": "Serio"
|
||||
},
|
||||
"radarr": {
|
||||
"wanted": "Wanted",
|
||||
"missing": "Missing",
|
||||
"queued": "Queued",
|
||||
"movies": "Filmoj"
|
||||
},
|
||||
"lidarr": {
|
||||
"wanted": "Wanted",
|
||||
"queued": "Queued",
|
||||
"albums": "Albumoj"
|
||||
},
|
||||
"readarr": {
|
||||
"wanted": "Wanted",
|
||||
"queued": "Queued",
|
||||
"books": "Libroj"
|
||||
},
|
||||
"bazarr": {
|
||||
"missingEpisodes": "Missing Episodes",
|
||||
"missingMovies": "Missing Movies"
|
||||
},
|
||||
"ombi": {
|
||||
"pending": "Pending",
|
||||
"approved": "Aprobita",
|
||||
"available": "Havebla"
|
||||
},
|
||||
"jellyseerr": {
|
||||
"pending": "Pending",
|
||||
"approved": "Aprobita",
|
||||
"available": "Havebla"
|
||||
},
|
||||
"overseerr": {
|
||||
"pending": "Pending",
|
||||
"processing": "Processing",
|
||||
"approved": "Aprobita",
|
||||
"available": "Havebla"
|
||||
},
|
||||
"pihole": {
|
||||
"queries": "Queries",
|
||||
"blocked": "Blocked",
|
||||
"gravity": "Gravity"
|
||||
},
|
||||
"adguard": {
|
||||
"queries": "Queries",
|
||||
"blocked": "Blokitaj",
|
||||
"filtered": "Filtritaj",
|
||||
"latency": "Latency"
|
||||
},
|
||||
"speedtest": {
|
||||
"upload": "Upload",
|
||||
"download": "Download",
|
||||
"ping": "Ping"
|
||||
},
|
||||
"portainer": {
|
||||
"running": "Running",
|
||||
"stopped": "Stopped",
|
||||
"total": "Totalo"
|
||||
},
|
||||
"traefik": {
|
||||
"routers": "Routers",
|
||||
"services": "Servoj",
|
||||
"middleware": "Middleware"
|
||||
},
|
||||
"navidrome": {
|
||||
"nothing_streaming": "No Active Streams",
|
||||
"please_wait": "Please Wait"
|
||||
},
|
||||
"npm": {
|
||||
"enabled": "Enabled",
|
||||
"disabled": "Disabled",
|
||||
"total": "Total"
|
||||
},
|
||||
"coinmarketcap": {
|
||||
"configure": "Configure one or more crypto currencies to track",
|
||||
"1hour": "1 horo",
|
||||
"1day": "1 tago",
|
||||
"7days": "7 tagoj",
|
||||
"30days": "30 tagoj"
|
||||
},
|
||||
"gotify": {
|
||||
"apps": "Applications",
|
||||
"clients": "Klientoj",
|
||||
"messages": "Mesaĝoj"
|
||||
},
|
||||
"prowlarr": {
|
||||
"enableIndexers": "Indexers",
|
||||
"numberOfGrabs": "Grabs",
|
||||
"numberOfQueries": "Queries",
|
||||
"numberOfFailGrabs": "Fail Grabs",
|
||||
"numberOfFailQueries": "Fail Queries"
|
||||
},
|
||||
"jackett": {
|
||||
"configured": "Configured",
|
||||
"errored": "Errored"
|
||||
},
|
||||
"strelaysrv": {
|
||||
"numActiveSessions": "Seancoj",
|
||||
"numConnections": "Konektoj",
|
||||
"dataRelayed": "Relayed",
|
||||
"transferRate": "Rate"
|
||||
},
|
||||
"mastodon": {
|
||||
"user_count": "Uzantoj",
|
||||
"status_count": "Afiŝoj",
|
||||
"domain_count": "Domains"
|
||||
},
|
||||
"authentik": {
|
||||
"users": "Users",
|
||||
"loginsLast24H": "Logins (24h)",
|
||||
"failedLoginsLast24H": "Failed Logins (24h)"
|
||||
},
|
||||
"proxmox": {
|
||||
"mem": "Memoro",
|
||||
"cpu": "Ĉefprocesoro",
|
||||
"lxc": "LXC",
|
||||
"vms": "VMs"
|
||||
},
|
||||
"glances": {
|
||||
"cpu": "Ĉefprocesoro",
|
||||
"mem": "Memoro",
|
||||
"wait": "Bonvolu atendi"
|
||||
},
|
||||
"quicklaunch": {
|
||||
"bookmark": "Bookmark",
|
||||
"service": "Servo"
|
||||
},
|
||||
"wmo": {
|
||||
"0-day": "Suna",
|
||||
"0-night": "Sennuba",
|
||||
"1-day": "Mainly Sunny",
|
||||
"1-night": "Mainly Clear",
|
||||
"2-day": "Nubeta",
|
||||
"2-night": "Nubeta",
|
||||
"3-day": "Nuba",
|
||||
"3-night": "Nuba",
|
||||
"45-day": "Nebula",
|
||||
"45-night": "Nebula",
|
||||
"48-day": "Nebula",
|
||||
"48-night": "Nebula",
|
||||
"51-day": "Light Drizzle",
|
||||
"51-night": "Light Drizzle",
|
||||
"53-day": "Drizzle",
|
||||
"53-night": "Drizzle",
|
||||
"55-day": "Heavy Drizzle",
|
||||
"55-night": "Heavy Drizzle",
|
||||
"56-day": "Light Freezing Drizzle",
|
||||
"56-night": "Light Freezing Drizzle",
|
||||
"57-day": "Freezing Drizzle",
|
||||
"57-night": "Freezing Drizzle",
|
||||
"61-day": "Light Rain",
|
||||
"61-night": "Light Rain",
|
||||
"63-day": "Pluvo",
|
||||
"63-night": "Pluvo",
|
||||
"65-day": "Pluvego",
|
||||
"65-night": "Pluvego",
|
||||
"66-day": "Frosta pluvo",
|
||||
"66-night": "Frosta pluvo",
|
||||
"67-day": "Frosta pluvo",
|
||||
"67-night": "Frosta pluvo",
|
||||
"71-day": "Light Snow",
|
||||
"71-night": "Light Snow",
|
||||
"73-day": "Neĝo",
|
||||
"73-night": "Neĝo",
|
||||
"75-day": "Neĝego",
|
||||
"75-night": "Neĝego",
|
||||
"77-day": "Snow Grains",
|
||||
"77-night": "Snow Grains",
|
||||
"80-day": "Light Showers",
|
||||
"80-night": "Light Showers",
|
||||
"81-day": "Showers",
|
||||
"81-night": "Showers",
|
||||
"82-day": "Heavy Showers",
|
||||
"82-night": "Heavy Showers",
|
||||
"85-day": "Snow Showers",
|
||||
"85-night": "Snow Showers",
|
||||
"86-day": "Snow Showers",
|
||||
"86-night": "Snow Showers",
|
||||
"95-day": "Fulmotondro",
|
||||
"95-night": "Fulmotondro",
|
||||
"96-day": "Fulmotondro kun hajlo",
|
||||
"96-night": "Fulmotondro kun hajlo",
|
||||
"99-day": "Fulmotondro kun hajlo",
|
||||
"99-night": "Fulmotondro kun hajlo"
|
||||
},
|
||||
"homebridge": {
|
||||
"available_update": "Sistemo",
|
||||
"updates": "Updates",
|
||||
"update_available": "Update Available",
|
||||
"up_to_date": "Up to Date",
|
||||
"child_bridges": "Child Bridges",
|
||||
"child_bridges_status": "{{ok}}/{{total}}"
|
||||
},
|
||||
"watchtower": {
|
||||
"containers_scanned": "Scanned",
|
||||
"containers_updated": "Updated",
|
||||
"containers_failed": "Failed"
|
||||
},
|
||||
"autobrr": {
|
||||
"approvedPushes": "Approved",
|
||||
"rejectedPushes": "Rejected",
|
||||
"filters": "Filtriloj",
|
||||
"indexers": "Indexers"
|
||||
},
|
||||
"tubearchivist": {
|
||||
"downloads": "Queue",
|
||||
"videos": "Videos",
|
||||
"channels": "Kanaloj",
|
||||
"playlists": "Playlists"
|
||||
},
|
||||
"truenas": {
|
||||
"load": "System Load",
|
||||
"uptime": "Uptime",
|
||||
"alerts": "Alerts",
|
||||
"time": "{{value, number(style: unit; unitDisplay: long;)}}"
|
||||
},
|
||||
"pyload": {
|
||||
"speed": "Speed",
|
||||
"active": "Aktiva",
|
||||
"queue": "Queue",
|
||||
"total": "Total"
|
||||
},
|
||||
"gluetun": {
|
||||
"public_ip": "Public IP",
|
||||
"region": "Regiono",
|
||||
"country": "Lando"
|
||||
},
|
||||
"hdhomerun": {
|
||||
"channels": "Kanaloj",
|
||||
"hd": "HD"
|
||||
},
|
||||
"scrutiny": {
|
||||
"passed": "Passed",
|
||||
"failed": "Failed",
|
||||
"unknown": "Unknown"
|
||||
},
|
||||
"paperlessngx": {
|
||||
"inbox": "Inbox",
|
||||
"total": "Totalo"
|
||||
},
|
||||
"diskstation": {
|
||||
"download": "Download",
|
||||
"leech": "Leech",
|
||||
"upload": "Upload",
|
||||
"seed": "Seed"
|
||||
},
|
||||
"flood": {
|
||||
"download": "Download",
|
||||
"upload": "Upload",
|
||||
"leech": "Leech",
|
||||
"seed": "Seed"
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
import { useTranslation } from "react-i18next";
|
||||
import useSWR from "swr";
|
||||
|
||||
export default function Ping({ service }) {
|
||||
const { t } = useTranslation();
|
||||
const { data, error } = useSWR(`/api/ping?${new URLSearchParams({ping: service.ping}).toString()}`, {
|
||||
refreshInterval: 30000
|
||||
});
|
||||
|
||||
if (error) {
|
||||
return (
|
||||
<div className="w-auto px-1.5 py-0.5 text-center bg-theme-500/10 dark:bg-theme-900/50 rounded-b-[3px] overflow-hidden">
|
||||
<div className="text-[8px] font-bold text-rose-500 uppercase">{t("ping.error")}</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (!data) {
|
||||
return (
|
||||
<div className="w-auto px-1.5 py-0.5 text-center bg-theme-500/10 dark:bg-theme-900/50 rounded-b-[3px] overflow-hidden">
|
||||
<div className="text-[8px] font-bold text-black/20 dark:text-white/40 uppercase">{t("ping.ping")}</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const statusText = `${service.ping}: HTTP status ${data.status}`;
|
||||
|
||||
if (data && data.status !== 200) {
|
||||
return (
|
||||
<div className="w-auto px-1.5 py-0.5 text-center bg-theme-500/10 dark:bg-theme-900/50 rounded-b-[3px] overflow-hidden" title={statusText}>
|
||||
<div className="text-[8px] font-bold text-rose-500/80">{data.status}</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (data && data.status === 200) {
|
||||
return (
|
||||
<div className="w-auto px-1.5 py-0.5 text-center bg-theme-500/10 dark:bg-theme-900/50 rounded-b-[3px] overflow-hidden" title={statusText}>
|
||||
<div className="text-[8px] font-bold text-emerald-500/80">{t("common.ms", { value: data.latency, style: "unit", unit: "millisecond", unitDisplay: "narrow", maximumFractionDigits: 0 })}</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -1,19 +1,52 @@
|
||||
import { useTranslation } from "react-i18next";
|
||||
import useSWR from "swr";
|
||||
|
||||
export default function Status({ service }) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const { data, error } = useSWR(`/api/docker/status/${service.container}/${service.server || ""}`);
|
||||
|
||||
if (error) {
|
||||
return <div className="w-3 h-3 bg-rose-300 dark:bg-rose-500 rounded-full" />;
|
||||
<div className="w-auto px-1.5 py-0.5 text-center bg-theme-500/10 dark:bg-theme-900/50 rounded-b-[3px] overflow-hidden" title={data.status}>
|
||||
<div className="text-[8px] font-bold text-rose-500/80 uppercase">{t("docker.error")}</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
if (data && data.status === "running") {
|
||||
return <div className="w-3 h-3 bg-emerald-300 dark:bg-emerald-500 rounded-full" />;
|
||||
if (data.health === "starting") {
|
||||
return (
|
||||
<div className="w-auto px-1.5 py-0.5 text-center bg-theme-500/10 dark:bg-theme-900/50 rounded-b-[3px] overflow-hidden" title={data.health}>
|
||||
<div className="text-[8px] font-bold text-blue-500/80 uppercase">{data.health}</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (data.health === "unhealthy") {
|
||||
return (
|
||||
<div className="w-auto px-1.5 py-0.5 text-center bg-theme-500/10 dark:bg-theme-900/50 rounded-b-[3px] overflow-hidden" title={data.health}>
|
||||
<div className="text-[8px] font-bold text-orange-400/50 dark:text-orange-400/80 uppercase">{data.health}</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="w-auto px-1.5 py-0.5 text-center bg-theme-500/10 dark:bg-theme-900/50 rounded-b-[3px] overflow-hidden" title={data.health ?? data.status}>
|
||||
<div className="text-[8px] font-bold text-emerald-500/80 uppercase">{data.health ?? data.status}</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (data && data.status === "not found") {
|
||||
return <div className="h-2.5 w-2.5 bg-orange-400/50 dark:bg-yellow-200/40 -rotate-45" />;
|
||||
if (data && (data.status === "not found" || data.status === "exited")) {
|
||||
return (
|
||||
<div className="w-auto px-1.5 py-0.5 text-center bg-theme-500/10 dark:bg-theme-900/50 rounded-b-[3px] overflow-hidden" title={data.status}>
|
||||
<div className="text-[8px] font-bold text-orange-400/50 dark:text-orange-400/80 uppercase">{data.status}</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return <div className="w-3 h-3 bg-black/20 dark:bg-white/40 rounded-full" />;
|
||||
return (
|
||||
<div className="w-auto px-1.5 py-0.5 text-center bg-theme-500/10 dark:bg-theme-900/50 rounded-b-[3px] overflow-hidden">
|
||||
<div className="text-[8px] font-bold text-black/20 dark:text-white/40 uppercase">{t("docker.unknown")}</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
@ -0,0 +1,35 @@
|
||||
import { performance } from "perf_hooks";
|
||||
|
||||
import createLogger from "utils/logger";
|
||||
import { httpProxy } from "utils/proxy/http";
|
||||
|
||||
const logger = createLogger("ping");
|
||||
|
||||
export default async function handler(req, res) {
|
||||
const { ping: pingURL } = req.query;
|
||||
|
||||
if (!pingURL) {
|
||||
logger.debug("No ping URL specified");
|
||||
return res.status(400).send({
|
||||
error: "No ping URL given",
|
||||
});
|
||||
}
|
||||
|
||||
let startTime = performance.now();
|
||||
let [status] = await httpProxy(pingURL, {
|
||||
method: "HEAD"
|
||||
});
|
||||
let endTime = performance.now();
|
||||
|
||||
if (status >= 400) {
|
||||
// try one more time as a GET in case HEAD is rejected for whatever reason
|
||||
startTime = performance.now();
|
||||
[status] = await httpProxy(pingURL);
|
||||
endTime = performance.now();
|
||||
}
|
||||
|
||||
return res.status(200).json({
|
||||
status,
|
||||
latency: endTime - startTime
|
||||
});
|
||||
}
|
@ -1,8 +1,9 @@
|
||||
import cachedFetch from "utils/proxy/cached-fetch";
|
||||
|
||||
export default async function handler(req, res) {
|
||||
const { latitude, longitude, units, cache } = req.query;
|
||||
const { latitude, longitude, units, cache, timezone } = req.query;
|
||||
const degrees = units === "imperial" ? "fahrenheit" : "celsius";
|
||||
const apiUrl = `https://api.open-meteo.com/v1/forecast?latitude=${latitude}&longitude=${longitude}&daily=sunrise,sunset¤t_weather=true&temperature_unit=${degrees}&timezone=auto`;
|
||||
const timezeone = timezone ?? 'auto'
|
||||
const apiUrl = `https://api.open-meteo.com/v1/forecast?latitude=${latitude}&longitude=${longitude}&daily=sunrise,sunset¤t_weather=true&temperature_unit=${degrees}&timezone=${timezeone}`;
|
||||
return res.send(await cachedFetch(apiUrl, cache));
|
||||
}
|
@ -0,0 +1,82 @@
|
||||
import { JSONRPCClient, JSONRPCErrorException } from "json-rpc-2.0";
|
||||
|
||||
import { formatApiCall } from "utils/proxy/api-helpers";
|
||||
import { httpProxy } from "utils/proxy/http";
|
||||
import getServiceWidget from "utils/config/service-helpers";
|
||||
import createLogger from "utils/logger";
|
||||
import widgets from "widgets/widgets";
|
||||
|
||||
const logger = createLogger("jsonrpcProxyHandler");
|
||||
|
||||
export async function sendJsonRpcRequest(url, method, params, username, password) {
|
||||
const headers = {
|
||||
"content-type": "application/json",
|
||||
"accept": "application/json"
|
||||
}
|
||||
|
||||
if (username && password) {
|
||||
headers.authorization = `Basic ${Buffer.from(`${username}:${password}`).toString("base64")}`;
|
||||
}
|
||||
|
||||
const client = new JSONRPCClient(async (rpcRequest) => {
|
||||
const body = JSON.stringify(rpcRequest);
|
||||
const httpRequestParams = {
|
||||
method: "POST",
|
||||
headers,
|
||||
body
|
||||
};
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
const [status, contentType, data] = await httpProxy(url, httpRequestParams);
|
||||
if (status === 200) {
|
||||
const json = JSON.parse(data.toString());
|
||||
|
||||
// in order to get access to the underlying error object in the JSON response
|
||||
// you must set `result` equal to undefined
|
||||
if (json.error && (json.result === null)) {
|
||||
json.result = undefined;
|
||||
}
|
||||
return client.receive(json);
|
||||
}
|
||||
|
||||
return Promise.reject(data?.error ? data : new Error(data.toString()));
|
||||
});
|
||||
|
||||
try {
|
||||
const response = await client.request(method, params);
|
||||
return [200, "application/json", JSON.stringify(response)];
|
||||
}
|
||||
catch (e) {
|
||||
if (e instanceof JSONRPCErrorException) {
|
||||
logger.debug("Error calling JSONPRC endpoint: %s. %s", url, e.message);
|
||||
return [200, "application/json", JSON.stringify({result: null, error: {code: e.code, message: e.message}})];
|
||||
}
|
||||
|
||||
logger.warn("Error calling JSONPRC endpoint: %s. %s", url, e);
|
||||
return [500, "application/json", JSON.stringify({result: null, error: {code: 2, message: e.toString()}})];
|
||||
}
|
||||
}
|
||||
|
||||
export default async function jsonrpcProxyHandler(req, res) {
|
||||
const { group, service, endpoint: method } = req.query;
|
||||
|
||||
if (group && service) {
|
||||
const widget = await getServiceWidget(group, service);
|
||||
const api = widgets?.[widget.type]?.api;
|
||||
|
||||
if (!api) {
|
||||
return res.status(403).json({ error: "Service does not support API calls" });
|
||||
}
|
||||
|
||||
if (widget) {
|
||||
const url = formatApiCall(api, { ...widget });
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
const [status, contentType, data] = await sendJsonRpcRequest(url, method, null, widget.username, widget.password);
|
||||
return res.status(status).end(data);
|
||||
}
|
||||
}
|
||||
|
||||
logger.debug("Invalid or missing proxy service type '%s' in group '%s'", service, group);
|
||||
return res.status(400).json({ error: "Invalid proxy service type" });
|
||||
}
|
@ -0,0 +1,211 @@
|
||||
import * as Icons from "react-icons/wi";
|
||||
|
||||
// see https://open-meteo.com/en/docs
|
||||
|
||||
const conditions = [
|
||||
{
|
||||
code: 1,
|
||||
icon: {
|
||||
day: Icons.WiDayCloudy,
|
||||
night: Icons.WiNightAltCloudy,
|
||||
},
|
||||
},
|
||||
{
|
||||
code: 2,
|
||||
icon: {
|
||||
day: Icons.WiDayCloudy,
|
||||
night: Icons.WiNightAltCloudy,
|
||||
},
|
||||
},
|
||||
{
|
||||
code: 3,
|
||||
icon: {
|
||||
day: Icons.WiDayCloudy,
|
||||
night: Icons.WiNightAltCloudy,
|
||||
},
|
||||
},
|
||||
{
|
||||
code: 45,
|
||||
icon: {
|
||||
day: Icons.WiDayFog,
|
||||
night: Icons.WiNightFog,
|
||||
},
|
||||
},
|
||||
{
|
||||
code: 48,
|
||||
icon: {
|
||||
day: Icons.WiDayFog,
|
||||
night: Icons.WiNightFog,
|
||||
},
|
||||
},
|
||||
{
|
||||
code: 51,
|
||||
icon: {
|
||||
day: Icons.WiDaySprinkle,
|
||||
night: Icons.WiNightAltSprinkle,
|
||||
},
|
||||
},
|
||||
{
|
||||
code: 53,
|
||||
icon: {
|
||||
day: Icons.WiDaySprinkle,
|
||||
night: Icons.WiNightAltSprinkle,
|
||||
},
|
||||
},
|
||||
{
|
||||
code: 55,
|
||||
icon: {
|
||||
day: Icons.WiDaySprinkle,
|
||||
night: Icons.WiNightAltSprinkle,
|
||||
},
|
||||
},
|
||||
{
|
||||
code: 56,
|
||||
icon: {
|
||||
day: Icons.WiDaySleet,
|
||||
night: Icons.WiNightAltSleet,
|
||||
},
|
||||
},
|
||||
{
|
||||
code: 57,
|
||||
icon: {
|
||||
day: Icons.WiDaySleet,
|
||||
night: Icons.WiNightAltSleet,
|
||||
},
|
||||
},
|
||||
{
|
||||
code: 61,
|
||||
icon: {
|
||||
day: Icons.WiDayShowers,
|
||||
night: Icons.WiNightAltShowers,
|
||||
},
|
||||
},
|
||||
{
|
||||
code: 63,
|
||||
icon: {
|
||||
day: Icons.WiDayShowers,
|
||||
night: Icons.WiNightAltShowers,
|
||||
},
|
||||
},
|
||||
{
|
||||
code: 65,
|
||||
icon: {
|
||||
day: Icons.WiDayShowers,
|
||||
night: Icons.WiNightAltShowers,
|
||||
},
|
||||
},
|
||||
{
|
||||
code: 66,
|
||||
icon: {
|
||||
day: Icons.WiDaySleet,
|
||||
night: Icons.WiNightAltSleet,
|
||||
},
|
||||
},
|
||||
{
|
||||
code: 67,
|
||||
icon: {
|
||||
day: Icons.WiDaySleet,
|
||||
night: Icons.WiNightAltSleet,
|
||||
},
|
||||
},
|
||||
{
|
||||
code: 71,
|
||||
icon: {
|
||||
day: Icons.WiDaySnow,
|
||||
night: Icons.WiNightAltSnow,
|
||||
},
|
||||
},
|
||||
{
|
||||
code: 73,
|
||||
icon: {
|
||||
day: Icons.WiDaySnow,
|
||||
night: Icons.WiNightAltSnow,
|
||||
},
|
||||
},
|
||||
{
|
||||
code: 75,
|
||||
icon: {
|
||||
day: Icons.WiDaySnow,
|
||||
night: Icons.WiNightAltSnow,
|
||||
},
|
||||
},
|
||||
{
|
||||
code: 77,
|
||||
icon: {
|
||||
day: Icons.WiDaySnow,
|
||||
night: Icons.WiNightAltSnow,
|
||||
},
|
||||
},
|
||||
{
|
||||
code: 80,
|
||||
icon: {
|
||||
day: Icons.WiDaySnow,
|
||||
night: Icons.WiNightAltSnow,
|
||||
},
|
||||
},
|
||||
{
|
||||
code: 81,
|
||||
icon: {
|
||||
day: Icons.WiDaySnow,
|
||||
night: Icons.WiNightAltSnow,
|
||||
},
|
||||
},
|
||||
{
|
||||
code: 82,
|
||||
icon: {
|
||||
day: Icons.WiDaySnow,
|
||||
night: Icons.WiNightAltSnow,
|
||||
},
|
||||
},
|
||||
{
|
||||
code: 85,
|
||||
icon: {
|
||||
day: Icons.WiDaySnow,
|
||||
night: Icons.WiNightAltSnow,
|
||||
},
|
||||
},
|
||||
{
|
||||
code: 86,
|
||||
icon: {
|
||||
day: Icons.WiDaySnow,
|
||||
night: Icons.WiNightAltSnow,
|
||||
},
|
||||
},
|
||||
{
|
||||
code: 95,
|
||||
icon: {
|
||||
day: Icons.WiDayThunderstorm,
|
||||
night: Icons.WiNightAltThunderstorm,
|
||||
},
|
||||
},
|
||||
{
|
||||
code: 96,
|
||||
icon: {
|
||||
day: Icons.WiDayThunderstorm,
|
||||
night: Icons.WiNightAltThunderstorm,
|
||||
},
|
||||
},
|
||||
{
|
||||
code: 99,
|
||||
icon: {
|
||||
day: Icons.WiDayThunderstorm,
|
||||
night: Icons.WiNightAltThunderstorm,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
export default function mapIcon(weatherStatusCode, timeOfDay) {
|
||||
const mapping = conditions.find((condition) => condition.code === weatherStatusCode);
|
||||
|
||||
if (mapping) {
|
||||
if (timeOfDay === "day") {
|
||||
return mapping.icon.day;
|
||||
}
|
||||
|
||||
if (timeOfDay === "night") {
|
||||
return mapping.icon.night;
|
||||
}
|
||||
}
|
||||
|
||||
return Icons.WiDaySunny;
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
import { useTranslation } from "next-i18next";
|
||||
|
||||
import Container from "components/services/widget/container";
|
||||
import Block from "components/services/widget/block";
|
||||
import useWidgetAPI from "utils/proxy/use-widget-api";
|
||||
|
||||
export default function Component({ service }) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const { widget } = service;
|
||||
|
||||
const { data: torrentData, error: torrentError } = useWidgetAPI(widget);
|
||||
|
||||
if (torrentError) {
|
||||
return <Container error={torrentError} />;
|
||||
}
|
||||
|
||||
if (!torrentData) {
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="deluge.leech" />
|
||||
<Block label="deluge.download" />
|
||||
<Block label="deluge.seed" />
|
||||
<Block label="deluge.upload" />
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
|
||||
const { torrents } = torrentData;
|
||||
const keys = torrents ? Object.keys(torrents) : [];
|
||||
|
||||
let rateDl = 0;
|
||||
let rateUl = 0;
|
||||
let completed = 0;
|
||||
for (let i = 0; i < keys.length; i += 1) {
|
||||
const torrent = torrents[keys[i]];
|
||||
rateDl += torrent.download_payload_rate;
|
||||
rateUl += torrent.upload_payload_rate;
|
||||
completed += torrent.total_remaining === 0 ? 1 : 0;
|
||||
}
|
||||
|
||||
const leech = keys.length - completed || 0;
|
||||
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="deluge.leech" value={t("common.number", { value: leech })} />
|
||||
<Block label="deluge.download" value={t("common.bitrate", { value: rateDl })} />
|
||||
<Block label="deluge.seed" value={t("common.number", { value: completed })} />
|
||||
<Block label="deluge.upload" value={t("common.bitrate", { value: rateUl })} />
|
||||
</Container>
|
||||
);
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
import { formatApiCall } from "utils/proxy/api-helpers";
|
||||
import { sendJsonRpcRequest } from "utils/proxy/handlers/jsonrpc";
|
||||
import getServiceWidget from "utils/config/service-helpers";
|
||||
import createLogger from "utils/logger";
|
||||
import widgets from "widgets/widgets";
|
||||
|
||||
const logger = createLogger("delugeProxyHandler");
|
||||
|
||||
const dataMethod = "web.update_ui";
|
||||
const dataParams = [
|
||||
["queue", "name", "total_wanted", "state", "progress", "download_payload_rate", "upload_payload_rate", "total_remaining"],
|
||||
{}
|
||||
];
|
||||
const loginMethod = "auth.login";
|
||||
|
||||
async function sendRpc(url, method, params) {
|
||||
const [status, contentType, data] = await sendJsonRpcRequest(url, method, params);
|
||||
const json = JSON.parse(data.toString());
|
||||
if (json?.error) {
|
||||
if (json.error.code === 1) {
|
||||
return [403, contentType, data];
|
||||
}
|
||||
return [500, contentType, data];
|
||||
}
|
||||
|
||||
return [status, contentType, data];
|
||||
}
|
||||
|
||||
function login(url, password) {
|
||||
return sendRpc(url, loginMethod, [password]);
|
||||
}
|
||||
|
||||
export default async function delugeProxyHandler(req, res) {
|
||||
const { group, service } = req.query;
|
||||
|
||||
if (!group || !service) {
|
||||
logger.debug("Invalid or missing service '%s' or group '%s'", service, group);
|
||||
return res.status(400).json({ error: "Invalid proxy service type" });
|
||||
}
|
||||
|
||||
const widget = await getServiceWidget(group, service);
|
||||
|
||||
if (!widget) {
|
||||
logger.debug("Invalid or missing widget for service '%s' in group '%s'", service, group);
|
||||
return res.status(400).json({ error: "Invalid proxy service type" });
|
||||
}
|
||||
|
||||
const api = widgets?.[widget.type]?.api
|
||||
const url = new URL(formatApiCall(api, { ...widget }));
|
||||
|
||||
let [status, contentType, data] = await sendRpc(url, dataMethod, dataParams);
|
||||
if (status === 403) {
|
||||
[status, contentType, data] = await login(url, widget.password);
|
||||
if (status !== 200) {
|
||||
return res.status(status).end(data);
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
[status, contentType, data] = await sendRpc(url, dataMethod, dataParams);
|
||||
}
|
||||
|
||||
return res.status(status).end(data);
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
import delugeProxyHandler from "./proxy";
|
||||
|
||||
const widget = {
|
||||
api: "{url}/json",
|
||||
proxyHandler: delugeProxyHandler,
|
||||
};
|
||||
|
||||
export default widget;
|
@ -0,0 +1,41 @@
|
||||
import { useTranslation } from "next-i18next";
|
||||
|
||||
import Container from "components/services/widget/container";
|
||||
import Block from "components/services/widget/block";
|
||||
import useWidgetAPI from "utils/proxy/use-widget-api";
|
||||
|
||||
export default function Component({ service }) {
|
||||
const { t } = useTranslation();
|
||||
const { widget } = service;
|
||||
const { data: listData, error: listError } = useWidgetAPI(widget, "list");
|
||||
|
||||
if (listError) {
|
||||
return <Container error={listError} />;
|
||||
}
|
||||
|
||||
const tasks = listData?.data?.tasks;
|
||||
if (!tasks) {
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="diskstation.leech" />
|
||||
<Block label="diskstation.download" />
|
||||
<Block label="diskstation.seed" />
|
||||
<Block label="diskstation.upload" />
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
|
||||
const rateDl = tasks.reduce((acc, task) => acc + (task?.additional?.transfer?.speed_download ?? 0), 0);
|
||||
const rateUl = tasks.reduce((acc, task) => acc + (task?.additional?.transfer?.speed_upload ?? 0), 0);
|
||||
const completed = tasks.filter((task) => task?.additional?.transfer?.size_downloaded === task?.size)?.length || 0;
|
||||
const leech = tasks.length - completed || 0;
|
||||
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="diskstation.leech" value={t("common.number", { value: leech })} />
|
||||
<Block label="diskstation.download" value={t("common.bitrate", { value: rateDl })} />
|
||||
<Block label="diskstation.seed" value={t("common.number", { value: completed })} />
|
||||
<Block label="diskstation.upload" value={t("common.bitrate", { value: rateUl })} />
|
||||
</Container>
|
||||
);
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
import { formatApiCall } from "utils/proxy/api-helpers";
|
||||
import { httpProxy } from "utils/proxy/http";
|
||||
import createLogger from "utils/logger";
|
||||
import widgets from "widgets/widgets";
|
||||
import getServiceWidget from "utils/config/service-helpers";
|
||||
|
||||
const logger = createLogger("diskstationProxyHandler");
|
||||
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);
|
||||
const [status, contentType, data] = await httpProxy(loginUrl);
|
||||
if (status !== 200) {
|
||||
return [status, contentType, data];
|
||||
}
|
||||
|
||||
const json = JSON.parse(data.toString());
|
||||
if (json?.success !== true) {
|
||||
// from https://global.download.synology.com/download/Document/Software/DeveloperGuide/Package/DownloadStation/All/enu/Synology_Download_Station_Web_API.pdf
|
||||
/*
|
||||
Code Description
|
||||
400 No such account or incorrect password
|
||||
401 Account disabled
|
||||
402 Permission denied
|
||||
403 2-step verification code required
|
||||
404 Failed to authenticate 2-step verification code
|
||||
*/
|
||||
let message = "Authentication failed.";
|
||||
if (json?.error?.code >= 403) message += " 2FA enabled.";
|
||||
logger.warn("Unable to login. Code: %d", json?.error?.code);
|
||||
return [401, "application/json", JSON.stringify({ code: json?.error?.code, message })];
|
||||
}
|
||||
|
||||
return [status, contentType, data];
|
||||
}
|
||||
|
||||
export default async function diskstationProxyHandler(req, res) {
|
||||
const { group, service, endpoint } = req.query;
|
||||
|
||||
if (!group || !service) {
|
||||
return res.status(400).json({ error: "Invalid proxy service type" });
|
||||
}
|
||||
|
||||
const widget = await getServiceWidget(group, service);
|
||||
const api = widgets?.[widget.type]?.api;
|
||||
if (!api) {
|
||||
return res.status(403).json({ error: "Service does not support API calls" });
|
||||
}
|
||||
|
||||
const url = formatApiCall(api, { endpoint, ...widget });
|
||||
let [status, contentType, data] = await httpProxy(url);
|
||||
if (status !== 200) {
|
||||
logger.debug("Error %d calling endpoint %s", status, url);
|
||||
return res.status(status, data);
|
||||
}
|
||||
|
||||
const json = JSON.parse(data.toString());
|
||||
if (json?.success !== true) {
|
||||
logger.debug("Logging in to DiskStation");
|
||||
[status, contentType, data] = await login(widget);
|
||||
if (status !== 200) {
|
||||
return res.status(status).end(data)
|
||||
}
|
||||
|
||||
[status, contentType, data] = await httpProxy(url);
|
||||
}
|
||||
|
||||
if (contentType) res.setHeader("Content-Type", contentType);
|
||||
return res.status(status).send(data);
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
import diskstationProxyHandler from "./proxy";
|
||||
|
||||
const widget = {
|
||||
api: "{url}/webapi/DownloadStation/task.cgi?api=SYNO.DownloadStation.Task&version=1&method={endpoint}",
|
||||
proxyHandler: diskstationProxyHandler,
|
||||
|
||||
mappings: {
|
||||
"list": {
|
||||
endpoint: "list&additional=transfer",
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export default widget;
|
@ -0,0 +1,53 @@
|
||||
import { useTranslation } from "next-i18next";
|
||||
|
||||
import Container from "components/services/widget/container";
|
||||
import Block from "components/services/widget/block";
|
||||
import useWidgetAPI from "utils/proxy/use-widget-api";
|
||||
|
||||
export default function Component({ service }) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const { widget } = service;
|
||||
|
||||
const { data: torrentData, error: torrentError } = useWidgetAPI(widget, "torrents");
|
||||
|
||||
if (torrentError || !torrentData?.torrents) {
|
||||
return <Container error={torrentError ?? {message: "No torrent data returned"}} />;
|
||||
}
|
||||
|
||||
if (!torrentData || !torrentData.torrents) {
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="flood.leech" />
|
||||
<Block label="flood.download" />
|
||||
<Block label="flood.seed" />
|
||||
<Block label="flood.upload" />
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
|
||||
let rateDl = 0;
|
||||
let rateUl = 0;
|
||||
let completed = 0;
|
||||
let leech = 0;
|
||||
|
||||
Object.values(torrentData.torrents).forEach(torrent => {
|
||||
rateDl += torrent.downRate;
|
||||
rateUl += torrent.upRate;
|
||||
if(torrent.status.includes('complete')){
|
||||
completed += 1;
|
||||
}
|
||||
if(torrent.status.includes('downloading')){
|
||||
leech += 1;
|
||||
}
|
||||
})
|
||||
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="flood.leech" value={t("common.number", { value: leech })} />
|
||||
<Block label="flood.download" value={t("common.bitrate", { value: rateDl })} />
|
||||
<Block label="flood.seed" value={t("common.number", { value: completed })} />
|
||||
<Block label="flood.upload" value={t("common.bitrate", { value: rateUl })} />
|
||||
</Container>
|
||||
);
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
import { formatApiCall } from "utils/proxy/api-helpers";
|
||||
import { httpProxy } from "utils/proxy/http";
|
||||
import getServiceWidget from "utils/config/service-helpers";
|
||||
import createLogger from "utils/logger";
|
||||
|
||||
const logger = createLogger("floodProxyHandler");
|
||||
|
||||
async function login(widget) {
|
||||
logger.debug("flood is rejecting the request, logging in.");
|
||||
const loginUrl = new URL(`${widget.url}/api/auth/authenticate`).toString();
|
||||
|
||||
const loginParams = {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: null
|
||||
};
|
||||
|
||||
if (widget.username && widget.password) {
|
||||
loginParams.body = JSON.stringify({
|
||||
"username": widget.username,
|
||||
"password": widget.password
|
||||
});
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
const [status, contentType, data] = await httpProxy(loginUrl, loginParams);
|
||||
return [status, data];
|
||||
}
|
||||
|
||||
export default async function floodProxyHandler(req, res) {
|
||||
const { group, service, endpoint } = req.query;
|
||||
|
||||
if (!group || !service) {
|
||||
logger.debug("Invalid or missing service '%s' or group '%s'", service, group);
|
||||
return res.status(400).json({ error: "Invalid proxy service type" });
|
||||
}
|
||||
|
||||
const widget = await getServiceWidget(group, service);
|
||||
|
||||
if (!widget) {
|
||||
logger.debug("Invalid or missing widget for service '%s' in group '%s'", service, group);
|
||||
return res.status(400).json({ error: "Invalid proxy service type" });
|
||||
}
|
||||
|
||||
const url = new URL(formatApiCall("{url}/api/{endpoint}", { endpoint, ...widget }));
|
||||
const params = { method: "GET", headers: {} };
|
||||
|
||||
let [status, contentType, data] = await httpProxy(url, params);
|
||||
if (status === 401) {
|
||||
[status, data] = await login(widget);
|
||||
|
||||
if (status !== 200) {
|
||||
logger.error("HTTP %d logging in to flood. Data: %s", status, data);
|
||||
return res.status(status).end(data);
|
||||
}
|
||||
|
||||
[status, contentType, data] = await httpProxy(url, params);
|
||||
}
|
||||
|
||||
if (status !== 200) {
|
||||
logger.error("HTTP %d getting data from flood. Data: %s", status, data);
|
||||
}
|
||||
|
||||
if (contentType) res.setHeader("Content-Type", contentType);
|
||||
return res.status(status).send(data);
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
import floodProxyHandler from "./proxy";
|
||||
|
||||
const widget = {
|
||||
proxyHandler: floodProxyHandler,
|
||||
};
|
||||
|
||||
export default widget;
|
@ -1,40 +0,0 @@
|
||||
import { JSONRPCClient } from "json-rpc-2.0";
|
||||
|
||||
import getServiceWidget from "utils/config/service-helpers";
|
||||
|
||||
export default async function nzbgetProxyHandler(req, res) {
|
||||
const { group, service, endpoint } = req.query;
|
||||
|
||||
if (group && service) {
|
||||
const widget = await getServiceWidget(group, service);
|
||||
|
||||
if (widget) {
|
||||
const constructedUrl = new URL(widget.url);
|
||||
constructedUrl.pathname = "jsonrpc";
|
||||
|
||||
const authorization = Buffer.from(`${widget.username}:${widget.password}`).toString("base64");
|
||||
|
||||
const client = new JSONRPCClient((jsonRPCRequest) =>
|
||||
fetch(constructedUrl.toString(), {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"content-type": "application/json",
|
||||
authorization: `Basic ${authorization}`,
|
||||
},
|
||||
body: JSON.stringify(jsonRPCRequest),
|
||||
}).then(async (response) => {
|
||||
if (response.status === 200) {
|
||||
const jsonRPCResponse = await response.json();
|
||||
return client.receive(jsonRPCResponse);
|
||||
}
|
||||
|
||||
return Promise.reject(new Error(response.statusText));
|
||||
})
|
||||
);
|
||||
|
||||
return res.send(await client.request(endpoint));
|
||||
}
|
||||
}
|
||||
|
||||
return res.status(400).json({ error: "Invalid proxy service type" });
|
||||
}
|
@ -1,7 +1,8 @@
|
||||
import nzbgetProxyHandler from "./proxy";
|
||||
import jsonrpcProxyHandler from "utils/proxy/handlers/jsonrpc";
|
||||
|
||||
const widget = {
|
||||
proxyHandler: nzbgetProxyHandler,
|
||||
api: "{url}/jsonrpc",
|
||||
proxyHandler: jsonrpcProxyHandler,
|
||||
};
|
||||
|
||||
export default widget;
|
||||
|
@ -0,0 +1,29 @@
|
||||
import Container from "components/services/widget/container";
|
||||
import Block from "components/services/widget/block";
|
||||
import useWidgetAPI from "utils/proxy/use-widget-api";
|
||||
|
||||
export default function Component({ service }) {
|
||||
const { widget } = service;
|
||||
|
||||
const { data: statisticsData, error: statisticsError } = useWidgetAPI(widget, "statistics");
|
||||
|
||||
if (statisticsError) {
|
||||
return <Container error={statisticsError} />;
|
||||
}
|
||||
|
||||
if (!statisticsData) {
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="paperlessngx.inbox" />
|
||||
<Block label="paperlessngx.total" />
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Container service={service}>
|
||||
{statisticsData.documents_inbox !== undefined && <Block label="paperlessngx.inbox" value={statisticsData.documents_inbox} />}
|
||||
<Block label="paperlessngx.total" value={statisticsData.documents_total} />
|
||||
</Container>
|
||||
);
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
import genericProxyHandler from "utils/proxy/handlers/generic";
|
||||
|
||||
const widget = {
|
||||
api: "{url}/api/{endpoint}",
|
||||
proxyHandler: genericProxyHandler,
|
||||
|
||||
mappings: {
|
||||
"statistics": {
|
||||
endpoint: "statistics/?format=json",
|
||||
validate: [
|
||||
"documents_total"
|
||||
]
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export default widget;
|
@ -0,0 +1,62 @@
|
||||
import Container from "components/services/widget/container";
|
||||
import Block from "components/services/widget/block";
|
||||
import useWidgetAPI from "utils/proxy/use-widget-api";
|
||||
|
||||
|
||||
// @see https://github.com/AnalogJ/scrutiny/blob/d8d56f77f9e868127c4849dac74d65512db658e8/webapp/frontend/src/app/shared/device-status.pipe.ts
|
||||
const DeviceStatus = {
|
||||
passed: 0,
|
||||
failed_smart: 1,
|
||||
failed_scrutiny: 2,
|
||||
failed_both: 3,
|
||||
|
||||
isFailed(s){ return s > this.passed && s <= this.failed_both},
|
||||
isUnknown(s){ return s < this.passed || s > this.failed_both}
|
||||
}
|
||||
|
||||
// @see https://github.com/AnalogJ/scrutiny/blob/d8d56f77f9e868127c4849dac74d65512db658e8/webapp/frontend/src/app/core/config/app.config.ts
|
||||
const DeviceStatusThreshold = {
|
||||
smart: 1,
|
||||
scrutiny: 2,
|
||||
both: 3
|
||||
}
|
||||
|
||||
export default function Component({ service }) {
|
||||
const { widget } = service;
|
||||
|
||||
const { data: scrutinySettings, error: scrutinySettingsError } = useWidgetAPI(widget, "settings");
|
||||
const { data: scrutinyData, error: scrutinyError } = useWidgetAPI(widget, "summary");
|
||||
|
||||
if (scrutinyError || scrutinySettingsError) {
|
||||
const finalError = scrutinyError ?? scrutinySettingsError;
|
||||
return <Container error={finalError} />;
|
||||
}
|
||||
|
||||
if (!scrutinyData || !scrutinySettings) {
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="scrutiny.passed" />
|
||||
<Block label="scrutiny.failed" />
|
||||
<Block label="scrutiny.unknown" />
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
|
||||
const deviceIds = Object.values(scrutinyData.data.summary);
|
||||
const statusThreshold = scrutinySettings.settings.metrics.status_threshold;
|
||||
|
||||
const failed = deviceIds.filter(deviceId => (DeviceStatus.isFailed(deviceId.device.device_status) && statusThreshold === DeviceStatusThreshold.both) || [statusThreshold, DeviceStatus.failed_both].includes(deviceId.device.device_status))?.length || 0;
|
||||
const unknown = deviceIds.filter(deviceId => DeviceStatus.isUnknown(deviceId.device.device_status))?.length || 0;
|
||||
const passed = deviceIds.length - (failed + unknown);
|
||||
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="scrutiny.passed" value={passed} />
|
||||
<Block label="scrutiny.failed" value={failed} />
|
||||
<Block label="scrutiny.unknown" value={unknown} />
|
||||
</Container>
|
||||
|
||||
);
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,23 @@
|
||||
import genericProxyHandler from "utils/proxy/handlers/generic";
|
||||
|
||||
const widget = {
|
||||
api: "{url}/api/{endpoint}",
|
||||
proxyHandler: genericProxyHandler,
|
||||
|
||||
mappings: {
|
||||
summary: {
|
||||
endpoint: "summary",
|
||||
validate: [
|
||||
"data",
|
||||
]
|
||||
},
|
||||
settings: {
|
||||
endpoint: "settings",
|
||||
validate: [
|
||||
"settings",
|
||||
]
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export default widget;
|
Loading…
Reference in new issue