Validate that bare servers can actually function and fix CSS.
This commit is contained in:
parent
26ff6820f0
commit
c2fe2b980f
7 changed files with 78 additions and 26 deletions
|
|
@ -75,5 +75,6 @@
|
||||||
"catppuccinFrappe": "Catppuccin Frappe",
|
"catppuccinFrappe": "Catppuccin Frappe",
|
||||||
"catppuccinLatte": "Catppuccin Latte"
|
"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."
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -74,5 +74,6 @@
|
||||||
"catppuccinFrappe": "Catppuccin Frappe",
|
"catppuccinFrappe": "Catppuccin Frappe",
|
||||||
"catppuccinLatte": "Catppuccin Latte"
|
"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."
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -74,5 +74,6 @@
|
||||||
"catppuccinFrappe": "Catppuccin Frappe",
|
"catppuccinFrappe": "Catppuccin Frappe",
|
||||||
"catppuccinLatte": "Catppuccin Latte"
|
"catppuccinLatte": "Catppuccin Latte"
|
||||||
},
|
},
|
||||||
"clipboard": "URL がクリップボードにコピーされました!"
|
"clipboard": "URL がクリップボードにコピーされました!",
|
||||||
|
"bareError": "それはうまくいきませんでした。Bare サーバーが存在し、ブロックされていないことを再確認してください。"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@ import { useState, useEffect } from "preact/hooks";
|
||||||
import { set } from "../../util/IDB";
|
import { set } from "../../util/IDB";
|
||||||
import { uninstallServiceWorkers } from "../../util/SWHelper";
|
import { uninstallServiceWorkers } from "../../util/SWHelper";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { ToastContainer, toast } from "react-toastify";
|
||||||
|
import { BareTest } from "./BareTest";
|
||||||
|
|
||||||
interface BareInputProps {
|
interface BareInputProps {
|
||||||
placeholder: string;
|
placeholder: string;
|
||||||
|
|
@ -31,26 +33,44 @@ function BareInput(props: BareInputProps) {
|
||||||
return finalUrl;
|
return finalUrl;
|
||||||
}
|
}
|
||||||
function handleChange() {
|
function handleChange() {
|
||||||
const url = validateUrl((document.getElementById("input") as HTMLInputElement).value);
|
const url = validateUrl(
|
||||||
setInputValue((document.getElementById("input") as HTMLInputElement).value);
|
(document.getElementById("input") as HTMLInputElement).value
|
||||||
set(props.storageKey, url);
|
);
|
||||||
localStorage.setItem(props.storageKey, url);
|
BareTest(url + "v3/").then((result) => {
|
||||||
uninstallServiceWorkers();
|
if (result) {
|
||||||
window.location.reload();
|
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 (
|
return (
|
||||||
<div className="flex flex-col items-center">
|
<div>
|
||||||
<input
|
<ToastContainer position="bottom-right" theme="dark" />
|
||||||
type="text"
|
<div className="flex flex-col items-center">
|
||||||
placeholder={props.placeholder}
|
<input
|
||||||
value={inputValue}
|
type="text"
|
||||||
id="input"
|
placeholder={props.placeholder}
|
||||||
className="font-roboto flex h-14 w-56 flex-row rounded-2xl border border-input-border-color bg-input p-4 text-center text-xl"
|
value={inputValue}
|
||||||
/>
|
id="input"
|
||||||
<div className="font-roboto items-center justify-center flex h-4 w-24 flex-row rounded-2xl border border-input-border-color bg-input p-4 text-center text-xl"
|
className="font-roboto flex h-14 w-56 flex-row rounded-2xl border border-input-border-color bg-input p-4 text-center text-xl"
|
||||||
onClick={handleChange}
|
/>
|
||||||
>
|
<div
|
||||||
{t("settings.bare.select")}
|
className="font-roboto mt-2 flex h-4 w-36 cursor-pointer flex-row items-center justify-center rounded-xl border border-input-border-color bg-input p-5 text-center text-lg"
|
||||||
|
onClick={handleChange}
|
||||||
|
>
|
||||||
|
{t("settings.bare.select")}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
|
||||||
29
src/pages/Settings/BareTest.tsx
Normal file
29
src/pages/Settings/BareTest.tsx
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
export function BareTest(bareUrl) {
|
||||||
|
const headers = new Headers({
|
||||||
|
"x-bare-url": "https://www.google.com",
|
||||||
|
"X-Bare-Headers": JSON.stringify({
|
||||||
|
Accept:
|
||||||
|
"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
return fetch(bareUrl, {
|
||||||
|
method: "GET",
|
||||||
|
headers: headers
|
||||||
|
})
|
||||||
|
.then((response) => {
|
||||||
|
if (
|
||||||
|
response.headers.get("x-bare-status") === "200" ||
|
||||||
|
response.headers.get("x-bare-status") === "302"
|
||||||
|
) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
// the site is a real site but doesn't act like a bare server
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
// incase the site doesn't exist
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
@ -27,7 +27,7 @@ function Customization({ id, active }) {
|
||||||
variants={settingsPageVariant}
|
variants={settingsPageVariant}
|
||||||
className="content-card flex w-full flex-col items-center justify-center text-center"
|
className="content-card flex w-full flex-col items-center justify-center text-center"
|
||||||
>
|
>
|
||||||
<div className="flex h-64 w-80 flex-col flex-wrap content-center items-center rounded-lg border border-input-border-color bg-lighter p-7 text-center">
|
<div className="flex h-64 w-80 flex-col flex-wrap content-center items-center rounded-lg border border-input-border-color bg-lighter p-2 text-center">
|
||||||
<div className="p-2 text-3xl font-bold text-input-text">
|
<div className="p-2 text-3xl font-bold text-input-text">
|
||||||
{t("settings.theme.title")}
|
{t("settings.theme.title")}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ const Proxy = ({ id, active }) => {
|
||||||
variants={settingsPageVariant}
|
variants={settingsPageVariant}
|
||||||
className="content-card flex w-full flex-row flex-wrap justify-center gap-4"
|
className="content-card flex w-full flex-row flex-wrap justify-center gap-4"
|
||||||
>
|
>
|
||||||
<div className="flex h-64 w-80 flex-col flex-wrap content-center items-center rounded-lg border border-input-border-color bg-lighter p-4 text-center">
|
<div className="flex h-64 w-80 flex-col flex-wrap content-center items-center rounded-lg border border-input-border-color bg-lighter p-2 text-center">
|
||||||
<div className="p-2 text-3xl font-bold text-input-text">
|
<div className="p-2 text-3xl font-bold text-input-text">
|
||||||
{t("settings.proxy.title")}
|
{t("settings.proxy.title")}
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -48,7 +48,7 @@ const Proxy = ({ id, active }) => {
|
||||||
</div>
|
</div>
|
||||||
<Dropdown storageKey="proxy" options={engines} refresh={false} />
|
<Dropdown storageKey="proxy" options={engines} refresh={false} />
|
||||||
</div>
|
</div>
|
||||||
<div className="flex h-64 w-80 flex-col flex-wrap content-center items-center rounded-lg border border-input-border-color bg-lighter p-4 text-center">
|
<div className="flex h-64 w-80 flex-col flex-wrap content-center items-center rounded-lg border border-input-border-color bg-lighter p-2 text-center">
|
||||||
<div className="p-2 text-3xl font-bold text-input-text">
|
<div className="p-2 text-3xl font-bold text-input-text">
|
||||||
{t("settings.proxymodes.title")}
|
{t("settings.proxymodes.title")}
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -61,7 +61,7 @@ const Proxy = ({ id, active }) => {
|
||||||
refresh={false}
|
refresh={false}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex h-64 w-80 flex-col flex-wrap content-center items-center rounded-lg border border-input-border-color bg-lighter p-4 text-center">
|
<div className="flex h-64 w-80 flex-col flex-wrap content-center items-center rounded-lg border border-input-border-color bg-lighter p-2 text-center">
|
||||||
<div className="p-2 text-3xl font-bold text-input-text">
|
<div className="p-2 text-3xl font-bold text-input-text">
|
||||||
{t("settings.search.title")}
|
{t("settings.search.title")}
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -74,7 +74,7 @@ const Proxy = ({ id, active }) => {
|
||||||
refresh={false}
|
refresh={false}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex h-64 w-80 flex-col flex-wrap content-center items-center rounded-lg border border-input-border-color bg-lighter p-4 text-center">
|
<div className="flex h-64 w-80 flex-col flex-wrap content-center items-center rounded-lg border border-input-border-color bg-lighter p-2 text-center">
|
||||||
<div className="p-2 text-3xl font-bold text-input-text">
|
<div className="p-2 text-3xl font-bold text-input-text">
|
||||||
{t("settings.bare.title")}
|
{t("settings.bare.title")}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue