Compare commits

...

29 Commits

Author SHA1 Message Date
Ben Phelps
d861264ecf fix error case cause failure to load anything 2022-09-11 11:13:54 +03:00
Ben Phelps
e3237b9022 fix text alignment 2022-09-10 21:43:14 +03:00
Ben Phelps
3882dd4f5a fix cases where configurations are empty 2022-09-09 22:01:01 +03:00
Ben Phelps
d66326b41d implement docker service discovery via labels 2022-09-09 21:53:05 +03:00
Anonymous
ef1c5dbcc9 Translated using Weblate (Dutch)
Currently translated at 100.0% (0 of 0 strings)

Translation: Homepage/Homepage
Translate-URL: https://hosted.weblate.org/projects/homepage/homepage/nl/
2022-09-09 14:59:59 +02:00
Allan Nordhøy
c45c8e93de Translated using Weblate (Norwegian Bokmål)
Currently translated at 100.0% (64 of 64 strings)

Translation: Homepage/Homepage
Translate-URL: https://hosted.weblate.org/projects/homepage/homepage/nb_NO/
2022-09-09 14:59:58 +02:00
Francisco Coelho
1e93bf3ec4 Translated using Weblate (Portuguese)
Currently translated at 32.8% (21 of 64 strings)

Translation: Homepage/Homepage
Translate-URL: https://hosted.weblate.org/projects/homepage/homepage/pt/
2022-09-09 14:59:58 +02:00
Bernhard Großer
4bff209bd7 Translated using Weblate (German)
Currently translated at 100.0% (64 of 64 strings)

Translation: Homepage/Homepage
Translate-URL: https://hosted.weblate.org/projects/homepage/homepage/de/
2022-09-09 14:59:58 +02:00
Ben Phelps
e5ee937c38 Added translation using Weblate (Dutch) 2022-09-09 14:59:54 +02:00
Ben Phelps
c418efe007 fix fallback to / in disk resource widget 2022-09-09 15:27:42 +03:00
Ben Phelps
5677254b46 add new weather feature to readme 2022-09-09 13:07:20 +03:00
Ben Phelps
cb76a8165d pre-create settings.yaml for build process 2022-09-09 13:07:09 +03:00
Ben Phelps
a7a1eca0cd attempt to fix weird race condition in builds? 2022-09-09 12:59:43 +03:00
Ben Phelps
85bc078c46 always attempt location fetch
if it fails, then we just fallback to user interaction
2022-09-09 12:57:15 +03:00
Anonymous
5c347d9427 Translated using Weblate (Vietnamese)
Currently translated at 50.0% (32 of 64 strings)

Translation: Homepage/Homepage
Translate-URL: https://hosted.weblate.org/projects/homepage/homepage/vi/
2022-09-09 11:44:50 +02:00
Anonymous
6c17efc2ab Translated using Weblate (Norwegian Bokmål)
Currently translated at 93.7% (60 of 64 strings)

Translation: Homepage/Homepage
Translate-URL: https://hosted.weblate.org/projects/homepage/homepage/nb_NO/
2022-09-09 11:44:50 +02:00
Anonymous
a6e929ba86 Translated using Weblate (Italian)
Currently translated at 14.0% (9 of 64 strings)

Translation: Homepage/Homepage
Translate-URL: https://hosted.weblate.org/projects/homepage/homepage/it/
2022-09-09 11:44:50 +02:00
Anonymous
f9886f7c63 Translated using Weblate (Chinese (Simplified))
Currently translated at 93.7% (60 of 64 strings)

Translation: Homepage/Homepage
Translate-URL: https://hosted.weblate.org/projects/homepage/homepage/zh_Hans/
2022-09-09 11:44:49 +02:00
Anonymous
ec937f6212 Translated using Weblate (Russian)
Currently translated at 14.0% (9 of 64 strings)

Translation: Homepage/Homepage
Translate-URL: https://hosted.weblate.org/projects/homepage/homepage/ru/
2022-09-09 11:44:49 +02:00
Anonymous
b7427c3409 Translated using Weblate (Portuguese)
Currently translated at 14.0% (9 of 64 strings)

Translation: Homepage/Homepage
Translate-URL: https://hosted.weblate.org/projects/homepage/homepage/pt/
2022-09-09 11:44:49 +02:00
Anonymous
5bd9cf46ea Translated using Weblate (French)
Currently translated at 14.0% (9 of 64 strings)

Translation: Homepage/Homepage
Translate-URL: https://hosted.weblate.org/projects/homepage/homepage/fr/
2022-09-09 11:44:49 +02:00
Anonymous
c340c42ef3 Translated using Weblate (Spanish)
Currently translated at 93.7% (60 of 64 strings)

Translation: Homepage/Homepage
Translate-URL: https://hosted.weblate.org/projects/homepage/homepage/es/
2022-09-09 11:44:48 +02:00
Anonymous
27c5b4227d Translated using Weblate (German)
Currently translated at 93.7% (60 of 64 strings)

