Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
newfish-cmyk committed Jan 10, 2025
1 parent 3f2881d commit a087d2d
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 29 deletions.
13 changes: 0 additions & 13 deletions packages/global/support/user/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,3 @@ export enum OAuthEnum {
wecom = 'wecom',
sso = 'sso'
}

export const defaultAvatars = [
'/imgs/avatar/RoyalBlueAvatar.svg',
'/imgs/avatar/PurpleAvatar.svg',
'/imgs/avatar/AdoraAvatar.svg',
'/imgs/avatar/OrangeAvatar.svg',
'/imgs/avatar/RedAvatar.svg',
'/imgs/avatar/GrayModernAvatar.svg',
'/imgs/avatar/TealAvatar.svg',
'/imgs/avatar/GreenAvatar.svg',
'/imgs/avatar/BrightBlueAvatar.svg',
'/imgs/avatar/BlueAvatar.svg'
];
16 changes: 16 additions & 0 deletions packages/global/support/user/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export const getRandomUserAvatar = () => {
const defaultAvatars = [
'/imgs/avatar/RoyalBlueAvatar.svg',
'/imgs/avatar/PurpleAvatar.svg',
'/imgs/avatar/AdoraAvatar.svg',
'/imgs/avatar/OrangeAvatar.svg',
'/imgs/avatar/RedAvatar.svg',
'/imgs/avatar/GrayModernAvatar.svg',
'/imgs/avatar/TealAvatar.svg',
'/imgs/avatar/GreenAvatar.svg',
'/imgs/avatar/BrightBlueAvatar.svg',
'/imgs/avatar/BlueAvatar.svg'
];

return defaultAvatars[Math.floor(Math.random() * defaultAvatars.length)];
};
9 changes: 3 additions & 6 deletions packages/service/support/user/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@ import { connectionMongo, getMongoModel } from '../../common/mongo';
const { Schema } = connectionMongo;
import { hashStr } from '@fastgpt/global/common/string/tools';
import type { UserModelSchema } from '@fastgpt/global/support/user/type';
import {
defaultAvatars,
UserStatusEnum,
userStatusMap
} from '@fastgpt/global/support/user/constant';
import { UserStatusEnum, userStatusMap } from '@fastgpt/global/support/user/constant';
import { getRandomUserAvatar } from '@fastgpt/global/support/user/utils';

export const userCollectionName = 'users';

Expand Down Expand Up @@ -38,7 +35,7 @@ const UserSchema = new Schema({
},
avatar: {
type: String,
default: defaultAvatars[Math.floor(Math.random() * defaultAvatars.length)]
default: getRandomUserAvatar()
},

promotionRate: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ import { ChatRecordContext } from '@/web/core/chat/context/chatRecordContext';
import { ChatItemContext } from '@/web/core/chat/context/chatItemContext';
import TimeBox from './components/TimeBox';
import MyBox from '@fastgpt/web/components/common/MyBox';
import { defaultAvatars } from '@fastgpt/global/support/user/constant';

const ResponseTags = dynamic(() => import('./components/ResponseTags'));
const FeedbackModal = dynamic(() => import('./components/FeedbackModal'));
Expand Down Expand Up @@ -167,12 +166,6 @@ const ChatBox = ({
chatBoxData?.appId === appId &&
(chatStartedWatch || chatRecords.length > 0 || variableList.length === 0);

const humanAvatar = useMemo(() => {
return chatType === 'share'
? defaultAvatars[Math.floor(Math.random() * defaultAvatars.length)]
: userAvatar;
}, [chatType, userAvatar]);

// 滚动到底部
const scrollToBottom = useMemoizedFn((behavior: 'smooth' | 'auto' = 'smooth', delay = 0) => {
setTimeout(() => {
Expand Down Expand Up @@ -913,7 +906,7 @@ const ChatBox = ({
{item.obj === ChatRoleEnum.Human && !item.hideInUI && (
<ChatItem
type={item.obj}
avatar={humanAvatar}
avatar={userAvatar}
chat={item}
onRetry={retryInput(item.dataId)}
onDelete={delOneMessage(item.dataId)}
Expand Down Expand Up @@ -1010,7 +1003,7 @@ const ChatBox = ({
showVoiceIcon,
statusBoxData,
t,
humanAvatar,
userAvatar,
variableList?.length,
welcomeText
]);
Expand Down
3 changes: 2 additions & 1 deletion projects/app/src/pages/api/core/chat/outLink/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { getAppLatestVersion } from '@fastgpt/service/core/app/version/controlle
import { FlowNodeTypeEnum } from '@fastgpt/global/core/workflow/node/constant';
import { NextAPI } from '@/service/middleware/entry';
import { UserModelSchema } from '@fastgpt/global/support/user/type';
import { getRandomUserAvatar } from '@fastgpt/global/support/user/utils';

async function handler(req: NextApiRequest, res: NextApiResponse) {
let { chatId, shareId, outLinkUid } = req.query as InitOutLinkChatProps;
Expand Down Expand Up @@ -48,7 +49,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
chatId,
appId: app._id,
title: chat?.title,
userAvatar: tmb?.user?.avatar,
userAvatar: getRandomUserAvatar(),
variables: chat?.variables,
app: {
chatConfig: getAppChatConfig({
Expand Down

0 comments on commit a087d2d

Please sign in to comment.