mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-30 10:28:42 +00:00
chat box
This commit is contained in:
@@ -1,14 +1,17 @@
|
||||
import { Schema, model, models, Model } from 'mongoose';
|
||||
import { ShareChatSchema as ShareChatSchemaType } from '@/types/mongoSchema';
|
||||
import { hashPassword } from '@/service/utils/tools';
|
||||
|
||||
const ShareChatSchema = new Schema({
|
||||
shareId: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
userId: {
|
||||
type: Schema.Types.ObjectId,
|
||||
ref: 'user',
|
||||
required: true
|
||||
},
|
||||
modelId: {
|
||||
appId: {
|
||||
type: Schema.Types.ObjectId,
|
||||
ref: 'model',
|
||||
required: true
|
||||
@@ -17,10 +20,6 @@ const ShareChatSchema = new Schema({
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
password: {
|
||||
type: String,
|
||||
set: (val: string) => hashPassword(val)
|
||||
},
|
||||
tokens: {
|
||||
type: Number,
|
||||
default: 0
|
||||
|
@@ -317,30 +317,17 @@ export const authChat = async ({
|
||||
showModelDetail
|
||||
};
|
||||
};
|
||||
export const authShareChat = async ({
|
||||
shareId,
|
||||
password
|
||||
}: {
|
||||
shareId: string;
|
||||
password: string;
|
||||
}) => {
|
||||
export const authShareChat = async ({ shareId }: { shareId: string }) => {
|
||||
// get shareChat
|
||||
const shareChat = await ShareChat.findById(shareId);
|
||||
const shareChat = await ShareChat.findOne({ shareId });
|
||||
|
||||
if (!shareChat) {
|
||||
return Promise.reject('分享链接已失效');
|
||||
}
|
||||
|
||||
if (shareChat.password !== hashPassword(password)) {
|
||||
return Promise.reject({
|
||||
code: 501,
|
||||
message: '密码不正确'
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
userId: String(shareChat.userId),
|
||||
appId: String(shareChat.modelId),
|
||||
appId: String(shareChat.appId),
|
||||
authType: 'token' as AuthType
|
||||
};
|
||||
};
|
||||
|
Reference in New Issue
Block a user