Translation: Homepage/Homepage
Translate-URL: https://hosted.weblate.org/projects/homepage/homepage/de/
2022-09-09 11:44:48 +02:00
Trung Le
914e869778 Translated using Weblate (Vietnamese)
Currently translated at 53.3% (32 of 60 strings)

Translation: Homepage/Homepage
Translate-URL: https://hosted.weblate.org/projects/homepage/homepage/vi/
2022-09-09 11:44:42 +02:00
Ben Phelps
e4ea30becc implement weather geolocation 2022-09-09 12:44:34 +03:00
Ben Phelps
61f91f0e45 remove logging 2022-09-09 11:51:36 +03:00
Ben Phelps
c6d8668e69 fix jellyfin integration 2022-09-09 11:42:08 +03:00
Anonymous
3c73b000df Translated using Weblate (Vietnamese)
Currently translated at 100.0% (0 of 0 strings)

Translation: Homepage/Homepage
Translate-URL: https://hosted.weblate.org/projects/homepage/homepage/vi/
2022-09-09 08:11:36 +02:00
Trung Le
ed5a5ae86f Added translation using Weblate (Vietnamese) 2022-09-09 08:11:33 +02:00
26 changed files with 785 additions and 243 deletions

View File

@@ -28,9 +28,8 @@ COPY . .
RUN <<EOF
set -xe
yarn next telemetry disable
mkdir config
mkdir config && echo '-' > config/settings.yaml
npm run build
rm -rf config
EOF
# Production image, copy all the files and run next

View File

@@ -20,6 +20,7 @@
* Information & Utility Widgets
- System Stats (Disk, CPU, Memory)
- Weather via WeatherAPI.com or OpenWeatherMap ([AlexFullmoon](https://github.com/benphelps/homepage/pull/25))
- Automatic location detection (with HTTPS), or manual location selection
- Search Bar ([aidenpwnz](https://github.com/benphelps/homepage/pull/45))
* Customizable
- 21 theme colors with light and dark mode support

View File

@@ -28,6 +28,7 @@
"react-i18next": "^11.18.5",
"react-icons": "^4.4.0",
"rutorrent-promise": "^2.0.0",
"shvl": "^3.0.0",
"swr": "^1.3.0"
},
"devDependencies": {

6
pnpm-lock.yaml generated
View File

@@ -32,6 +32,7 @@ specifiers:
react-i18next: ^11.18.5
react-icons: ^4.4.0
rutorrent-promise: ^2.0.0
shvl: ^3.0.0
swr: ^1.3.0
tailwindcss: ^3.1.8
typescript: ^4.8.2
@@ -56,6 +57,7 @@ dependencies:
react-i18next: 11.18.5_4sidbwfhen5r7txudrvpua6nty
react-icons: 4.4.0_react@18.2.0
rutorrent-promise: 2.0.0
shvl: 3.0.0
swr: 1.3.0_react@18.2.0
devDependencies:
@@ -2354,6 +2356,10 @@ packages:
engines: {node: '>=8'}
dev: true
/shvl/3.0.0:
resolution: {integrity: sha512-5IomAM3ykE/g9K9L6lhODc+TpCuN03rrhlboegeKyyfh66DDdpRD5JN37DYhNHH+RaYjiIDx64K/Ms/xQYOR5w==}
dev: false
/side-channel/1.0.4:
resolution: {integrity: sha512-q5XPytqFEIKHkGdiMIrY10mvLRvnQh42/+GoBlFW3b2LXLE2xxJpZFdm94we0BaoV3RwJyGqg5wS7epxTv0Zvw==}
dependencies:

View File

@@ -1,87 +1,93 @@
{
"widget":{
"missing_type":"Fehlender Widget-Typ: {{type}}",
"api_error":"API-Fehler",
"status":"Status"
},
"search":{
"placeholder":"Suche…"
},
"resources":{
"total":"Gesamt",
"free":"Frei",
"used":"Gebraucht"
},
"docker":{
"rx":"Rx",
"tx":"Tx",
"mem":"Mem",
"cpu":"Zentralprozessor",
"offline":"Offline"
},
"emby":{
"playing":"Spielen",
"transcoding":"Transcodierung",
"bitrate":"Bitrate"
},
"tautulli":{
"playing":"Spielen",
"transcoding":"Transcodierung",
"bitrate":"Bitrate"
},
"nzbget":{
"rate":"Rate",
"remaining":"Verblieben",
"downloaded":"Heruntergeladen"
},
"rutorrent":{
"active":"Aktiv",
"upload":"Hochladen",
"download":"Download"
},
"sonarr":{
"wanted":"Gesucht",
"queued":"In Warteschlange",
"series":"Serie"
},
"radarr":{
"wanted":"Gesucht",
"queued":"In Warteschlange",
"movies":"Filme"
},
"ombi":{
"pending":"Ausstehend",
"approved":"Genehmigt",
"available":"Verfügbar"
},
"jellyseerr":{
"pending":"Ausstehend",
"approved":"Genehmigt",
"available":"Verfügbar"
},
"pihole":{
"queries":"Abfragen",
"blocked":"verstopft",
"gravity":"Schwere"
},
"speedtest":{
"upload":"Hochladen",
"download":"Download",
"ping":"Klingeln"
},
"portainer":{
"running":"Betrieb",
"stopped":"Gestoppt",
"total":"Gesamt"
},
"traefik":{
"routers":"Router",
"services":"Dienstleistungen",
"middleware":"Middleware"
},
"npm":{
"enabled":"Ermöglicht",
"disabled":"Deaktiviert",
"total":"Gesamt"
}
"widget": {
"missing_type": "Fehlender Widget-Typ: {{type}}",
"api_error": "API-Fehler",
"status": "Status"
},
"search": {
"placeholder": "Suche…"
},
"resources": {
"total": "Gesamt",
"free": "Frei",
"used": "Gebraucht"
},
"docker": {
"rx": "Rx",
"tx": "Tx",
"mem": "Mem",
"cpu": "Prozessor",
"offline": "Offline"
},
"emby": {
"playing": "Spielen",
"transcoding": "Transcodierung",
"bitrate": "Bitrate"
},
"tautulli": {
"playing": "Spielen",
"transcoding": "Transcodierung",
"bitrate": "Bitrate"
},
"nzbget": {
"rate": "Rate",
"remaining": "Verblieben",
"downloaded": "Heruntergeladen"
},
"rutorrent": {
"active": "Aktiv",
"upload": "Hochladen",
"download": "Download"
},
"sonarr": {
"wanted": "Gesucht",
"queued": "In Warteschlange",
"series": "Serie"
},
"radarr": {
"wanted": "Gesucht",
"queued": "In Warteschlange",
"movies": "Filme"
},
"ombi": {
"pending": "Ausstehend",
"approved": "Genehmigt",
"available": "Verfügbar"
},
"jellyseerr": {
"pending": "Ausstehend",
"approved": "Genehmigt",
"available": "Verfügbar"
},
"pihole": {
"queries": "Abfragen",
"blocked": "Blockiert",
"gravity": "Gravity"
},
"speedtest": {
"upload": "Upload",
"download": "Download",
"ping": "Ping"
},
"portainer": {
"running": "Betrieb",
"stopped": "Gestoppt",
"total": "Gesamt"
},
"traefik": {
"routers": "Router",
"services": "Services",
"middleware": "Middleware"
},
"npm": {
"enabled": "Aktiviert",
"disabled": "Deaktiviert",
"total": "Gesamt"
},
"weather": {
"current": "Aktueller Standort",
"allow": "Zum Zulassen anklicken",
"updating": "Aktualisieren",
"wait": "Bitte warten"
}
}

View File

@@ -15,6 +15,12 @@
"api_error": "API Error",
"status": "Status"
},
"weather": {
"current": "Current Location",
"allow": "Click to allow",
"updating": "Updating",
"wait": "Please wait"
},
"search": {
"placeholder": "Search…"
},

View File

@@ -83,5 +83,11 @@
"enabled": "Activado",
"disabled": "Desactivado",
"total": "Total"
},
"weather": {
"current": "Current Location",
"allow": "Click to allow",
"updating": "Updating",
"wait": "Please wait"
}
}

View File

@@ -94,5 +94,11 @@
"bitrate": "{{value, bytes(bits: true)}}",
"percent": "{{value, percent}}",
"ms": "{{value, number}}"
},
"weather": {
"current": "Current Location",
"allow": "Click to allow",
"updating": "Updating",
"wait": "Please wait"
}
}

View File

@@ -83,5 +83,11 @@
"enabled": "Enabled",
"disabled": "Disabled",
"total": "Total"
},
"weather": {
"current": "Current Location",
"allow": "Click to allow",
"updating": "Updating",
"wait": "Please wait"
}
}

View File

@@ -83,5 +83,11 @@
"enabled": "Påskrudd",
"disabled": "Avskrudd",
"total": "Totalt"
},
"weather": {
"allow": "Klikk for å tillate",
"updating": "Oppdaterer …",
"wait": "Vent litt …",
"current": "Nåværende posisjon"
}
}

View File

@@ -0,0 +1,93 @@
{
"widget": {
"missing_type": "Missing Widget Type: {{type}}",
"api_error": "API Error",
"status": "Status"
},
"resources": {
"total": "Total",
"free": "Free",
"used": "Used"
},
"docker": {
"rx": "RX",
"tx": "TX",
"mem": "MEM",
"cpu": "CPU",
"offline": "Offline"
},
"nzbget": {
"rate": "Rate",
"remaining": "Remaining",
"downloaded": "Downloaded"
},
"speedtest": {
"upload": "Upload",
"download": "Download",
"ping": "Ping"
},
"portainer": {
"running": "Running",
"stopped": "Stopped",
"total": "Total"
},
"weather": {
"updating": "Updating",
"wait": "Please wait",
"current": "Current Location",
"allow": "Click to allow"
},
"search": {
"placeholder": "Search…"
},
"emby": {
"playing": "Playing",
"transcoding": "Transcoding",
"bitrate": "Bitrate"
},
"tautulli": {
"playing": "Playing",
"transcoding": "Transcoding",
"bitrate": "Bitrate"
},
"rutorrent": {
"active": "Active",
"upload": "Upload",
"download": "Download"
},
"sonarr": {
"wanted": "Wanted",
"queued": "Queued",
"series": "Series"
},
"radarr": {
"movies": "Movies",
"wanted": "Wanted",
"queued": "Queued"
},
"ombi": {
"pending": "Pending",
"approved": "Approved",
"available": "Available"
},
"jellyseerr": {
"pending": "Pending",
"approved": "Approved",
"available": "Available"
},
"pihole": {
"queries": "Queries",
"blocked": "Blocked",
"gravity": "Gravity"
},
"traefik": {
"routers": "Routers",
"services": "Services",
"middleware": "Middleware"
},
"npm": {
"enabled": "Enabled",
"disabled": "Disabled",
"total": "Total"
}
}

