Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
赵月辉
/
fastgpt-migrated
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Unverified
Commit
33154a9c
authored
Apr 08, 2023
by
archer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 去除share
parent
e1c75036
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
7 additions
and
41 deletions
+7
-41
Dockerfile
+0
-1
src/api/chat.ts
+1
-2
src/pages/api/chat/generate.ts
+2
-17
src/pages/api/user/sendEmail.ts
+0
-9
src/pages/chat/components/SlideBar.tsx
+1
-1
src/pages/chat/index.tsx
+1
-0
src/service/models/chat.ts
+2
-6
src/service/utils/chat.ts
+0
-4
src/types/mongoSchema.d.ts
+0
-1
No files found.
Dockerfile
View file @
33154a9c
...
@@ -55,7 +55,6 @@ USER nextjs
...
@@ -55,7 +55,6 @@ USER nextjs
EXPOSE
3000
EXPOSE
3000
ENV
PORT 3000
ENV
PORT 3000
ENV
MAX_USER ''
ENV
AXIOS_PROXY_HOST ''
ENV
AXIOS_PROXY_HOST ''
ENV
AXIOS_PROXY_PORT ''
ENV
AXIOS_PROXY_PORT ''
ENV
MONGODB_URI ''
ENV
MONGODB_URI ''
...
...
src/api/chat.ts
View file @
33154a9c
...
@@ -5,8 +5,7 @@ import type { InitChatResponse } from './response/chat';
...
@@ -5,8 +5,7 @@ import type { InitChatResponse } from './response/chat';
/**
/**
* 获取一个聊天框的ID
* 获取一个聊天框的ID
*/
*/
export
const
getChatSiteId
=
(
modelId
:
string
,
isShare
=
false
)
=>
export
const
getChatSiteId
=
(
modelId
:
string
)
=>
GET
<
string
>
(
`/chat/generate?modelId=
${
modelId
}
`
);
GET
<
string
>
(
`/chat/generate?modelId=
${
modelId
}
&isShare=
${
isShare
?
'true'
:
'false'
}
`
);
/**
/**
* 获取初始化聊天内容
* 获取初始化聊天内容
...
...
src/pages/api/chat/generate.ts
View file @
33154a9c
import
type
{
NextApiRequest
,
NextApiResponse
}
from
'next'
;
import
type
{
NextApiRequest
,
NextApiResponse
}
from
'next'
;
import
{
jsonRes
}
from
'@/service/response'
;
import
{
jsonRes
}
from
'@/service/response'
;
import
{
connectToDatabase
,
Model
,
Chat
}
from
'@/service/mongo'
;
import
{
connectToDatabase
,
Chat
}
from
'@/service/mongo'
;
import
{
authToken
}
from
'@/service/utils/tools'
;
import
{
authToken
}
from
'@/service/utils/tools'
;
import
type
{
ModelSchema
}
from
'@/types/mongoSchema'
;
/* 获取我的模型 */
/* 获取我的模型 */
export
default
async
function
handler
(
req
:
NextApiRequest
,
res
:
NextApiResponse
<
any
>
)
{
export
default
async
function
handler
(
req
:
NextApiRequest
,
res
:
NextApiResponse
<
any
>
)
{
try
{
try
{
const
{
modelId
,
isShare
=
'false'
}
=
req
.
query
as
{
const
{
modelId
}
=
req
.
query
as
{
modelId
:
string
;
modelId
:
string
;
isShare
?:
'true'
|
'false'
;
};
};
const
{
authorization
}
=
req
.
headers
;
const
{
authorization
}
=
req
.
headers
;
...
@@ -26,23 +24,10 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
...
@@ -26,23 +24,10 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
await
connectToDatabase
();
await
connectToDatabase
();
// 获取模型配置
const
model
=
await
Model
.
findOne
<
ModelSchema
>
({
_id
:
modelId
,
userId
});
if
(
!
model
)
{
throw
new
Error
(
'模型不存在'
);
}
// 创建 chat 数据
// 创建 chat 数据
const
response
=
await
Chat
.
create
({
const
response
=
await
Chat
.
create
({
userId
,
userId
,
modelId
,
modelId
,
expiredTime
:
Date
.
now
()
+
model
.
security
.
expiredTime
,
loadAmount
:
model
.
security
.
maxLoadAmount
,
isShare
:
isShare
===
'true'
,
content
:
[]
content
:
[]
});
});
...
...
src/pages/api/user/sendEmail.ts
View file @
33154a9c
...
@@ -16,15 +16,6 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
...
@@ -16,15 +16,6 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
await
connectToDatabase
();
await
connectToDatabase
();
// 注册人数限流
if
(
type
===
EmailTypeEnum
.
register
)
{
const
maxCount
=
process
.
env
.
MAX_USER
?
+
process
.
env
.
MAX_USER
:
Infinity
;
const
userCount
=
await
User
.
count
();
if
(
userCount
>=
maxCount
)
{
throw
new
Error
(
'当前注册用户已满,请等待名额~'
);
}
}
let
code
=
''
;
let
code
=
''
;
for
(
let
i
=
0
;
i
<
6
;
i
++
)
{
for
(
let
i
=
0
;
i
<
6
;
i
++
)
{
code
+=
Math
.
floor
(
Math
.
random
()
*
10
);
code
+=
Math
.
floor
(
Math
.
random
()
*
10
);
...
...
src/pages/chat/components/SlideBar.tsx
View file @
33154a9c
...
@@ -281,7 +281,7 @@ const SlideBar = ({
...
@@ -281,7 +281,7 @@ const SlideBar = ({
mr=
{
3
}
mr=
{
3
}
onClick=
{
async
()
=>
{
onClick=
{
async
()
=>
{
copyData
(
copyData
(
`${location.origin}/chat?chatId=${await getChatSiteId(modelId
, true
)}`
,
`${location.origin}/chat?chatId=${await getChatSiteId(modelId)}`
,
'已复制分享链接'
'已复制分享链接'
);
);
onCloseShare
();
onCloseShare
();
...
...
src/pages/chat/index.tsx
View file @
33154a9c
...
@@ -351,6 +351,7 @@ const Chat = ({ chatId }: { chatId: string }) => {
...
@@ -351,6 +351,7 @@ const Chat = ({ chatId }: { chatId: string }) => {
isClosable
:
true
,
isClosable
:
true
,
duration
:
5000
duration
:
5000
});
});
router
.
push
(
'/model/list'
);
},
},
onSettled
()
{
onSettled
()
{
setLoading
(
false
);
setLoading
(
false
);
...
...
src/service/models/chat.ts
View file @
33154a9c
...
@@ -15,21 +15,17 @@ const ChatSchema = new Schema({
...
@@ -15,21 +15,17 @@ const ChatSchema = new Schema({
expiredTime
:
{
expiredTime
:
{
// 过期时间
// 过期时间
type
:
Number
,
type
:
Number
,
required
:
true
default
:
Date
.
now
()
},
},
loadAmount
:
{
loadAmount
:
{
// 剩余加载次数
// 剩余加载次数
type
:
Number
,
type
:
Number
,
required
:
true
default
:
-
1
},
},
updateTime
:
{
updateTime
:
{
type
:
Date
,
type
:
Date
,
default
:
()
=>
new
Date
()
default
:
()
=>
new
Date
()
},
},
isShare
:
{
type
:
Boolean
,
default
:
false
},
content
:
{
content
:
{
type
:
[
type
:
[
{
{
...
...
src/service/utils/chat.ts
View file @
33154a9c
...
@@ -26,14 +26,10 @@ export const authChat = async (chatId: string, authorization?: string) => {
...
@@ -26,14 +26,10 @@ export const authChat = async (chatId: string, authorization?: string) => {
}
}
// 凭证校验
// 凭证校验
if
(
!
chat
.
isShare
)
{
const
userId
=
await
authToken
(
authorization
);
const
userId
=
await
authToken
(
authorization
);
if
(
userId
!==
String
(
chat
.
userId
.
_id
))
{
if
(
userId
!==
String
(
chat
.
userId
.
_id
))
{
return
Promise
.
reject
(
'无权使用该对话'
);
return
Promise
.
reject
(
'无权使用该对话'
);
}
}
}
else
if
(
chat
.
loadAmount
===
0
||
chat
.
expiredTime
<=
Date
.
now
())
{
return
Promise
.
reject
(
'聊天框已过期'
);
}
// 获取 user 的 apiKey
// 获取 user 的 apiKey
const
{
user
,
userApiKey
,
systemKey
}
=
await
getOpenApiKey
(
chat
.
userId
as
unknown
as
string
);
const
{
user
,
userApiKey
,
systemKey
}
=
await
getOpenApiKey
(
chat
.
userId
as
unknown
as
string
);
...
...
src/types/mongoSchema.d.ts
View file @
33154a9c
...
@@ -93,7 +93,6 @@ export interface ChatSchema {
...
@@ -93,7 +93,6 @@ export interface ChatSchema {
expiredTime
:
number
;
expiredTime
:
number
;
loadAmount
:
number
;
loadAmount
:
number
;
updateTime
:
Date
;
updateTime
:
Date
;
isShare
:
boolean
;
content
:
ChatItemType
[];
content
:
ChatItemType
[];
}
}
export
interface
ChatPopulate
extends
ChatSchema
{
export
interface
ChatPopulate
extends
ChatSchema
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment