Compare commits

...

25 Commits

Author SHA1 Message Date
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
17 changed files with 619 additions and 203 deletions

View File

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

View File

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

View File

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

View File

@@ -83,5 +83,11 @@
"enabled": "Activado", "enabled": "Activado",
"disabled": "Desactivado", "disabled": "Desactivado",
"total": "Total" "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)}}", "bitrate": "{{value, bytes(bits: true)}}",
"percent": "{{value, percent}}", "percent": "{{value, percent}}",
"ms": "{{value, number}}" "ms": "{{value, number}}"
},
"weather": {
"current": "Current Location",
"allow": "Click to allow",
"updating": "Updating",
"wait": "Please wait"
} }
} }

View File

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

View File

@@ -83,5 +83,11 @@
"enabled": "Påskrudd", "enabled": "Påskrudd",
"disabled": "Avskrudd", "disabled": "Avskrudd",
"total": "Totalt" "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" "status": "Status"
}, },
"search": { "search": {
"placeholder": "Procurar…" "placeholder": "Pesquisar…"
}, },
"resources": { "resources": {
"total": "Total", "total": "Total",
@@ -20,32 +20,32 @@
"offline": "Desligada" "offline": "Desligada"
}, },
"emby": { "emby": {
"playing": "Jogando", "playing": "A reproduzir",
"transcoding": "Transcodificação", "transcoding": "Transcodificação",
"bitrate": "Taxa de bits" "bitrate": "Taxa de bits"
}, },
"tautulli": { "tautulli": {
"playing": "Jogando", "playing": "Reproduzindo",
"transcoding": "Transcodificação", "transcoding": "Transcodificação",
"bitrate": "Taxa de bits" "bitrate": "Taxa de bits"
}, },
"nzbget": { "nzbget": {
"rate": "Avaliar", "rate": "Avaliar",
"remaining": "Remanescente", "remaining": "Em falta",
"downloaded": "Baixada" "downloaded": "Baixada"
}, },
"rutorrent": { "rutorrent": {
"active": "Ativa", "active": "Ativa",
"upload": "Envio", "upload": "Envio",
"download": "Download" "download": "ReceçãoDownload"
}, },
"sonarr": { "sonarr": {
"wanted": "Desejada", "wanted": "Desejada",
"queued": "Enfileiradas", "queued": "Em fila",
"series": "Series" "series": "Séries"
}, },
"radarr": { "radarr": {
"wanted": "Desejada", "wanted": "Desejado",
"queued": "Enfileiradas", "queued": "Enfileiradas",
"movies": "Filmes" "movies": "Filmes"
}, },
@@ -94,5 +94,11 @@
"ms": "{{value, number}}", "ms": "{{value, number}}",
"bitrate": "{{value, bytes(bits: true)}}", "bitrate": "{{value, bytes(bits: true)}}",
"percent": "{{value, percent}}" "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": "Включено", "enabled": "Включено",
"disabled": "Неполноценный", "disabled": "Неполноценный",
"total": "Общий" "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":{ "widget": {
"missing_type":"缺少小部件类型:{{type}}", "missing_type": "缺少小部件类型:{{type}}",
"api_error":"API错误", "api_error": "API错误",
"status":"地位" "status": "地位"
}, },
"search":{ "search": {
"placeholder":"搜索…" "placeholder": "搜索…"
}, },
"resources":{ "resources": {
"total":"全部的", "total": "全部的",
"free":"自由的", "free": "自由的",
"used":"用过的" "used": "用过的"
}, },
"docker":{ "docker": {
"rx":"rx", "rx": "rx",
"tx":"TX", "tx": "TX",
"mem":"mem", "mem": "mem",
"cpu":"中央处理器", "cpu": "中央处理器",
"offline":"离线" "offline": "离线"
}, },
"emby":{ "emby": {
"playing":"玩", "playing": "玩",
"transcoding":"转码", "transcoding": "转码",
"bitrate":"比特率" "bitrate": "比特率"
}, },
"tautulli":{ "tautulli": {
"playing":"玩", "playing": "玩",
"transcoding":"转码", "transcoding": "转码",
"bitrate":"比特率" "bitrate": "比特率"
}, },
"nzbget":{ "nzbget": {
"rate":"速度", "rate": "速度",
"remaining":"其余的", "remaining": "其余的",
"downloaded":"下载" "downloaded": "下载"
}, },
"rutorrent":{ "rutorrent": {
"active":"积极的", "active": "积极的",
"upload":"上传", "upload": "上传",
"download":"下载" "download": "下载"
}, },
"sonarr":{ "sonarr": {
"wanted":"通缉", "wanted": "通缉",
"queued":"排队", "queued": "排队",
"series":"系列" "series": "系列"
}, },
"radarr":{ "radarr": {
"wanted":"通缉", "wanted": "通缉",
"queued":"排队", "queued": "排队",
"movies":"电影" "movies": "电影"
}, },
"ombi":{ "ombi": {
"pending":"待办的", "pending": "待办的",
"approved":"得到正式认可的", "approved": "得到正式认可的",
"available":"可用的" "available": "可用的"
}, },
"jellyseerr":{ "jellyseerr": {
"pending":"待办的", "pending": "待办的",
"approved":"得到正式认可的", "approved": "得到正式认可的",
"available":"可用的" "available": "可用的"
}, },
"pihole":{ "pihole": {
"queries":"查询", "queries": "查询",
"blocked":"阻止", "blocked": "阻止",
"gravity":"重力" "gravity": "重力"
}, },
"speedtest":{ "speedtest": {
"upload":"上传", "upload": "上传",
"download":"下载", "download": "下载",
"ping":"ping" "ping": "ping"
}, },
"portainer":{ "portainer": {
"running":"跑步", "running": "跑步",
"stopped":"停了下来", "stopped": "停了下来",
"total":"全部的" "total": "全部的"
}, },
"traefik":{ "traefik": {
"routers":"路由器", "routers": "路由器",
"services":"服务", "services": "服务",
"middleware":"中间件" "middleware": "中间件"
}, },
"npm":{ "npm": {
"enabled":"已启用", "enabled": "已启用",
"disabled":"禁用", "disabled": "禁用",
"total":"全部的" "total": "全部的"
} },
"weather": {
"current": "Current Location",
"allow": "Click to allow",
"updating": "Updating",
"wait": "Please wait"
}
} }

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 }) { 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 useSWR from "swr";
import { useState } from "react";
import { BiError } from "react-icons/bi"; 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 { useTranslation } from "react-i18next";
import Icon from "./icon"; import Icon from "./icon";
export default function OpenWeatherMap({ options }) { function Widget({ options }) {
const { t, i18n } = useTranslation(); const { t, i18n } = useTranslation();
const { data, error } = useSWR( const { data, error } = useSWR(
`/api/widgets/openweathermap?${new URLSearchParams({ lang: i18n.language, ...options }).toString()}` `/api/widgets/openweathermap?${new URLSearchParams({ lang: i18n.language, ...options }).toString()}`
); );
if (error || data?.cod === 401) { if (error || data?.cod === 401 || data?.error) {
return ( 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-row items-center justify-end">
<div className="flex flex-col items-center"> <div className="flex flex-col items-center">
<BiError className="w-8 h-8 text-theme-800 dark:text-theme-200" /> <BiError className="w-8 h-8 text-theme-800 dark:text-theme-200" />
<div className="flex flex-col ml-3 text-left"> <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-sm">{t("widget.api_error")}</span>
<span className="text-theme-800 dark:text-theme-200 text-xs">Error</span> <span className="text-theme-800 dark:text-theme-200 text-xs">-</span>
</div> </div>
</div> </div>
</div> </div>
@@ -28,11 +31,19 @@ export default function OpenWeatherMap({ options }) {
} }
if (!data) { if (!data) {
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">
if (data.error) { <div className="flex flex-col items-center">
return <div className="flex flex-row 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"; const unit = options.units === "metric" ? "celsius" : "fahrenheit";
@@ -57,3 +68,55 @@ export default function OpenWeatherMap({ options }) {
</div> </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 useSWR from "swr";
import { useState } from "react";
import { BiError } from "react-icons/bi"; 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 { useTranslation } from "react-i18next";
import Icon from "./icon"; import Icon from "./icon";
export default function WeatherApi({ options }) { function Widget({ options }) {
const { t, i18n } = useTranslation(); const { t, i18n } = useTranslation();
const { data, error } = useSWR( const { data, error } = useSWR(
`/api/widgets/weather?${new URLSearchParams({ lang: i18n.language, ...options }).toString()}` `/api/widgets/weather?${new URLSearchParams({ lang: i18n.language, ...options }).toString()}`
); );
if (error) { if (error || data?.error) {
return ( 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-row items-center justify-end">
<div className="flex flex-col items-center"> <div className="flex flex-col items-center">
<BiError className="w-8 h-8 text-theme-800 dark:text-theme-200" /> <BiError className="w-8 h-8 text-theme-800 dark:text-theme-200" />
<div className="flex flex-col ml-3 text-left"> <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-sm">{t("widget.api_error")}</span>
<span className="text-theme-800 dark:text-theme-200 text-xs">Error</span> <span className="text-theme-800 dark:text-theme-200 text-xs">-</span>
</div> </div>
</div> </div>
</div> </div>
@@ -28,11 +31,19 @@ export default function WeatherApi({ options }) {
} }
if (!data) { if (!data) {
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">
if (data.error) { <div className="flex flex-col items-center">
return <div className="flex flex-row items-center justify-end" />; <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"; const unit = options.units === "metric" ? "celsius" : "fahrenheit";
@@ -58,3 +69,55 @@ export default function WeatherApi({ options }) {
</div> </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

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