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
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

@@ -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

@@ -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

@@ -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 || "/"),
});