View File

@@ -5,7 +5,7 @@
"status": "Status"
},
"search": {
"placeholder": "Procurar…"
"placeholder": "Pesquisar…"
},
"resources": {
"total": "Total",
@@ -20,32 +20,32 @@
"offline": "Desligada"
},
"emby": {
"playing": "Jogando",
"playing": "A reproduzir",
"transcoding": "Transcodificação",
"bitrate": "Taxa de bits"
},
"tautulli": {
"playing": "Jogando",
"playing": "Reproduzindo",
"transcoding": "Transcodificação",
"bitrate": "Taxa de bits"
},
"nzbget": {
"rate": "Avaliar",
"remaining": "Remanescente",
"remaining": "Em falta",
"downloaded": "Baixada"
},
"rutorrent": {
"active": "Ativa",
"upload": "Envio",
"download": "Download"
"download": "ReceçãoDownload"
},
"sonarr": {
"wanted": "Desejada",
"queued": "Enfileiradas",
"series": "Series"
"queued": "Em fila",
"series": "Séries"
},
"radarr": {
"wanted": "Desejada",
"wanted": "Desejado",
"queued": "Enfileiradas",
"movies": "Filmes"
},
@@ -94,5 +94,11 @@
"ms": "{{value, number}}",
"bitrate": "{{value, bytes(bits: true)}}",
"percent": "{{value, percent}}"
},
"weather": {
"current": "Localização atual",
"allow": "Clicar para permitir",
"updating": "A atualizar",
"wait": "Por favor aguarde"
}
}

View File

@@ -83,5 +83,11 @@
"enabled": "Включено",
"disabled": "Неполноценный",
"total": "Общий"
},
"weather": {
"wait": "Please wait",
"current": "Current Location",
"allow": "Click to allow",
"updating": "Updating"
}
}

View File

@@ -0,0 +1,93 @@
{
"widget": {
"missing_type": "Thiếu loại Widget: {{type}}",
"api_error": "Lỗi API",
"status": "Trạng thái"
},
"search": {
"placeholder": "Tìm kiếm…"
},
"resources": {
"total": "Tổng",
"free": "Dư",
"used": "Đã dùng"
},
"docker": {
"rx": "RX",
"tx": "TX",
"mem": "BỘ NHỚ",
"cpu": "CPU",
"offline": "Ngoại tuyến"
},
"emby": {
"playing": "Đang chơi",
"transcoding": "Chuyển định dạng",
"bitrate": "Bitrate"
},
"tautulli": {
"playing": "Đang chơi",
"transcoding": "Chuyển định dạng",
"bitrate": "Bitrate"
},
"nzbget": {
"rate": "Rate",
"remaining": "Còn lại",
"downloaded": "Đã tải"
},
"rutorrent": {
"active": "Hoạt động",
"upload": "Tải lên",
"download": "Tải xuống"
},
"sonarr": {
"wanted": "Wanted",
"queued": "Queued",
"series": "Series"
},
"radarr": {
"wanted": "Wanted",
"queued": "Queued",
"movies": "Movies"
},
"ombi": {
"pending": "Pending",
"approved": "Approved",
"available": "Available"
},
"jellyseerr": {
"pending": "Pending",
"approved": "Approved",
"available": "Available"
},
"pihole": {
"queries": "Queries",
"blocked": "Blocked",
"gravity": "Gravity"
},
"speedtest": {
"upload": "Upload",
"download": "Download",
"ping": "Ping"
},
"portainer": {
"running": "Running",
"stopped": "Stopped",
"total": "Total"
},
"traefik": {
"routers": "Routers",
"services": "Services",
"middleware": "Middleware"
},
"npm": {
"enabled": "Enabled",
"disabled": "Disabled",
"total": "Total"
},
"weather": {
"current": "Current Location",
"allow": "Click to allow",
"updating": "Updating",
"wait": "Please wait"
}
}

View File

@@ -1,87 +1,93 @@
{
"widget":{
"missing_type":"缺少小部件类型:{{type}}",
"api_error":"API错误",
"status":"地位"
},
"search":{
"placeholder":"搜索…"
},
"resources":{
"total":"全部的",
"free":"自由的",
"used":"用过的"
},
"docker":{
"rx":"rx",
"tx":"TX",
"mem":"mem",
"cpu":"中央处理器",
"offline":"离线"
},
"emby":{
"playing":"玩",
"transcoding":"转码",
"bitrate":"比特率"
},
"tautulli":{
"playing":"玩",
"transcoding":"转码",
"bitrate":"比特率"
},
"nzbget":{
"rate":"速度",
"remaining":"其余的",
"downloaded":"下载"
},
"rutorrent":{
"active":"积极的",
"upload":"上传",
"download":"下载"
},
"sonarr":{
"wanted":"通缉",
"queued":"排队",
"series":"系列"
},
"radarr":{
"wanted":"通缉",
"queued":"排队",
"movies":"电影"
},
"ombi":{
"pending":"待办的",
"approved":"得到正式认可的",
"available":"可用的"
},
"jellyseerr":{
"pending":"待办的",
"approved":"得到正式认可的",
"available":"可用的"
},
"pihole":{
"queries":"查询",
"blocked":"阻止",
"gravity":"重力"
},
"speedtest":{
"upload":"上传",
"download":"下载",
"ping":"ping"
},
"portainer":{
"running":"跑步",
"stopped":"停了下来",
"total":"全部的"
},
"traefik":{
"routers":"路由器",
"services":"服务",
"middleware":"中间件"
},
"npm":{
"enabled":"已启用",
"disabled":"禁用",
"total":"全部的"
}
"widget": {
"missing_type": "缺少小部件类型:{{type}}",
"api_error": "API错误",
"status": "地位"
},
"search": {
"placeholder": "搜索…"
},
"resources": {
"total": "全部的",
"free": "自由的",
"used": "用过的"
},
"docker": {
"rx": "rx",
"tx": "TX",
"mem": "mem",
"cpu": "中央处理器",
"offline": "离线"
},
"emby": {
"playing": "玩",
"transcoding": "转码",
"bitrate": "比特率"
},
"tautulli": {
"playing": "玩",
"transcoding": "转码",
"bitrate": "比特率"
},
"nzbget": {
"rate": "速度",
"remaining": "其余的",
"downloaded": "下载"
},
"rutorrent": {
"active": "积极的",
"upload": "上传",
"download": "下载"
},
"sonarr": {
"wanted": "通缉",
"queued": "排队",
"series": "系列"
},
"radarr": {
"wanted": "通缉",
"queued": "排队",
"movies": "电影"
},
"ombi": {
"pending": "待办的",
"approved": "得到正式认可的",
"available": "可用的"
},
"jellyseerr": {
"pending": "待办的",
"approved": "得到正式认可的",
"available": "可用的"
},
"pihole": {
"queries": "查询",
"blocked": "阻止",
"gravity": "重力"
},
"speedtest": {
"upload": "上传",
"download": "下载",
"ping": "ping"
},
"portainer": {
"running": "跑步",
"stopped": "停了下来",
"total": "全部的"
},
"traefik": {
"routers": "路由器",
"services": "服务",
"middleware": "中间件"
},
"npm": {
"enabled": "已启用",
"disabled": "禁用",
"total": "全部的"
},
"weather": {
"current": "Current Location",
"allow": "Click to allow",
"updating": "Updating",
"wait": "Please wait"
}
}

View File

@@ -54,7 +54,7 @@ export default function Item({ service }) {
}}
className="flex-1 flex items-center justify-between rounded-r-md "
>
<div className="flex-1 px-2 py-2 text-sm">
<div className="flex-1 px-2 py-2 text-sm text-left">
{service.name}
<p className="text-theme-500 dark:text-theme-400 text-xs font-extralight">{service.description}</p>
</div>

View File

@@ -1,6 +1,48 @@
import Emby from "./emby";
import useSWR from "swr";
import { useTranslation } from "react-i18next";
import Widget from "../widget";
import Block from "../block";
import { formatApiUrl } from "utils/api-helpers";
// Jellyfin and Emby share the same API, so proxy the Emby widget to Jellyfin.
export default function Jellyfin({ service }) {
return <Emby service={service} />;
const { t } = useTranslation();
const config = service.widget;
const { data: sessionsData, error: sessionsError } = useSWR(formatApiUrl(config, "Sessions"));
if (sessionsError) {
return <Widget error={t("widget.api_error")} />;
}
if (!sessionsData) {
return (
<Widget>
<Block label={t("emby.playing")} />
<Block label={t("emby.transcoding")} />
<Block label={t("emby.bitrate")} />
</Widget>
);
}
const playing = sessionsData.filter((session) => session?.NowPlayingItem);
const transcoding = sessionsData.filter(
(session) => session?.PlayState && session.PlayState.PlayMethod === "Transcode"
);
const bitrate = playing.reduce(
(acc, session) =>
acc + session.NowPlayingQueueFullItems[0].MediaSources.reduce((acb, source) => acb + source.Bitrate, 0),
0
);
return (
<Widget>
<Block label={t("emby.playing")} value={playing.length} />
<Block label={t("emby.transcoding")} value={transcoding.length} />
<Block label={t("emby.bitrate")} value={t("common.bitrate", { value: bitrate })} />
</Widget>
);
}

View File

@@ -1,25 +1,28 @@
import useSWR from "swr";
import { useState } from "react";
import { BiError } from "react-icons/bi";
import { WiCloudDown } from "react-icons/wi";
import { MdLocationDisabled, MdLocationSearching } from "react-icons/md";
import { useTranslation } from "react-i18next";
import Icon from "./icon";
export default function OpenWeatherMap({ options }) {
function Widget({ options }) {
const { t, i18n } = useTranslation();
const { data, error } = useSWR(
`/api/widgets/openweathermap?${new URLSearchParams({ lang: i18n.language, ...options }).toString()}`
);
if (error || data?.cod === 401) {
if (error || data?.cod === 401 || data?.error) {
return (
<div className="flex flex-col">
<div className="flex flex-col justify-center">
<div className="flex flex-row items-center justify-end">
<div className="flex flex-col items-center">
<BiError className="w-8 h-8 text-theme-800 dark:text-theme-200" />
<div className="flex flex-col ml-3 text-left">
<span className="text-theme-800 dark:text-theme-200 text-sm">API</span>
<span className="text-theme-800 dark:text-theme-200 text-xs">Error</span>
<span className="text-theme-800 dark:text-theme-200 text-sm">{t("widget.api_error")}</span>
<span className="text-theme-800 dark:text-theme-200 text-xs">-</span>
</div>
</div>
</div>
@@ -28,11 +31,19 @@ export default function OpenWeatherMap({ options }) {
}
if (!data) {
return <div className="flex flex-row items-center" />;
}
if (data.error) {
return <div className="flex flex-row items-center" />;
return (
<div className="flex flex-col justify-center">
<div className="flex flex-row items-center justify-end">
<div className="flex flex-col items-center">
<WiCloudDown className="w-8 h-8 text-theme-800 dark:text-theme-200" />
</div>
<div className="flex flex-col ml-3 text-left">
<span className="text-theme-800 dark:text-theme-200 text-sm">{t("weather.updating")}</span>
<span className="text-theme-800 dark:text-theme-200 text-xs">{t("weather.wait")}</span>
</div>
</div>
</div>
);
}
const unit = options.units === "metric" ? "celsius" : "fahrenheit";
@@ -57,3 +68,55 @@ export default function OpenWeatherMap({ options }) {
</div>
);
}
export default function OpenWeatherMap({ options }) {
const { t } = useTranslation();
const [location, setLocation] = useState(false);
const [requesting, setRequesting] = useState(false);
if (!location && options.latitude && options.longitude) {
setLocation({ latitude: options.latitude, longitude: options.longitude });
}
const requestLocation = () => {
setRequesting(true);
navigator.geolocation.getCurrentPosition(
(position) => {
setLocation({ latitude: position.coords.latitude, longitude: position.coords.longitude });
setRequesting(false);
},
() => {
setRequesting(false);
},
{
enableHighAccuracy: true,
maximumAge: 1000 * 60 * 60 * 3,
timeout: 1000 * 30,
}
);
};
if (!requesting && !location) requestLocation();
if (!location) {
return (
<button type="button" onClick={() => requestLocation()} className="flex flex-col justify-center">
<div className="flex flex-row items-center justify-end">
<div className="flex flex-col items-center">
{requesting ? (
<MdLocationSearching className="w-6 h-6 text-theme-800 dark:text-theme-200 animate-pulse" />
) : (
<MdLocationDisabled className="w-6 h-6 text-theme-800 dark:text-theme-200" />
)}
</div>
<div className="flex flex-col ml-3 text-left">
<span className="text-theme-800 dark:text-theme-200 text-sm">{t("weather.current")}</span>
<span className="text-theme-800 dark:text-theme-200 text-xs">{t("weather.allow")}</span>
</div>
</div>
</button>
);
}
return <Widget options={{ ...location, ...options }} />;
}

View File

@@ -1,25 +1,28 @@
import useSWR from "swr";
import { useState } from "react";
import { BiError } from "react-icons/bi";
import { WiCloudDown } from "react-icons/wi";
import { MdLocationDisabled, MdLocationSearching } from "react-icons/md";
import { useTranslation } from "react-i18next";
import Icon from "./icon";
export default function WeatherApi({ options }) {
function Widget({ options }) {
const { t, i18n } = useTranslation();
const { data, error } = useSWR(
`/api/widgets/weather?${new URLSearchParams({ lang: i18n.language, ...options }).toString()}`
);
if (error) {
if (error || data?.error) {
return (
<div className="flex flex-col">
<div className="flex flex-col justify-center">
<div className="flex flex-row items-center justify-end">
<div className="flex flex-col items-center">
<BiError className="w-8 h-8 text-theme-800 dark:text-theme-200" />
<div className="flex flex-col ml-3 text-left">
<span className="text-theme-800 dark:text-theme-200 text-sm">API</span>
<span className="text-theme-800 dark:text-theme-200 text-xs">Error</span>
<span className="text-theme-800 dark:text-theme-200 text-sm">{t("widget.api_error")}</span>
<span className="text-theme-800 dark:text-theme-200 text-xs">-</span>
</div>
</div>
</div>
@@ -28,11 +31,19 @@ export default function WeatherApi({ options }) {
}
if (!data) {
return <div className="flex flex-row items-center justify-end" />;
}
if (data.error) {
return <div className="flex flex-row items-center justify-end" />;
return (
<div className="flex flex-col justify-center">
<div className="flex flex-row items-center justify-end">
<div className="flex flex-col items-center">
<WiCloudDown className="w-8 h-8 text-theme-800 dark:text-theme-200" />
</div>
<div className="flex flex-col ml-3 text-left">
<span className="text-theme-800 dark:text-theme-200 text-sm">{t("weather.updating")}</span>
<span className="text-theme-800 dark:text-theme-200 text-xs">{t("weather.wait")}</span>
</div>
</div>
</div>
);
}
const unit = options.units === "metric" ? "celsius" : "fahrenheit";
@@ -58,3 +69,55 @@ export default function WeatherApi({ options }) {
</div>
);
}
export default function WeatherApi({ options }) {
const { t } = useTranslation();
const [location, setLocation] = useState(false);
const [requesting, setRequesting] = useState(false);
if (!location && options.latitude && options.longitude) {
setLocation({ latitude: options.latitude, longitude: options.longitude });
}
const requestLocation = () => {
setRequesting(true);
navigator.geolocation.getCurrentPosition(
(position) => {
setLocation({ latitude: position.coords.latitude, longitude: position.coords.longitude });
setRequesting(false);
},
() => {
setRequesting(false);
},
{
enableHighAccuracy: true,
maximumAge: 1000 * 60 * 60 * 3,
timeout: 1000 * 30,
}
);
};
if (!requesting && !location) requestLocation();
if (!location) {
return (
<button type="button" onClick={() => requestLocation()} className="flex flex-col justify-center">
<div className="flex flex-row items-center justify-end">
<div className="flex flex-col items-center">
{requesting ? (
<MdLocationSearching className="w-6 h-6 text-theme-800 dark:text-theme-200 animate-pulse" />
) : (
<MdLocationDisabled className="w-6 h-6 text-theme-800 dark:text-theme-200" />
)}
</div>
<div className="flex flex-col ml-3 text-left">
<span className="text-theme-800 dark:text-theme-200 text-sm">{t("weather.current")}</span>
<span className="text-theme-800 dark:text-theme-200 text-xs">{t("weather.allow")}</span>
</div>
</div>
</button>
);
}
return <Widget options={{ ...location, ...options }} />;
}

View File

@@ -14,7 +14,7 @@ export default async function handler(req, res) {
}
try {
const docker = new Docker(await getDockerArguments(containerServer));
const docker = new Docker(getDockerArguments(containerServer));
const containers = await docker.listContainers({
all: true,
});

View File

@@ -13,7 +13,7 @@ export default async function handler(req, res) {
}
try {
const docker = new Docker(await getDockerArguments(containerServer));
const docker = new Docker(getDockerArguments(containerServer));
const containers = await docker.listContainers({
all: true,
});

View File

@@ -1,40 +1,38 @@
import { promises as fs } from "fs";
import path from "path";
import yaml from "js-yaml";
import checkAndCopyConfig from "utils/config";
import { servicesFromConfig, servicesFromDocker, cleanServiceGroups } from "utils/service-helpers";
export default async function handler(req, res) {
checkAndCopyConfig("services.yaml");
let discoveredServices;
let configuredServices;
const servicesYaml = path.join(process.cwd(), "config", "services.yaml");
const fileContents = await fs.readFile(servicesYaml, "utf8");
const services = yaml.load(fileContents);
try {
discoveredServices = cleanServiceGroups(await servicesFromDocker());
} catch {
discoveredServices = [];
}
// map easy to write YAML objects into easy to consume JS arrays
const servicesArray = services.map((group) => ({
name: Object.keys(group)[0],
services: group[Object.keys(group)[0]].map((entries) => {
const { widget, ...service } = entries[Object.keys(entries)[0]];
const result = {
name: Object.keys(entries)[0],
...service,
};
try {
configuredServices = cleanServiceGroups(await servicesFromConfig());
} catch {
configuredServices = [];
}
if (widget) {
const { type } = widget;
const mergedGroupsNames = [
...new Set([discoveredServices.map((group) => group.name), configuredServices.map((group) => group.name)].flat()),
];
result.widget = {
type,
service_group: Object.keys(group)[0],
service_name: Object.keys(entries)[0],
};
}
const mergedGroups = [];
return result;
}),
}));
mergedGroupsNames.forEach((groupName) => {
const discoveredGroup = discoveredServices.find((group) => group.name === groupName) || { services: [] };
const configuredGroup = configuredServices.find((group) => group.name === groupName) || { services: [] };
res.send(servicesArray);
const mergedGroup = {
name: groupName,
services: [...discoveredGroup.services, ...configuredGroup.services].filter((service) => service),
};
mergedGroups.push(mergedGroup);
});
res.send(mergedGroups);
}

View File

@@ -1,3 +1,5 @@
import { existsSync } from "fs";
import { cpu, drive, mem } from "node-os-utils";
export default async function handler(req, res) {
@@ -13,6 +15,12 @@ export default async function handler(req, res) {
}
if (type === "disk") {
if (!existsSync(target)) {
return res.status(404).json({
error: "Target not found",
});
}
return res.status(200).json({
drive: await drive.info(target || "/"),
});

View File

@@ -1,15 +1,15 @@
import path from "path";
import { promises as fs } from "fs";
import { readFileSync } from "fs";
import yaml from "js-yaml";
import checkAndCopyConfig from "utils/config";
export default async function getDockerArguments(server) {
export default function getDockerArguments(server) {
checkAndCopyConfig("docker.yaml");
const configFile = path.join(process.cwd(), "config", "docker.yaml");
const configData = await fs.readFile(configFile, "utf8");
const configData = readFileSync(configFile, "utf8");
const servers = yaml.load(configData);
if (!server) {

View File

@@ -11,7 +11,7 @@ i18n
.init({
fallbackLng: "en",
ns: ["common"],
debug: process.env.NODE_ENV === "development",
// debug: process.env.NODE_ENV === "development",
defaultNS: "common",
nonExplicitSupportedLngs: true,
interpolation: {

View File

@@ -2,12 +2,23 @@ import { promises as fs } from "fs";
import path from "path";
import yaml from "js-yaml";
import Docker from "dockerode";
import * as shvl from "shvl";
import checkAndCopyConfig from "utils/config";
import getDockerArguments from "utils/docker";
export async function servicesFromConfig() {
checkAndCopyConfig("services.yaml");
export default async function getServiceWidget(group, service) {
const servicesYaml = path.join(process.cwd(), "config", "services.yaml");
const fileContents = await fs.readFile(servicesYaml, "utf8");
const services = yaml.load(fileContents);
if (!services) {
return [];
}
// map easy to write YAML objects into easy to consume JS arrays
const servicesArray = services.map((servicesGroup) => ({
name: Object.keys(servicesGroup)[0],
@@ -17,7 +28,106 @@ export default async function getServiceWidget(group, service) {
})),
}));
const serviceGroup = servicesArray.find((g) => g.name === group);
return servicesArray;
}
export async function servicesFromDocker() {
checkAndCopyConfig("docker.yaml");
const dockerYaml = path.join(process.cwd(), "config", "docker.yaml");
const dockerFileContents = await fs.readFile(dockerYaml, "utf8");
const servers = yaml.load(dockerFileContents);
if (!servers) {
return [];
}
const serviceServers = await Promise.all(
Object.keys(servers).map(async (serverName) => {
const docker = new Docker(getDockerArguments(serverName));
const containers = await docker.listContainers({
all: true,
});
// bad docker connections can result in a <Buffer ...> object?
// in any case, this ensures the result is the expected array
if (!Array.isArray(containers)) {
return [];
}
const discovered = containers.map((container) => {
let constructedService = null;
Object.keys(container.Labels).forEach((label) => {
if (label.startsWith("homepage")) {
if (!constructedService) {
constructedService = {
container: container.Names[0].replace(/^\//, ""),
server: serverName,
};
}
shvl.set(constructedService, label.replace("homepage.", ""), container.Labels[label]);
}
});
return constructedService;
});
return { server: serverName, services: discovered.filter((filteredService) => filteredService) };
})
);
const mappedServiceGroups = [];
serviceServers.forEach((server) => {
server.services.forEach((serverService) => {
let serverGroup = mappedServiceGroups.find((searchedGroup) => searchedGroup.name === serverService.group);
if (!serverGroup) {
mappedServiceGroups.push({
name: serverService.group,
services: [],
});
serverGroup = mappedServiceGroups[mappedServiceGroups.length - 1];
}
const { name: serviceName, group: serverServiceGroup, ...pushedService } = serverService;
const result = {
name: serviceName,
...pushedService,
};
serverGroup.services.push(result);
});
});
return mappedServiceGroups;
}
export function cleanServiceGroups(groups) {
return groups.map((serviceGroup) => ({
name: serviceGroup.name,
services: serviceGroup.services.map((service) => {
const cleanedService = { ...service };
if (cleanedService.widget) {
const { type } = cleanedService.widget;
cleanedService.widget = {
type,
service_name: service.name,
service_group: serviceGroup.name,
};
}
return cleanedService;
}),
}));
}
export default async function getServiceWidget(group, service) {
const configuredServices = await servicesFromConfig();
const serviceGroup = configuredServices.find((g) => g.name === group);
if (serviceGroup) {
const serviceEntry = serviceGroup.services.find((s) => s.name === service);
if (serviceEntry) {
@@ -26,5 +136,16 @@ export default async function getServiceWidget(group, service) {
}
}
const discoveredServices = await servicesFromDocker();
const dockerServiceGroup = discoveredServices.find((g) => g.name === group);
if (dockerServiceGroup) {
const dockerServiceEntry = dockerServiceGroup.services.find((s) => s.name === service);
if (dockerServiceEntry) {
const { widget } = dockerServiceEntry;
return widget;
}
}
return false;
}