From 452a58a74ac93ecb3e73eef4e895be94282bea67 Mon Sep 17 00:00:00 2001 From: hailin Date: Wed, 25 Jun 2025 17:51:30 +0800 Subject: [PATCH] . --- chatdesk-ui/app/[locale]/login/page.tsx | 2 +- chatdesk-ui/app/api/chat/custom/route.ts | 2 +- chatdesk-ui/app/api/retrieval/process/docx/route.ts | 2 +- chatdesk-ui/app/api/retrieval/process/route.ts | 2 +- chatdesk-ui/app/api/retrieval/retrieve/route.ts | 2 +- chatdesk-ui/app/api/username/available/route.ts | 2 +- chatdesk-ui/app/api/username/get/route.ts | 2 +- chatdesk-ui/components/chat/chat-helpers/index.ts | 2 +- chatdesk-ui/lib/runtime-env/client.ts | 2 +- chatdesk-ui/lib/runtime-env/index.ts | 10 ++++++++++ chatdesk-ui/lib/runtime-env/server.ts | 3 ++- chatdesk-ui/lib/server/server-chat-helpers.ts | 2 +- chatdesk-ui/lib/supabase/client.ts | 2 +- 13 files changed, 23 insertions(+), 12 deletions(-) create mode 100644 chatdesk-ui/lib/runtime-env/index.ts diff --git a/chatdesk-ui/app/[locale]/login/page.tsx b/chatdesk-ui/app/[locale]/login/page.tsx index 9342ffd..d103d66 100644 --- a/chatdesk-ui/app/[locale]/login/page.tsx +++ b/chatdesk-ui/app/[locale]/login/page.tsx @@ -9,7 +9,7 @@ import { Metadata } from "next" import { cookies, headers } from "next/headers" import { redirect } from "next/navigation" //import { getRuntimeEnv } from "@/lib/ipconfig" // 新增引入 -import { getRuntimeEnv } from "@/lib/get-runtime-env" // ✅ 新路径 +import { getRuntimeEnv } from "@/lib/runtime-env" import { PostgrestError } from '@supabase/supabase-js'; import initTranslations from "@/lib/i18n"; diff --git a/chatdesk-ui/app/api/chat/custom/route.ts b/chatdesk-ui/app/api/chat/custom/route.ts index 1a28c11..fdefc60 100644 --- a/chatdesk-ui/app/api/chat/custom/route.ts +++ b/chatdesk-ui/app/api/chat/custom/route.ts @@ -6,7 +6,7 @@ import { ServerRuntime } from "next" import OpenAI from "openai" import { ChatCompletionCreateParamsBase } from "openai/resources/chat/completions.mjs" //import { getRuntimeEnv } from "@/lib/ipconfig" // 新增引入 -import { getRuntimeEnv } from "@/lib/get-runtime-env" // ✅ 新路径 +import { getRuntimeEnv } from "@/lib/runtime-env" export const runtime: ServerRuntime = "edge" diff --git a/chatdesk-ui/app/api/retrieval/process/docx/route.ts b/chatdesk-ui/app/api/retrieval/process/docx/route.ts index e151f5c..a13a76c 100644 --- a/chatdesk-ui/app/api/retrieval/process/docx/route.ts +++ b/chatdesk-ui/app/api/retrieval/process/docx/route.ts @@ -7,7 +7,7 @@ import { createClient } from "@supabase/supabase-js" import { NextResponse } from "next/server" import OpenAI from "openai" //import { getRuntimeEnv } from "@/lib/ipconfig" // 新增引入 -import { getRuntimeEnv } from "@/lib/get-runtime-env" // ✅ 新路径 +import { getRuntimeEnv } from "@/lib/runtime-env" import { generateBgeM3Embedding } from "@/lib/generate-bgem3-embedding" export async function POST(req: Request) { diff --git a/chatdesk-ui/app/api/retrieval/process/route.ts b/chatdesk-ui/app/api/retrieval/process/route.ts index 528f740..c41a5ab 100644 --- a/chatdesk-ui/app/api/retrieval/process/route.ts +++ b/chatdesk-ui/app/api/retrieval/process/route.ts @@ -14,7 +14,7 @@ import { createClient } from "@supabase/supabase-js" import { NextResponse } from "next/server" import OpenAI from "openai" //import { getRuntimeEnv } from "@/lib/ipconfig" // 新增引入 -import { getRuntimeEnv } from "@/lib/get-runtime-env" // ✅ 新路径 +import { getRuntimeEnv } from "@/lib/runtime-env" export async function POST(req: Request) { diff --git a/chatdesk-ui/app/api/retrieval/retrieve/route.ts b/chatdesk-ui/app/api/retrieval/retrieve/route.ts index e0019b5..32c5bac 100644 --- a/chatdesk-ui/app/api/retrieval/retrieve/route.ts +++ b/chatdesk-ui/app/api/retrieval/retrieve/route.ts @@ -5,7 +5,7 @@ import { Database } from "@/supabase/types" import { createClient } from "@supabase/supabase-js" import OpenAI from "openai" //import { getRuntimeEnv } from "@/lib/ipconfig" // 新增引入 -import { getRuntimeEnv } from "@/lib/get-runtime-env" // ✅ 新路径 +import { getRuntimeEnv } from "@/lib/runtime-env" export async function POST(request: Request) { diff --git a/chatdesk-ui/app/api/username/available/route.ts b/chatdesk-ui/app/api/username/available/route.ts index 1b17527..c13fb2c 100644 --- a/chatdesk-ui/app/api/username/available/route.ts +++ b/chatdesk-ui/app/api/username/available/route.ts @@ -1,7 +1,7 @@ import { Database } from "@/supabase/types" import { createClient } from "@supabase/supabase-js" //import { getRuntimeEnv } from "@/lib/ipconfig" // 新增引入 -import { getRuntimeEnv } from "@/lib/get-runtime-env" // ✅ 新路径 +import { getRuntimeEnv } from "@/lib/runtime-env" export const runtime = "edge" diff --git a/chatdesk-ui/app/api/username/get/route.ts b/chatdesk-ui/app/api/username/get/route.ts index 4f81b01..c44d183 100644 --- a/chatdesk-ui/app/api/username/get/route.ts +++ b/chatdesk-ui/app/api/username/get/route.ts @@ -1,7 +1,7 @@ import { Database } from "@/supabase/types" import { createClient } from "@supabase/supabase-js" //import { getRuntimeEnv } from "@/lib/ipconfig" // 新增引入 -import { getRuntimeEnv } from "@/lib/get-runtime-env" // ✅ 新路径 +import { getRuntimeEnv } from "@/lib/runtime-env" export const runtime = "edge" diff --git a/chatdesk-ui/components/chat/chat-helpers/index.ts b/chatdesk-ui/components/chat/chat-helpers/index.ts index 8ede441..0e96b91 100644 --- a/chatdesk-ui/components/chat/chat-helpers/index.ts +++ b/chatdesk-ui/components/chat/chat-helpers/index.ts @@ -23,7 +23,7 @@ import React from "react" import { toast } from "sonner" import { v4 as uuidv4 } from "uuid" //import { getRuntimeEnv } from "@/lib/ipconfig" -import { getRuntimeEnv } from "@/lib/get-runtime-env" // ✅ 新路径 +import { getRuntimeEnv } from "@/lib/runtime-env" type RetrievedFileItem = Tables<"file_items"> & { diff --git a/chatdesk-ui/lib/runtime-env/client.ts b/chatdesk-ui/lib/runtime-env/client.ts index 4ab2c9e..61136cd 100644 --- a/chatdesk-ui/lib/runtime-env/client.ts +++ b/chatdesk-ui/lib/runtime-env/client.ts @@ -1,4 +1,4 @@ // lib/runtime-env/client.ts -export function getRuntimeEnvClient(key: string): string | undefined { +export function getRuntimeEnvCSR(key: string): string | undefined { return (window as any).RUNTIME_ENV?.[key] } diff --git a/chatdesk-ui/lib/runtime-env/index.ts b/chatdesk-ui/lib/runtime-env/index.ts new file mode 100644 index 0000000..4f23b7f --- /dev/null +++ b/chatdesk-ui/lib/runtime-env/index.ts @@ -0,0 +1,10 @@ +// lib/runtime-env/index.ts +export function getRuntimeEnv(key: string): string | undefined { + if (typeof window === "undefined") { + const { getRuntimeEnvSSR } = require("./server") + return getRuntimeEnvSSR(key) + } else { + const { getRuntimeEnvCSR } = require("./client") + return getRuntimeEnvCSR(key) + } +} diff --git a/chatdesk-ui/lib/runtime-env/server.ts b/chatdesk-ui/lib/runtime-env/server.ts index 0b64b01..8d4069e 100644 --- a/chatdesk-ui/lib/runtime-env/server.ts +++ b/chatdesk-ui/lib/runtime-env/server.ts @@ -1,7 +1,7 @@ // lib/runtime-env/server.ts import { headers } from "next/headers" -export function getRuntimeEnvServer(key: string): string | undefined { +export function getRuntimeEnvSSR(key: string): string | undefined { if (key === "SUPABASE_URL") { const h = headers() const proto = h.get("x-forwarded-proto") ?? (h.get("host")?.includes(":443") ? "https" : "http") @@ -9,5 +9,6 @@ export function getRuntimeEnvServer(key: string): string | undefined { const hostname = rawHost.split(",")[0].split(":")[0].trim() return `${proto}://${hostname}:8000` } + return process.env[key] } diff --git a/chatdesk-ui/lib/server/server-chat-helpers.ts b/chatdesk-ui/lib/server/server-chat-helpers.ts index 1475d8f..3931ed5 100644 --- a/chatdesk-ui/lib/server/server-chat-helpers.ts +++ b/chatdesk-ui/lib/server/server-chat-helpers.ts @@ -4,7 +4,7 @@ import { VALID_ENV_KEYS } from "@/types/valid-keys" import { getSupabaseServerClient } from "@/lib/supabase/server" import { cookies } from "next/headers" //import { getRuntimeEnv } from "@/lib/ipconfig" // 新增引入 -import { getRuntimeEnv } from "@/lib/get-runtime-env" // ✅ 新路径 +import { getRuntimeEnv } from "@/lib/runtime-env" export async function getServerProfile() { diff --git a/chatdesk-ui/lib/supabase/client.ts b/chatdesk-ui/lib/supabase/client.ts index 876a5a7..dc9f658 100644 --- a/chatdesk-ui/lib/supabase/client.ts +++ b/chatdesk-ui/lib/supabase/client.ts @@ -10,7 +10,7 @@ import { createBrowserClient } from "@supabase/ssr" //import { getRuntimeEnv } from "@/lib/ipconfig" -import { getRuntimeEnv } from "@/lib/get-runtime-env" // ✅ 新路径 +import { getRuntimeEnv } from "@/lib/runtime-env" export const createClient = () => createBrowserClient(