-
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #677 from gnmyt/features/multiple-providers
🗃️ Support für LibreSpeed & Cloudflare Speed
- Loading branch information
Showing
30 changed files
with
820 additions
and
184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
138 changes: 138 additions & 0 deletions
138
client/src/common/components/ProviderDialog/ProviderDialog.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
import {DialogContext, DialogProvider} from "@/common/contexts/Dialog"; | ||
import {t} from "i18next"; | ||
import {FontAwesomeIcon} from "@fortawesome/react-fontawesome"; | ||
import {faClose} from "@fortawesome/free-solid-svg-icons"; | ||
import "./styles.sass"; | ||
import React, {useContext, useEffect, useState} from "react"; | ||
import OoklaImage from "./assets/img/ookla.webp"; | ||
import LibreImage from "./assets/img/libre.webp"; | ||
import CloudflareImage from "./assets/img/cloudflare.webp"; | ||
import {jsonRequest, patchRequest} from "@/common/utils/RequestUtil"; | ||
import {Trans} from "react-i18next"; | ||
import {ConfigContext} from "@/common/contexts/Config"; | ||
|
||
const providers = [ | ||
{id: "ookla", name: "Ookla", image: OoklaImage}, | ||
{id: "libre", name: "LibreSpeed", image: LibreImage}, | ||
{id: "cloudflare", name: "Cloudflare", image: CloudflareImage} | ||
] | ||
|
||
|
||
export const Dialog = () => { | ||
const close = useContext(DialogContext); | ||
const [config, reloadConfig] = useContext(ConfigContext); | ||
const [provider, setProvider] = useState(config.provider || "ookla"); | ||
|
||
const [licenseAccepted, setLicenseAccepted] = useState(false); | ||
const [licenseError, setLicenseError] = useState(false); | ||
|
||
const [ooklaServers, setOoklaServers] = useState({}); | ||
const [libreServers, setLibreServers] = useState({}); | ||
|
||
const [serverId, setServerId] = useState("none"); | ||
|
||
useEffect(() => { | ||
jsonRequest("/info/server/ookla").then((response) => { | ||
setOoklaServers(response); | ||
}); | ||
jsonRequest("/info/server/libre").then((response) => { | ||
setLibreServers(response); | ||
}); | ||
}, []); | ||
|
||
useEffect(() => { | ||
if (config[provider + "Id"]) setServerId(config[provider + "Id"]); | ||
}, [provider]); | ||
|
||
useEffect(() => { | ||
if (serverId === "") setServerId("none"); | ||
}, [serverId]); | ||
|
||
const update = async () => { | ||
if (provider === "ookla" && !licenseAccepted) { | ||
setLicenseError(true); | ||
return; | ||
} | ||
|
||
await patchRequest("/config/provider", {value: provider}); | ||
|
||
if (serverId !== config[provider + "Id"] && provider !== "cloudflare") { | ||
await patchRequest("/config/" + provider + "Id", {value: serverId}); | ||
} | ||
|
||
reloadConfig(); | ||
|
||
close(); | ||
} | ||
|
||
return ( | ||
<> | ||
<div className="dialog-header"> | ||
<h4 className="dialog-text">{t("update.provider_title")}</h4> | ||
<FontAwesomeIcon icon={faClose} className="dialog-text dialog-icon" onClick={() => close()}/> | ||
</div> | ||
<div className="provider-dialog-content"> | ||
<div className="provider-header"> | ||
{providers.map((current, index) => ( | ||
<div className={`provider-item ${current.id === provider ? "provider-item-active" : ""}`} | ||
key={index} onClick={() => setProvider(current.id)}> | ||
<img src={current.image} alt={current.name}/> | ||
<h3>{current.name}</h3> | ||
</div> | ||
))} | ||
</div> | ||
{provider !== "cloudflare" && <div className="provider-content"> | ||
<div className="provider-setting"> | ||
<h3>{t("dialog.provider.server")}</h3> | ||
<select className="dialog-input provider-input" value={serverId} | ||
onChange={(e) => setServerId(e.target.value)}> | ||
<option value="none">{t("dialog.provider.choose_automatically")}</option> | ||
{provider === "ookla" && Object.keys(ooklaServers).map((current, index) => ( | ||
<option key={index} value={current}>{ooklaServers[current]}</option> | ||
))} | ||
{provider === "libre" && Object.keys(libreServers).map((current, index) => ( | ||
<option key={index} value={current}>{libreServers[current]}</option> | ||
))} | ||
</select> | ||
</div> | ||
<div className="provider-setting"> | ||
<h3>{t("dialog.provider.server_id")}</h3> | ||
<input type="text" className="dialog-input provider-input" value={serverId === "none" ? "" : serverId} | ||
onChange={(e) => setServerId(e.target.value)}/> | ||
</div> | ||
</div>} | ||
{provider === "cloudflare" && <div className="provider-content"> | ||
<p className="cloudflare-provider-info">{t("dialog.provider.cloudflare_note")}</p> | ||
</div>} | ||
</div> | ||
<div className="provider-dialog-footer"> | ||
<div className="provider-license-box"> | ||
{provider === "ookla" && <> | ||
<input type="checkbox" className={licenseError ? "cb-error" : ""} id="license" name="license" | ||
onChange={(e) => setLicenseAccepted(e.target.checked)}/> | ||
<label htmlFor="license" | ||
><Trans components={{ | ||
Eula: <a href="https://www.speedtest.net/about/eula" target="_blank" | ||
rel="noreferrer" />, | ||
GDPR: <a href="https://www.speedtest.net/about/privacy" target="_blank" | ||
rel="noreferrer" />, | ||
TOS: <a href="https://www.speedtest.net/about/terms" target="_blank" | ||
rel="noreferrer" />}}>dialog.provider.ookla_license</Trans></label> | ||
</>} | ||
</div> | ||
|
||
<button className="dialog-btn" onClick={update}>{t("dialog.update")}</button> | ||
</div> | ||
</> | ||
) | ||
} | ||
|
||
export const ProviderDialog = (props) => { | ||
return ( | ||
<> | ||
<DialogProvider close={props.onClose}> | ||
<Dialog/> | ||
</DialogProvider> | ||
</> | ||
) | ||
} |
Binary file added
BIN
+2.31 KB
client/src/common/components/ProviderDialog/assets/img/cloudflare.webp
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export {ProviderDialog as default} from "./ProviderDialog"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
@import "@/common/styles/colors" | ||
|
||
.provider-dialog-content | ||
display: flex | ||
margin: 1rem 0.5rem | ||
user-select: none | ||
flex-direction: column | ||
|
||
.provider-header | ||
display: flex | ||
gap: 1rem | ||
|
||
.provider-item | ||
display: flex | ||
align-items: center | ||
padding: 0.3rem 0.5rem | ||
gap: 0.5rem | ||
border-radius: 0.8rem | ||
border: 2px solid $light-gray | ||
color: $darker-white | ||
cursor: pointer | ||
|
||
img | ||
width: 2.5rem | ||
height: 2.5rem | ||
|
||
h3 | ||
margin: 0 | ||
|
||
&:hover | ||
background-color: $darker-gray | ||
|
||
.provider-item-active | ||
background-color: $light-gray | ||
|
||
&:hover | ||
background-color: $light-gray | ||
|
||
.provider-content | ||
display: flex | ||
flex-direction: column | ||
margin-top: 1rem | ||
|
||
|
||
.provider-setting | ||
display: flex | ||
gap: 1rem | ||
align-items: center | ||
justify-content: space-between | ||
|
||
.provider-input | ||
width: 20rem | ||
box-sizing: border-box | ||
margin-top: 0.5rem | ||
margin-bottom: 0.5rem | ||
font-size: 1.3rem | ||
|
||
h3 | ||
color: $darker-white | ||
|
||
.cloudflare-provider-info | ||
color: $subtext | ||
text-align: center | ||
|
||
.provider-dialog-footer | ||
display: flex | ||
align-items: center | ||
justify-content: space-between | ||
|
||
.provider-license-box | ||
display: flex | ||
align-items: center | ||
gap: 0.5rem | ||
|
||
input | ||
border: 2px solid $light-gray | ||
|
||
.cb-error | ||
border-color: $red | ||
|
||
label | ||
color: $subtext | ||
max-width: 16rem | ||
flex: 1 | ||
|
||
|
||
@media screen and (max-width: 610px) | ||
.provider-dialog-content | ||
.provider-header | ||
flex-direction: column | ||
|
||
@media screen and (max-width: 520px) | ||
.provider-dialog-content | ||
.provider-setting .provider-input | ||
width: 60% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.