Skip to content

Commit

Permalink
share link random avatar (#3541)
Browse files Browse the repository at this point in the history
* share link random avatar

* fix

* delete unused code
  • Loading branch information
newfish-cmyk authored Jan 10, 2025
1 parent cef8487 commit b26345d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 28 deletions.
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)];
};
16 changes: 2 additions & 14 deletions packages/service/support/user/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,10 @@ const { Schema } = connectionMongo;
import { hashStr } from '@fastgpt/global/common/string/tools';
import type { UserModelSchema } from '@fastgpt/global/support/user/type';
import { UserStatusEnum, userStatusMap } from '@fastgpt/global/support/user/constant';
import { getRandomUserAvatar } from '@fastgpt/global/support/user/utils';

export const userCollectionName = 'users';

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'
];

const UserSchema = new Schema({
status: {
type: String,
Expand Down Expand Up @@ -47,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 @@ -104,14 +104,9 @@ const ChatBox = ({
showVoiceIcon = true,
showEmptyIntro = false,
active = true,
shareId,
outLinkUid,
teamId,
teamToken,
onStartChat
}: Props) => {
const ScrollContainerRef = useRef<HTMLDivElement>(null);
const router = useRouter();
const { t } = useTranslation();
const { toast } = useToast();
const { feConfigs } = useSystemStore();
Expand Down Expand Up @@ -925,10 +920,6 @@ const ChatBox = ({
isLastChild={index === chatRecords.length - 1}
{...{
showVoiceIcon,
shareId,
outLinkUid,
teamId,
teamToken,
statusBoxData,
questionGuides,
onMark: onMark(
Expand Down Expand Up @@ -1004,17 +995,13 @@ const ChatBox = ({
onCloseUserLike,
onMark,
onReadUserDislike,
outLinkUid,
questionGuides,
retryInput,
shareId,
showEmpty,
showMarkIcon,
showVoiceIcon,
statusBoxData,
t,
teamId,
teamToken,
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 b26345d

Please sign in to comment.