Add env vars type

This commit is contained in:
Liam 2022-10-26 19:57:43 +01:00
parent 8ef4128b45
commit 566aebd8a4
5 changed files with 32 additions and 10 deletions

17
src/consts/EnvVars.ts Normal file

@ -0,0 +1,17 @@
type Vars = {
HTTP_PROXY: string;
SITE_NAME: string;
SITE_TITLE: string;
SITE_DESCRIPTION: string;
SITE_COLOR: string;
SITE_URL: string;
};
export const VARS: Vars = {
HTTP_PROXY: "HTTP_PROXY",
SITE_NAME: "SITE_NAME",
SITE_TITLE: "SITE_TITLE",
SITE_DESCRIPTION: "SITE_DESCRIPTION",
SITE_COLOR: "SITE_COLOR",
SITE_URL: "SITE_URL",
};

@ -1,10 +1,11 @@
import env from "@beam-australia/react-env"; import env from "@beam-australia/react-env";
import { VARS } from "./EnvVars";
const WebsiteTypes = { const WebsiteTypes = {
ScoreSaber: { ScoreSaber: {
ApiUrl: { ApiUrl: {
PlayerData: PlayerData:
env("HTTP_PROXY") + "/https://scoresaber.com/api/player/%s/basic", env(VARS.HTTP_PROXY) + "/https://scoresaber.com/api/player/%s/basic",
MapData: MapData:
"https://scoresaber.com/api/leaderboard/by-hash/%h/info?difficulty=%d", "https://scoresaber.com/api/leaderboard/by-hash/%h/info?difficulty=%d",
}, },
@ -18,7 +19,8 @@ const WebsiteTypes = {
}, },
BeatLeader: { BeatLeader: {
ApiUrl: { ApiUrl: {
PlayerData: env("HTTP_PROXY") + "/https://api.beatleader.xyz/player/%s", PlayerData:
env(VARS.HTTP_PROXY) + "/https://api.beatleader.xyz/player/%s",
MapData: "https://api.beatleader.xyz/map/hash/%h", MapData: "https://api.beatleader.xyz/map/hash/%h",
}, },
async getMapStarCount(mapHash, mapDiff, characteristic) { async getMapStarCount(mapHash, mapDiff, characteristic) {

@ -1,9 +1,10 @@
import env from "@beam-australia/react-env"; import env from "@beam-australia/react-env";
import { VARS } from "../consts/EnvVars";
import { BeatSaverMapData } from "../types/BeatSaverMapData"; import { BeatSaverMapData } from "../types/BeatSaverMapData";
import { getValue, setValue, valueExists } from "../utils/redisUtils"; import { getValue, setValue, valueExists } from "../utils/redisUtils";
const BEATSAVER_MAP_API = const BEATSAVER_MAP_API =
env("HTTP_PROXY") + "/https://api.beatsaver.com/maps/hash/%s"; env(VARS.HTTP_PROXY) + "/https://api.beatsaver.com/maps/hash/%s";
const KEY = "BS_MAP_DATA_"; const KEY = "BS_MAP_DATA_";

@ -2,6 +2,7 @@ import env from "@beam-australia/react-env";
import { createTheme, NextUIProvider } from "@nextui-org/react"; import { createTheme, NextUIProvider } from "@nextui-org/react";
import { DefaultSeo } from "next-seo"; import { DefaultSeo } from "next-seo";
import { ThemeProvider as NextThemesProvider } from "next-themes"; import { ThemeProvider as NextThemesProvider } from "next-themes";
import { VARS } from "../consts/EnvVars";
import "../styles/globals.css"; import "../styles/globals.css";
const lightTheme = createTheme({ const lightTheme = createTheme({
@ -22,13 +23,13 @@ function MyApp({ Component, pageProps }) {
return ( return (
<> <>
<DefaultSeo <DefaultSeo
titleTemplate={`${env("SITE_NAME")} | %s`} titleTemplate={`${env(VARS.SITE_NAME)} | %s`}
description={env("SITE_DESCRIPTION}")} description={env(VARS.SITE_DESCRIPTION)}
openGraph={{ openGraph={{
url: env("SITE_URL"), url: env(VARS.SITE_URL),
title: env("SITE_NAME"), title: env(VARS.SITE_NAME),
description: env("SITE_DESCRIPTION"), description: env(VARS.SITE_DESCRIPTION),
site_name: env("SITE_NAME"), site_name: env(VARS.SITE_NAME),
images: [ images: [
{ {
url: "https://cdn.fascinated.cc/fHknFPctAC.png?raw=true", url: "https://cdn.fascinated.cc/fHknFPctAC.png?raw=true",

@ -2,6 +2,7 @@ import env from "@beam-australia/react-env";
import { CssBaseline, Image } from "@nextui-org/react"; import { CssBaseline, Image } from "@nextui-org/react";
import Document, { Head, Html, Main, NextScript } from "next/document"; import Document, { Head, Html, Main, NextScript } from "next/document";
import React from "react"; import React from "react";
import { VARS } from "../consts/EnvVars";
class MyDocument extends Document { class MyDocument extends Document {
static async getInitialProps(ctx) { static async getInitialProps(ctx) {
@ -29,7 +30,7 @@ class MyDocument extends Document {
/> />
<link rel="shortcut icon" href="/favicon.ico" /> <link rel="shortcut icon" href="/favicon.ico" />
<meta name="theme-color" content={"#" + env("SITE_COLOR")} /> <meta name="theme-color" content={"#" + env(VARS.SITE_COLOR)} />
<meta <meta
property="og:keywords" property="og:keywords"
content="BeatSaber,Overlay,OBS,Twitch,YouTube,BeatSaber Overlay,Github," content="BeatSaber,Overlay,OBS,Twitch,YouTube,BeatSaber Overlay,Github,"