From 5ebde6cfc511cb87cb73c130b17c4c6dceb37607 Mon Sep 17 00:00:00 2001 From: Matin Dehghanian Date: Fri, 6 Dec 2024 20:56:14 +0330 Subject: [PATCH] Refactor environment variable handling and enhance UserBox component with subscription link adjustments --- .env.example | 20 ++++++---- src/App.jsx | 80 ++++++++++++++++++++++--------------- src/components/UserBox.jsx | 81 +++++++++++++++++++++----------------- 3 files changed, 106 insertions(+), 75 deletions(-) diff --git a/.env.example b/.env.example index e750f2a..b834c28 100644 --- a/.env.example +++ b/.env.example @@ -1,11 +1,17 @@ -# Application Information +### Customization +# Brand Name VITE_BRAND_NAME=Ourenus +# Brand Logo URL VITE_LOGO_SRC=https://raw.githubusercontent.com/MatinDehghanian/public-assets/refs/heads/main/icons/uranus.svg - -# URLs -VITE_PANEL_DOMAIN=https://panel.example.com:8000 -VITE_JSON_APPS_URL=https://raw.githubusercontent.com/MatinDehghanian/public-assets/refs/heads/main/json/os.json +# Support URL VITE_SUPPORT_URL=https://t.me/YourID - # Feature Toggles -VITE_OFF_SECTIONS={"appsBox": true, "logoBox": true, "timeBox": true, "usageBox": true, "userBox": true, "supportBox": true, "configs": true} \ No newline at end of file +VITE_OFF_SECTIONS={"appsBox": true, "logoBox": true, "timeBox": true, "usageBox": true, "userBox": true, "supportBox": true, "configs": true} +# Apps JSON URL +VITE_JSON_APPS_URL=https://raw.githubusercontent.com/MatinDehghanian/public-assets/refs/heads/main/json/os.json + +### Host Settings +# Host URL +VITE_PANEL_DOMAIN=https://panel.example.com:8000 +# Is Host +VITE_IS_HOST=false \ No newline at end of file diff --git a/src/App.jsx b/src/App.jsx index 9abc031..acd5354 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -66,43 +66,52 @@ function App() { } }, [data?.links]); - const url = data?.subscription_url?.includes("https://") - ? data?.subscription_url - : `${window.location.origin}${data?.subscription_url}`; + const getAdjustedUrl = (subURL) => { + if (import.meta.env.VITE_IS_HOST) { + return subURL.replace( + /https?:\/\/[^/]+/, + import.meta.env.VITE_PANEL_DOMAIN + ); + } else if (subURL?.includes("https://")) { + return subURL; + } + + return `${window.location.origin}${subURL}`; + }; const title = data?.username ? `${data.username} Sub Info` : `${import.meta.env.VITE_BRAND_NAME || "Ourenus"} Sub Info`; - const isOffSections = useMemo(() => { - try { - const envValue = import.meta.env.VITE_OFF_SECTIONS; - if (envValue) { - return JSON.parse(envValue); - } - return { - appsBox: true, - logoBox: true, - timeBox: true, - usageBox: true, - userBox: true, - supportBox: true, - configs: true, - }; - } catch (error) { - console.error("Failed to parse VITE_OFF_SECTIONS:", error); - return { - appsBox: true, - logoBox: true, - timeBox: true, - usageBox: true, - userBox: true, - supportBox: true, - configs: true, - }; + const isOffSections = useMemo(() => { + try { + const envValue = import.meta.env.VITE_OFF_SECTIONS; + if (envValue) { + return JSON.parse(envValue); } - }, []); + return { + appsBox: true, + logoBox: true, + timeBox: true, + usageBox: true, + userBox: true, + supportBox: true, + configs: true, + }; + } catch (error) { + console.error("Failed to parse VITE_OFF_SECTIONS:", error); + return { + appsBox: true, + logoBox: true, + timeBox: true, + usageBox: true, + userBox: true, + supportBox: true, + configs: true, + }; + } + }, []); return ( @@ -144,7 +153,12 @@ function App() { handleLanguageChange={handleLanguageChange} /> {isOffSections.logoBox && } - {isOffSections.userBox && } + {isOffSections.userBox && ( + + )} {isOffSections.usageBox && ( )} - {isOffSections.appsBox && } + {isOffSections.appsBox && ( + + )} {isOffSections.configs && ( { +const UserBox = ({ data, subLink }) => { const theme = useTheme(); const { t } = useTranslation(); @@ -72,20 +72,16 @@ const UserBox = ({ data }) => { setOpenQrModal(false); }; - const SubUrl = data?.subscription_url?.includes("https://") - ? data?.subscription_url - : `${window.location.origin}${data?.subscription_url}`; - useEffect(() => { - setQrLink(SubUrl); - }, [SubUrl]); + setQrLink(subLink); + }, [subLink]); return ( <> { { - - + + - - - + {import.meta.env.VITE_SUPPORT_URL && ( + + + + )}