mirror of
https://github.com/DI0IK/homepage-plus.git
synced 2025-07-09 14:58:47 +00:00
starting of widget refactoring
This commit is contained in:
parent
d6f6ea9dba
commit
562235f828
42 changed files with 337 additions and 301 deletions
|
@ -1,44 +1,44 @@
|
|||
const formats = {
|
||||
emby: `{url}/emby/{endpoint}?api_key={key}`,
|
||||
jellyfin: `{url}/emby/{endpoint}?api_key={key}`,
|
||||
pihole: `{url}/admin/{endpoint}`,
|
||||
radarr: `{url}/api/v3/{endpoint}?apikey={key}`,
|
||||
sonarr: `{url}/api/v3/{endpoint}?apikey={key}`,
|
||||
speedtest: `{url}/api/{endpoint}`,
|
||||
tautulli: `{url}/api/v2?apikey={key}&cmd={endpoint}`,
|
||||
traefik: `{url}/api/{endpoint}`,
|
||||
portainer: `{url}/api/endpoints/{env}/{endpoint}`,
|
||||
rutorrent: `{url}/plugins/httprpc/action.php`,
|
||||
transmission: `{url}/transmission/rpc`,
|
||||
qbittorrent: `{url}/api/v2/{endpoint}`,
|
||||
jellyseerr: `{url}/api/v1/{endpoint}`,
|
||||
overseerr: `{url}/api/v1/{endpoint}`,
|
||||
ombi: `{url}/api/v1/{endpoint}`,
|
||||
npm: `{url}/api/{endpoint}`,
|
||||
lidarr: `{url}/api/v1/{endpoint}?apikey={key}`,
|
||||
readarr: `{url}/api/v1/{endpoint}?apikey={key}`,
|
||||
bazarr: `{url}/api/{endpoint}/wanted?apikey={key}`,
|
||||
sabnzbd: `{url}/api/?apikey={key}&output=json&mode={endpoint}`,
|
||||
coinmarketcap: `https://pro-api.coinmarketcap.com/{endpoint}`,
|
||||
gotify: `{url}/{endpoint}`,
|
||||
prowlarr: `{url}/api/v1/{endpoint}`,
|
||||
jackett: `{url}/api/v2.0/{endpoint}?apikey={key}&configured=true`,
|
||||
adguard: `{url}/control/{endpoint}`,
|
||||
strelaysrv: `{url}/{endpoint}`,
|
||||
mastodon: `{url}/api/v1/{endpoint}`,
|
||||
};
|
||||
// const formats = {
|
||||
// emby: `{url}/emby/{endpoint}?api_key={key}`,
|
||||
// jellyfin: `{url}/emby/{endpoint}?api_key={key}`,
|
||||
// pihole: `{url}/admin/{endpoint}`,
|
||||
// radarr: `{url}/api/v3/{endpoint}?apikey={key}`,
|
||||
// sonarr: `{url}/api/v3/{endpoint}?apikey={key}`,
|
||||
// speedtest: `{url}/api/{endpoint}`,
|
||||
// tautulli: `{url}/api/v2?apikey={key}&cmd={endpoint}`,
|
||||
// traefik: `{url}/api/{endpoint}`,
|
||||
// portainer: `{url}/api/endpoints/{env}/{endpoint}`,
|
||||
// rutorrent: `{url}/plugins/httprpc/action.php`,
|
||||
// transmission: `{url}/transmission/rpc`,
|
||||
// qbittorrent: `{url}/api/v2/{endpoint}`,
|
||||
// jellyseerr: `{url}/api/v1/{endpoint}`,
|
||||
// overseerr: `{url}/api/v1/{endpoint}`,
|
||||
// ombi: `{url}/api/v1/{endpoint}`,
|
||||
// npm: `{url}/api/{endpoint}`,
|
||||
// lidarr: `{url}/api/v1/{endpoint}?apikey={key}`,
|
||||
// readarr: `{url}/api/v1/{endpoint}?apikey={key}`,
|
||||
// bazarr: `{url}/api/{endpoint}/wanted?apikey={key}`,
|
||||
// sabnzbd: `{url}/api/?apikey={key}&output=json&mode={endpoint}`,
|
||||
// coinmarketcap: `https://pro-api.coinmarketcap.com/{endpoint}`,
|
||||
// gotify: `{url}/{endpoint}`,
|
||||
// prowlarr: `{url}/api/v1/{endpoint}`,
|
||||
// jackett: `{url}/api/v2.0/{endpoint}?apikey={key}&configured=true`,
|
||||
// adguard: `{url}/control/{endpoint}`,
|
||||
// strelaysrv: `{url}/{endpoint}`,
|
||||
// mastodon: `{url}/api/v1/{endpoint}`,
|
||||
// };
|
||||
|
||||
export function formatApiCall(api, args) {
|
||||
export function formatApiCall(url, args) {
|
||||
const find = /\{.*?\}/g;
|
||||
const replace = (match) => {
|
||||
const key = match.replace(/\{|\}/g, "");
|
||||
return args[key];
|
||||
};
|
||||
|
||||
return formats[api].replace(find, replace);
|
||||
return url.replace(find, replace);
|
||||
}
|
||||
|
||||
export function formatApiUrl(widget, endpoint) {
|
||||
export function formatProxyUrl(widget, endpoint) {
|
||||
const params = new URLSearchParams({
|
||||
type: widget.type,
|
||||
group: widget.service_group,
|
||||
|
@ -47,3 +47,23 @@ export function formatApiUrl(widget, endpoint) {
|
|||
});
|
||||
return `/api/services/proxy?${params.toString()}`;
|
||||
}
|
||||
|
||||
export function asJson(data) {
|
||||
if (data?.length > 0) {
|
||||
const json = JSON.parse(data.toString());
|
||||
return json;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
export function jsonArrayTransform(data, transform) {
|
||||
const json = asJson(data);
|
||||
if (json instanceof Array) {
|
||||
return transform(json);
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
export function jsonArrayFilter(data, filter) {
|
||||
return jsonArrayTransform(data, (items) => items.filter(filter));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue