From f25e675f7ffcbc8a3e51e10fe151f5e550ad420a Mon Sep 17 00:00:00 2001 From: Cooper Ransom Date: Mon, 1 Apr 2024 11:01:56 -0400 Subject: [PATCH] Increase silly text chance and replace backend url with env var --- src/hooks/useRandomTranslation.ts | 4 ++-- src/pages/TopFlix.tsx | 7 ++++--- src/pages/TopSources.tsx | 3 ++- src/pages/parts/admin/ConfigValuesPart.tsx | 5 +++-- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/hooks/useRandomTranslation.ts b/src/hooks/useRandomTranslation.ts index 4351ffad..50d78aee 100644 --- a/src/hooks/useRandomTranslation.ts +++ b/src/hooks/useRandomTranslation.ts @@ -1,8 +1,8 @@ import { useCallback, useMemo } from "react"; import { useTranslation } from "react-i18next"; -// 10% chance of getting a joke title -const shouldGiveJokeTitle = () => Math.floor(Math.random() * 10) === 0; +// 35% chance of getting a joke title (Cooper done changed this code!) +const shouldGiveJokeTitle = () => Math.random() < 0.35; export function useRandomTranslation() { const { t } = useTranslation(); diff --git a/src/pages/TopFlix.tsx b/src/pages/TopFlix.tsx index c621e9ec..a51b97d3 100644 --- a/src/pages/TopFlix.tsx +++ b/src/pages/TopFlix.tsx @@ -5,6 +5,7 @@ import { useNavigate } from "react-router-dom"; // Import Link from react-router import { ThiccContainer } from "@/components/layout/ThinContainer"; import { Divider } from "@/components/utils/Divider"; import { Heading1, Paragraph } from "@/components/utils/Text"; +import { BACKEND_URL } from "@/setup/constants"; import { SubPageLayout } from "./layouts/SubPageLayout"; import { PageTitle } from "./parts/util/PageTitle"; @@ -84,7 +85,7 @@ function ConfigValue(props: { } async function getRecentPlayedItems() { - const response = await fetch("https://backend.sudo-flix.lol/metrics"); + const response = await fetch(BACKEND_URL); const text = await response.text(); const regex = @@ -118,7 +119,7 @@ async function getRecentPlayedItems() { } async function getTotalViews() { - const response = await fetch("https://backend.sudo-flix.lol/metrics"); + const response = await fetch(BACKEND_URL); const text = await response.text(); // Add up all mw_media_watch_count entries @@ -138,7 +139,7 @@ async function getTotalViews() { } function getProcessStartTime(): Promise { - return fetch("https://backend.sudo-flix.lol/metrics") + return fetch(BACKEND_URL) .then((response) => response.text()) .then((text) => { const regex = /process_start_time_seconds (\d+)/; diff --git a/src/pages/TopSources.tsx b/src/pages/TopSources.tsx index 1913ef43..c631c4a7 100644 --- a/src/pages/TopSources.tsx +++ b/src/pages/TopSources.tsx @@ -4,6 +4,7 @@ import { useNavigate } from "react-router-dom"; import { ThiccContainer } from "@/components/layout/ThinContainer"; import { Divider } from "@/components/utils/Divider"; import { Heading1, Paragraph } from "@/components/utils/Text"; +import { BACKEND_URL } from "@/setup/constants"; import { SubPageLayout } from "./layouts/SubPageLayout"; import { PageTitle } from "./parts/util/PageTitle"; @@ -24,7 +25,7 @@ function ConfigValue(props: { name: string; children?: ReactNode }) { } async function getTopSources() { - const response = await fetch("https://backend.sudo-flix.lol/metrics"); + const response = await fetch(BACKEND_URL); const text = await response.text(); const regex = diff --git a/src/pages/parts/admin/ConfigValuesPart.tsx b/src/pages/parts/admin/ConfigValuesPart.tsx index dce783b2..ca3cb6d1 100644 --- a/src/pages/parts/admin/ConfigValuesPart.tsx +++ b/src/pages/parts/admin/ConfigValuesPart.tsx @@ -3,9 +3,10 @@ import { ReactNode, useEffect, useState } from "react"; import { Divider } from "@/components/utils/Divider"; import { Heading2 } from "@/components/utils/Text"; import { conf } from "@/setup/config"; +import { BACKEND_URL } from "@/setup/constants"; async function getAccountNumber() { - const response = await fetch("https://backend.sudo-flix.lol/metrics"); + const response = await fetch(BACKEND_URL); const text = await response.text(); // Adjusted regex to match any hostname @@ -26,7 +27,7 @@ async function getAccountNumber() { } async function getAllAccounts() { - const response = await fetch("https://backend.sudo-flix.lol/metrics"); + const response = await fetch(BACKEND_URL); const text = await response.text(); const regex = /mw_user_count{namespace="movie-web"} (\d+)/;