From c2fe2b980f63a816c9ad0541343fa047e7072d67 Mon Sep 17 00:00:00 2001 From: rift <117926989+Riftriot@users.noreply.github.com> Date: Sun, 7 Jan 2024 16:59:28 -0600 Subject: [PATCH] Validate that bare servers can actually function and fix CSS. --- src/locales/en.json | 3 +- src/locales/es.json | 3 +- src/locales/ja.json | 3 +- src/pages/Settings/BareInput.tsx | 56 +++++++++++++++++++--------- src/pages/Settings/BareTest.tsx | 29 ++++++++++++++ src/pages/Settings/Customization.tsx | 2 +- src/pages/Settings/Proxy.tsx | 8 ++-- 7 files changed, 78 insertions(+), 26 deletions(-) create mode 100644 src/pages/Settings/BareTest.tsx diff --git a/src/locales/en.json b/src/locales/en.json index 1371fcf..75a052d 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -75,5 +75,6 @@ "catppuccinFrappe": "Catppuccin Frappe", "catppuccinLatte": "Catppuccin Latte" }, - "clipboard": "URL copied to clipboard!" + "clipboard": "URL copied to clipboard!", + "bareError": "That didn't quite work. Double check that the bare server exists and isn't blocked." } diff --git a/src/locales/es.json b/src/locales/es.json index 3a4dfb1..bc61258 100644 --- a/src/locales/es.json +++ b/src/locales/es.json @@ -74,5 +74,6 @@ "catppuccinFrappe": "Catppuccin Frappe", "catppuccinLatte": "Catppuccin Latte" }, - "clipboard": "¡URL copiada al portapapeles!" + "clipboard": "¡URL copiada al portapapeles!", + "bareError": "Esto no es funcional. Vuelva a verificar que el servidor bare exista y no esté bloqueado." } diff --git a/src/locales/ja.json b/src/locales/ja.json index 6527cc4..c929ba5 100644 --- a/src/locales/ja.json +++ b/src/locales/ja.json @@ -74,5 +74,6 @@ "catppuccinFrappe": "Catppuccin Frappe", "catppuccinLatte": "Catppuccin Latte" }, - "clipboard": "URL がクリップボードにコピーされました!" + "clipboard": "URL がクリップボードにコピーされました!", + "bareError": "それはうまくいきませんでした。Bare サーバーが存在し、ブロックされていないことを再確認してください。" } diff --git a/src/pages/Settings/BareInput.tsx b/src/pages/Settings/BareInput.tsx index 4a46769..17364f0 100644 --- a/src/pages/Settings/BareInput.tsx +++ b/src/pages/Settings/BareInput.tsx @@ -2,6 +2,8 @@ import { useState, useEffect } from "preact/hooks"; import { set } from "../../util/IDB"; import { uninstallServiceWorkers } from "../../util/SWHelper"; import { useTranslation } from "react-i18next"; +import { ToastContainer, toast } from "react-toastify"; +import { BareTest } from "./BareTest"; interface BareInputProps { placeholder: string; @@ -31,26 +33,44 @@ function BareInput(props: BareInputProps) { return finalUrl; } function handleChange() { - const url = validateUrl((document.getElementById("input") as HTMLInputElement).value); - setInputValue((document.getElementById("input") as HTMLInputElement).value); - set(props.storageKey, url); - localStorage.setItem(props.storageKey, url); - uninstallServiceWorkers(); - window.location.reload(); + const url = validateUrl( + (document.getElementById("input") as HTMLInputElement).value + ); + BareTest(url + "v3/").then((result) => { + if (result) { + setInputValue( + (document.getElementById("input") as HTMLInputElement).value + ); + set(props.storageKey, url); + localStorage.setItem(props.storageKey, url); + uninstallServiceWorkers(); + window.location.reload(); + } else { + (document.getElementById("input") as HTMLInputElement).value = + localStorage.getItem("bare") || "/bare/"; + toast(t("bareError"), { + type: "error" + }); + } + }); } return ( -