mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-10-01 15:48:23 -05:00
Zod validated config for security and ease of getting started
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import type { CacheEntry } from "@epic-web/cachified";
|
||||
import { ServerConfig } from "~/config.server";
|
||||
import { LRUCache } from "~/modules/cache";
|
||||
|
||||
declare global {
|
||||
@@ -11,8 +12,7 @@ export const cache = (global.__lruCache = global.__lruCache
|
||||
? global.__lruCache
|
||||
: new LRUCache<string, CacheEntry<unknown>>({ max: 5000 }));
|
||||
|
||||
export const ttl = (ms: number) =>
|
||||
process.env.DISABLE_CACHE === "true" ? 0 : ms;
|
||||
export const ttl = (ms: number) => (ServerConfig.disableCache ? 0 : ms);
|
||||
|
||||
export function syncCached<T>(key: string, getFreshValue: () => T) {
|
||||
if (cache.has(key)) {
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
sql,
|
||||
} from "kysely";
|
||||
import { jsonArrayFrom, jsonBuildObject } from "kysely/helpers/sqlite";
|
||||
import { Config } from "~/config";
|
||||
import type { DB, Tables } from "~/db/tables";
|
||||
import { IS_E2E_TEST_RUN } from "./e2e";
|
||||
|
||||
@@ -72,8 +73,7 @@ export function commonUserJsonObject(eb: ExpressionBuilder<Tables, "User">) {
|
||||
}
|
||||
|
||||
const USER_SUBMITTED_IMAGE_ROOT =
|
||||
(process.env.NODE_ENV === "development" &&
|
||||
import.meta.env.VITE_PROD_MODE !== "true") ||
|
||||
(process.env.NODE_ENV === "development" && !Config.prodMode) ||
|
||||
IS_E2E_TEST_RUN ||
|
||||
process.env.NODE_ENV === "test"
|
||||
? "http://127.0.0.1:9000/sendou"
|
||||
@@ -127,7 +127,7 @@ export function tournamentLogoWithDefault(
|
||||
"UnvalidatedUserSubmittedImage.id",
|
||||
)
|
||||
.$asScalar(),
|
||||
sql.lit(`${import.meta.env.VITE_TOURNAMENT_DEFAULT_LOGO}`),
|
||||
sql.lit(Config.tournamentDefaultLogo),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import type { Params, UIMatch } from "react-router";
|
||||
import { data, redirect } from "react-router";
|
||||
import type { z } from "zod";
|
||||
import type { navItems } from "~/components/layout/nav-items";
|
||||
import { ServerConfig } from "~/config.server";
|
||||
import { uploadStreamToS3 } from "~/features/img-upload/s3.server";
|
||||
import invariant from "./invariant";
|
||||
import { logger } from "./logger";
|
||||
@@ -224,8 +225,7 @@ const LOHI_TOKEN_HEADER_NAME = "Lohi-Token";
|
||||
|
||||
/** Some endpoints can only be accessed with an auth token. Used by Lohi bot and cron jobs. */
|
||||
export function canAccessLohiEndpoint(request: Request) {
|
||||
invariant(process.env.LOHI_TOKEN, "LOHI_TOKEN is required");
|
||||
return request.headers.get(LOHI_TOKEN_HEADER_NAME) === process.env.LOHI_TOKEN;
|
||||
return request.headers.get(LOHI_TOKEN_HEADER_NAME) === ServerConfig.lohiToken;
|
||||
}
|
||||
|
||||
function errorToastRedirect(message: string) {
|
||||
|
||||
Reference in New Issue
Block a user