From df82af251ae7cbc3a1ca77502ec27dd616e78ccc Mon Sep 17 00:00:00 2001 From: AprilNEA Date: Wed, 27 Dec 2023 14:21:48 +0800 Subject: [PATCH 1/6] feat: custom brand styles --- packages/frontend/next.config.js | 14 +++++++++++--- packages/frontend/src/app/(user-end)/page.tsx | 9 +++++---- packages/frontend/src/app/auth/page.tsx | 15 +++++++++++---- packages/frontend/src/app/layout.tsx | 4 ++-- packages/frontend/src/components/avatar/index.tsx | 15 +++++++++++++-- .../frontend/src/components/loading/index.tsx | 14 +++++++++++++- .../frontend/src/components/sidebar/index.tsx | 12 +++++++++++- packages/frontend/src/global.d.ts | 12 ++++++++++-- packages/frontend/src/locales/cn.ts | 5 +++-- packages/frontend/src/locales/en.ts | 1 + packages/frontend/src/store/chat.ts | 3 ++- 11 files changed, 82 insertions(+), 22 deletions(-) diff --git a/packages/frontend/next.config.js b/packages/frontend/next.config.js index 416d60d7..384873a5 100644 --- a/packages/frontend/next.config.js +++ b/packages/frontend/next.config.js @@ -9,9 +9,17 @@ const config = fs.existsSync(CONFIG_FILE) /** @type {import('next').NextConfig} */ const nextConfig = { env: { - NEXT_PUBLIC_TITLE: config?.title ?? 'ChatGPT Admin Web', - NEXT_PUBLIC_DESCRIPTION: - config?.description ?? 'Your personal ChatGPT Bot.', + TITLE: config?.brand?.title ?? config?.title ?? 'ChatGPT Admin Web', + DESCRIPTION: + config?.brand?.description ?? + config?.description ?? + 'Your personal ChatGPT Bot.', + LOGO: config?.brand?.logo?.index, + LOGO_BOT: config?.brand?.logo?.bot, + LOGO_LOGIN: config?.brand?.logo?.login, + LOGO_LOADING: config?.brand?.logo?.loading, + LOGO_SIDEBAR: config?.brand?.logo?.sidebar, + ONBOARDING: config?.brand?.onboarding, }, transpilePackages: ['shared'], webpack(config) { diff --git a/packages/frontend/src/app/(user-end)/page.tsx b/packages/frontend/src/app/(user-end)/page.tsx index 73e03526..14b9b25c 100644 --- a/packages/frontend/src/app/(user-end)/page.tsx +++ b/packages/frontend/src/app/(user-end)/page.tsx @@ -5,8 +5,8 @@ import { useRouter } from 'next/navigation'; import { IconButton } from '@/components/button'; import Chat from '@/components/chat'; import AddIcon from '@/icons/add.svg'; -import ReturnIcon from '@/icons/return.svg'; import ChatGptIcon from '@/icons/bot.svg'; +import ReturnIcon from '@/icons/return.svg'; import Locale from '@/locales'; import { useStore } from '@/store'; import styles from '@/styles/module/welcome.module.scss'; @@ -26,10 +26,11 @@ export default function ChatPage() { className={styles['return-btn']} >
-
-
+
{Locale.Index.Title}
-
{Locale.Index.WelcomeCaption}
+
+ {process.env.DESCRIPTION ?? Locale.Index.WelcomeCaption} +
} diff --git a/packages/frontend/src/app/auth/page.tsx b/packages/frontend/src/app/auth/page.tsx index 3326c716..ee1ef285 100644 --- a/packages/frontend/src/app/auth/page.tsx +++ b/packages/frontend/src/app/auth/page.tsx @@ -270,11 +270,18 @@ export default function AuthPage() { return (
- -
-
- {process.env.NEXT_PUBLIC_TITLE} + {!!process.env.LOGO_LOGIN ? ( + Logo + ) : ( + + )}
+
{Locales.Index.Title}
{tab === 'code' ? ( diff --git a/packages/frontend/src/app/layout.tsx b/packages/frontend/src/app/layout.tsx index 989a3b79..f8ee0073 100644 --- a/packages/frontend/src/app/layout.tsx +++ b/packages/frontend/src/app/layout.tsx @@ -2,8 +2,8 @@ import { SWRProvider } from '@/app/provider'; export const metadata = { - title: process.env.NEXT_PUBLIC_TITLE, - description: process.env.NEXT_PUBLIC_DESCRIPTION, + title: process.env.TITLE, + description: process.env.DESCRIPTION, }; export default function RootLayout({ diff --git a/packages/frontend/src/components/avatar/index.tsx b/packages/frontend/src/components/avatar/index.tsx index 31f98bea..1b3fc8fa 100644 --- a/packages/frontend/src/components/avatar/index.tsx +++ b/packages/frontend/src/components/avatar/index.tsx @@ -1,4 +1,5 @@ import dynamic from 'next/dynamic'; +import Image from 'next/image'; import BotIcon from '@/icons/bot.svg'; import LoadingIcon from '@/icons/three-dots.svg'; @@ -19,8 +20,18 @@ const Emoji = dynamic(async () => (await import('emoji-picker-react')).Emoji, { export function Avatar(props: { role: ChatMessage['role'] }) { const config = useStore((state) => state.config); - if (props.role === 'assistant') { - return ; + if (props.role !== 'user') { + return process.env.LOGO_BOT ? ( + Logo + ) : ( + + ); } return ( diff --git a/packages/frontend/src/components/loading/index.tsx b/packages/frontend/src/components/loading/index.tsx index a9512cbd..01fe7494 100644 --- a/packages/frontend/src/components/loading/index.tsx +++ b/packages/frontend/src/components/loading/index.tsx @@ -1,3 +1,5 @@ +import Image from 'next/image'; + import BotIcon from '@/icons/bot.svg'; import LoadingIcon from '@/icons/three-dots.svg'; import styles from '@/styles/module/home.module.scss'; @@ -5,7 +7,17 @@ import styles from '@/styles/module/home.module.scss'; export function Loading(props: { noLogo?: boolean }) { return (
- {!props.noLogo && } + {!props.noLogo && + (process.env.LOGO_LOADING ? ( + logo + ) : ( + + ))}
); diff --git a/packages/frontend/src/components/sidebar/index.tsx b/packages/frontend/src/components/sidebar/index.tsx index 07576ba5..13baddeb 100644 --- a/packages/frontend/src/components/sidebar/index.tsx +++ b/packages/frontend/src/components/sidebar/index.tsx @@ -1,6 +1,7 @@ 'use client'; import clsx from 'clsx'; +import Image from 'next/image'; import Link from 'next/link'; import { useRouter } from 'next/navigation'; import { useEffect, useState } from 'react'; @@ -198,7 +199,16 @@ export function Sidebar({ children }: { children: React.ReactNode }) {
)}
- + {process.env.LOGO_SIDEBAR ? ( + Logo + ) : ( + + )}
diff --git a/packages/frontend/src/global.d.ts b/packages/frontend/src/global.d.ts index 6ce0b02a..81ee2121 100644 --- a/packages/frontend/src/global.d.ts +++ b/packages/frontend/src/global.d.ts @@ -12,7 +12,15 @@ declare module '*.svg'; declare namespace NodeJS { interface ProcessEnv { NODE_ENV: 'development' | 'production'; - NEXT_PUBLIC_TITLE: string; - NEXT_PUBLIC_DESCRIPTION: string; + TITLE: string; + DESCRIPTION: string; + + LOGO?: string; + LOGO_BOT?: string; + LOGO_LOGIN?: string; + LOGO_LOADING?: string; + LOGO_SIDEBAR?: string; + + ONBOARDING?: string; } } diff --git a/packages/frontend/src/locales/cn.ts b/packages/frontend/src/locales/cn.ts index 6d255499..c2e28aa9 100644 --- a/packages/frontend/src/locales/cn.ts +++ b/packages/frontend/src/locales/cn.ts @@ -1,4 +1,4 @@ -export const TITLE = process.env.NEXT_PUBLIC_TITLE || 'ChatGPT Admin Web'; +export const TITLE = process.env.TITLE || 'ChatGPT Admin Web'; const cn = { // Auth Page @@ -19,7 +19,7 @@ const cn = { // Index Page Index: { DefaultUser: '用户', - Title: process.env.NEXT_PUBLIC_TITLE || 'ChatGPT Admin Web', + Title: TITLE, SubTitle: '欢迎关注微信公众号:', PremiumLimit: (count: number) => `当前可用:${count} 条`, UpgradePremium: '升级到高级版', @@ -59,6 +59,7 @@ const cn = { ChatItemCount: (count: number) => `${count} 条对话`, }, Chat: { + Onboarding: process.env.ONBOARDING ?? '你好,请问有什么可以帮助您?', SubTitle: (count: number) => `与 ${TITLE} 的 ${count} 条对话`, Actions: { ChatList: '查看消息列表', diff --git a/packages/frontend/src/locales/en.ts b/packages/frontend/src/locales/en.ts index c2cf63f0..47942fbc 100644 --- a/packages/frontend/src/locales/en.ts +++ b/packages/frontend/src/locales/en.ts @@ -63,6 +63,7 @@ const en: LocaleType = { ChatItemCount: (count: number) => `${count} messages`, }, Chat: { + Onboarding: process.env.ONBOARDING ?? 'Welcome to use AI Chatting Room', SubTitle: (count: number) => `${count} conversations with ${TITLE}`, Actions: { ChatList: 'View Message List', diff --git a/packages/frontend/src/store/chat.ts b/packages/frontend/src/store/chat.ts index 39c8a709..60298c96 100644 --- a/packages/frontend/src/store/chat.ts +++ b/packages/frontend/src/store/chat.ts @@ -1,5 +1,6 @@ import { StateCreator } from 'zustand'; +import Locales from '@/locales'; import { ChatSlice, StoreType } from '@/store/types'; import { TextLineStream } from '@/utils/text_line_stream'; @@ -63,7 +64,7 @@ export const createChatStore: StateCreator = ( currentChatSessionMessages: [ { role: 'system', - content: '你好,请问有什么可以帮助您?', + content: Locales.Chat.Onboarding, modelId: 1, createdAt: new Date(), updatedAt: new Date(), From 2262601147a76fe98a83ecb117e24b7c17a3c406 Mon Sep 17 00:00:00 2001 From: AprilNEA Date: Wed, 27 Dec 2023 16:40:44 +0800 Subject: [PATCH 2/6] feat: remove usetuped wechat, add custom favicon --- packages/frontend/src/app/auth/page.tsx | 28 +++++++++++++------------ packages/frontend/src/app/layout.tsx | 3 +++ 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/packages/frontend/src/app/auth/page.tsx b/packages/frontend/src/app/auth/page.tsx index ee1ef285..2cb8b183 100644 --- a/packages/frontend/src/app/auth/page.tsx +++ b/packages/frontend/src/app/auth/page.tsx @@ -296,20 +296,22 @@ export default function AuthPage() {
OR
-
-
{ - setTab(() => { - if (tab != 'wechat') return 'wechat'; - else return 'code'; - }); - }} - > - {tab == 'wechat' ? : } -
使用{tab == 'wechat' ? '验证码' : '微信'}登陆
+ {process.env.WECHAT && ( +
+
{ + setTab(() => { + if (tab != 'wechat') return 'wechat'; + else return 'code'; + }); + }} + > + {tab == 'wechat' ? : } +
使用{tab == 'wechat' ? '验证码' : '微信'}登陆
+
-
+ )}
+ {process.env.LOGO && ( + + )} Date: Wed, 27 Dec 2023 17:35:59 +0800 Subject: [PATCH 3/6] chore(turbo): remove build from start pipeline --- turbo.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/turbo.json b/turbo.json index 6e76f8f9..17789a18 100644 --- a/turbo.json +++ b/turbo.json @@ -33,6 +33,7 @@ ] }, "build": { + "inputs": ["config.json"], "dependsOn": [ "db:generate", "^build" @@ -48,7 +49,6 @@ }, "start": { "dependsOn": [ - "build", "^start" ] }, From 1dfe27d4cd83b9c22e0e1a693ae3753fd8387853 Mon Sep 17 00:00:00 2001 From: AprilNEA Date: Wed, 27 Dec 2023 17:36:54 +0800 Subject: [PATCH 4/6] chore: bump version 3.2.4-alpha --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a10b1122..d9fdf01a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "chatgpt-admin-web", - "version": "3.2.3", + "version": "3.2.4-alpha", "description": "ChatGPT Admin Web", "license": "MIT", "author": "AprilNEA (https://sku.moe)", From d0a5418f35897ea9fb34e101cccb800eaf45968a Mon Sep 17 00:00:00 2001 From: AprilNEA Date: Wed, 27 Dec 2023 17:45:54 +0800 Subject: [PATCH 5/6] fix: crypto.randomUUID is not a function in some browser edge browser case Appliction error: a client-side exception. --- packages/frontend/package.json | 2 ++ .../frontend/src/app/(user-end)/chat/new/page.tsx | 4 +++- packages/frontend/src/utils/client-utils.ts | 10 ++++++++++ pnpm-lock.yaml | 15 +++++++++++++++ 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/packages/frontend/package.json b/packages/frontend/package.json index 007bce5e..520184f1 100644 --- a/packages/frontend/package.json +++ b/packages/frontend/package.json @@ -37,12 +37,14 @@ "sass": "^1.59.2", "shared": "workspace:*", "swr": "^2.2.4", + "uuid": "^9.0.1", "zustand": "^4.3.6" }, "devDependencies": { "@types/react": "^18.0.28", "@types/react-dom": "^18.0.11", "@types/react-katex": "^3.0.0", + "@types/uuid": "^9.0.7", "autoprefixer": "^10.4.16", "postcss": "^8.4.31", "tailwindcss": "^3.3.5", diff --git a/packages/frontend/src/app/(user-end)/chat/new/page.tsx b/packages/frontend/src/app/(user-end)/chat/new/page.tsx index 9ffa559d..8e9a5a1b 100644 --- a/packages/frontend/src/app/(user-end)/chat/new/page.tsx +++ b/packages/frontend/src/app/(user-end)/chat/new/page.tsx @@ -4,6 +4,8 @@ 移除将会导致在客户端未刷新的情况下 randomUUID 永远相同 */ import { RedirectType, redirect } from 'next/navigation'; +import { randomUUID } from '@/utils/client-utils'; + export default function NewChatPage() { - redirect(`/chat/${crypto.randomUUID()}?new=true`, RedirectType.replace); + redirect(`/chat/${randomUUID()}?new=true`, RedirectType.replace); } diff --git a/packages/frontend/src/utils/client-utils.ts b/packages/frontend/src/utils/client-utils.ts index 0c32315e..8e0bbc8e 100644 --- a/packages/frontend/src/utils/client-utils.ts +++ b/packages/frontend/src/utils/client-utils.ts @@ -1,6 +1,16 @@ +import { v4 as uuidv4 } from 'uuid'; + import { showToast } from '@/components/ui-lib'; import Locale from '@/locales'; +export const randomUUID = () => { + if ('crypto' in window && 'randomUUID' in crypto) { + return crypto.randomUUID(); + } else { + return uuidv4(); + } +}; + export function trimTopic(topic: string) { return topic.replace(/[,。!?、,.!?]*$/, ''); } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3a947acc..ac778713 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -260,6 +260,9 @@ importers: swr: specifier: ^2.2.4 version: 2.2.4(react@18.2.0) + uuid: + specifier: ^9.0.1 + version: 9.0.1 zustand: specifier: ^4.3.6 version: 4.3.6(react@18.2.0) @@ -273,6 +276,9 @@ importers: '@types/react-katex': specifier: ^3.0.0 version: 3.0.0 + '@types/uuid': + specifier: ^9.0.7 + version: 9.0.7 autoprefixer: specifier: ^10.4.16 version: 10.4.16(postcss@8.4.31) @@ -4354,6 +4360,10 @@ packages: resolution: {integrity: sha512-cputDpIbFgLUaGQn6Vqg3/YsJwxUwHLO13v3i5ouxT4lat0khip9AEWxtERujXV9wxIB1EyF97BSJFt6vpdI8g==} dev: false + /@types/uuid@9.0.7: + resolution: {integrity: sha512-WUtIVRUZ9i5dYXefDEAI7sh9/O7jGvHg7Df/5O/gtH3Yabe5odI3UWopVR1qbPXQtvOxWu3mM4XxlYeZtMWF4g==} + dev: true + /@types/yargs-parser@21.0.0: resolution: {integrity: sha512-iO9ZQHkZxHn4mSakYV0vFHAVDyEOIJQrV2uZ06HxEPcx+mt8swXoZHIbaaJ2crJYFfErySgktuTZ3BeLz+XmFA==} dev: true @@ -11157,6 +11167,11 @@ packages: hasBin: true dev: false + /uuid@9.0.1: + resolution: {integrity: sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==} + hasBin: true + dev: false + /uvu@0.5.6: resolution: {integrity: sha512-+g8ENReyr8YsOc6fv/NVJs2vFdHBnBNdfE49rshrTzDWOlUx4Gq7KOS2GD8eqhy2j+Ejq29+SbKH8yjkAqXqoA==} engines: {node: '>=8'} From 9aef736e565a20b5d66954592d1fa9869ad9b01d Mon Sep 17 00:00:00 2001 From: AprilNEA Date: Wed, 27 Dec 2023 18:27:37 +0800 Subject: [PATCH 6/6] chore: bump 3.2.4 version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d9fdf01a..7b392dae 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "chatgpt-admin-web", - "version": "3.2.4-alpha", + "version": "3.2.4", "description": "ChatGPT Admin Web", "license": "MIT", "author": "AprilNEA (https://sku.moe)",