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
0a689b0a
authored
Jul 28, 2023
by
archer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: save chat and hook
parent
a77e3880
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
71 additions
and
55 deletions
+71
-55
client/src/pages/api/admin/initv4.ts
+2
-2
client/src/pages/chat/components/ToolMenu.tsx
+32
-26
client/src/service/events/pushBill.ts
+1
-1
client/src/service/utils/auth.ts
+2
-2
client/src/service/utils/chat/saveChat.ts
+34
-24
No files found.
client/src/pages/api/admin/initv4.ts
View file @
0a689b0a
...
@@ -385,8 +385,8 @@ async function init(limit: number, skip: number) {
...
@@ -385,8 +385,8 @@ async function init(limit: number, skip: number) {
// 遍历 app
// 遍历 app
const
apps
=
await
App
.
find
(
const
apps
=
await
App
.
find
(
{
{
chat
:
{
$ne
:
null
}
chat
:
{
$ne
:
null
}
,
// modules: { $exists: false },
modules
:
{
$exists
:
false
}
// userId: '63f9a14228d2a688d8dc9e1b'
// userId: '63f9a14228d2a688d8dc9e1b'
},
},
'_id chat'
'_id chat'
...
...
client/src/pages/chat/components/ToolMenu.tsx
View file @
0a689b0a
import
React
,
{
use
Ref
}
from
'react'
;
import
React
,
{
use
Memo
}
from
'react'
;
import
{
useChatBox
}
from
'@/components/ChatBox'
;
import
{
useChatBox
}
from
'@/components/ChatBox'
;
import
{
ChatItemType
}
from
'@/types/chat'
;
import
{
ChatItemType
}
from
'@/types/chat'
;
import
{
Menu
,
MenuButton
,
MenuList
,
MenuItem
,
Box
}
from
'@chakra-ui/react'
;
import
{
Menu
,
MenuButton
,
MenuList
,
MenuItem
,
Box
}
from
'@chakra-ui/react'
;
...
@@ -8,30 +8,36 @@ import { useRouter } from 'next/router';
...
@@ -8,30 +8,36 @@ import { useRouter } from 'next/router';
const
ToolMenu
=
({
history
}:
{
history
:
ChatItemType
[]
})
=>
{
const
ToolMenu
=
({
history
}:
{
history
:
ChatItemType
[]
})
=>
{
const
{
onExportChat
}
=
useChatBox
();
const
{
onExportChat
}
=
useChatBox
();
const
router
=
useRouter
();
const
router
=
useRouter
();
const
menuList
=
useRef
([
const
{
appId
}
=
router
.
query
;
{
icon
:
'chat'
,
const
menuList
=
useMemo
(
label
:
'新对话'
,
()
=>
[
onClick
:
()
=>
{
{
router
.
push
({
icon
:
'chat'
,
query
:
{
label
:
'新对话'
,
appId
:
router
.
query
?.
appId
onClick
:
()
=>
{
}
router
.
push
({
});
query
:
{
}
appId
},
}
{
});
icon
:
'apiLight'
,
}
label
:
'HTML导出'
,
},
onClick
:
()
=>
onExportChat
({
type
:
'html'
,
history
})
{
},
icon
:
'apiLight'
,
{
label
:
'HTML导出'
,
icon
:
'markdown'
,
onClick
:
()
=>
onExportChat
({
type
:
'html'
,
history
})
label
:
'Markdown导出'
,
},
onClick
:
()
=>
onExportChat
({
type
:
'md'
,
history
})
{
},
icon
:
'markdown'
,
{
icon
:
'pdf'
,
label
:
'PDF导出'
,
onClick
:
()
=>
onExportChat
({
type
:
'pdf'
,
history
})
}
label
:
'Markdown导出'
,
]);
onClick
:
()
=>
onExportChat
({
type
:
'md'
,
history
})
},
{
icon
:
'pdf'
,
label
:
'PDF导出'
,
onClick
:
()
=>
onExportChat
({
type
:
'pdf'
,
history
})
}
],
[
appId
,
history
,
onExportChat
,
router
]
);
return
history
.
length
>
0
?
(
return
history
.
length
>
0
?
(
<
Menu
autoSelect=
{
false
}
isLazy
>
<
Menu
autoSelect=
{
false
}
isLazy
>
<
MenuButton
<
MenuButton
...
@@ -45,7 +51,7 @@ const ToolMenu = ({ history }: { history: ChatItemType[] }) => {
...
@@ -45,7 +51,7 @@ const ToolMenu = ({ history }: { history: ChatItemType[] }) => {
<
MyIcon
name=
{
'more'
}
w=
{
'14px'
}
p=
{
2
}
/>
<
MyIcon
name=
{
'more'
}
w=
{
'14px'
}
p=
{
2
}
/>
</
MenuButton
>
</
MenuButton
>
<
MenuList
color=
{
'myGray.700'
}
minW=
{
`120px !important`
}
zIndex=
{
10
}
>
<
MenuList
color=
{
'myGray.700'
}
minW=
{
`120px !important`
}
zIndex=
{
10
}
>
{
menuList
.
current
.
map
((
item
)
=>
(
{
menuList
.
map
((
item
)
=>
(
<
MenuItem
key=
{
item
.
label
}
onClick=
{
item
.
onClick
}
py=
{
[
2
,
3
]
}
>
<
MenuItem
key=
{
item
.
label
}
onClick=
{
item
.
onClick
}
py=
{
[
2
,
3
]
}
>
<
MyIcon
name=
{
item
.
icon
as
any
}
w=
{
[
'14px'
,
'16px'
]
}
/>
<
MyIcon
name=
{
item
.
icon
as
any
}
w=
{
[
'14px'
,
'16px'
]
}
/>
<
Box
ml=
{
[
1
,
2
]
}
>
{
item
.
label
}
</
Box
>
<
Box
ml=
{
[
1
,
2
]
}
>
{
item
.
label
}
</
Box
>
...
...
client/src/service/events/pushBill.ts
View file @
0a689b0a
...
@@ -19,7 +19,7 @@ export const pushTaskBill = async ({
...
@@ -19,7 +19,7 @@ export const pushTaskBill = async ({
shareId
?:
string
;
shareId
?:
string
;
response
:
ChatHistoryItemResType
[];
response
:
ChatHistoryItemResType
[];
})
=>
{
})
=>
{
const
total
=
response
.
reduce
((
sum
,
item
)
=>
sum
+
item
.
price
,
0
)
||
1
;
const
total
=
response
.
reduce
((
sum
,
item
)
=>
sum
+
item
.
price
,
0
);
await
Promise
.
allSettled
([
await
Promise
.
allSettled
([
Bill
.
create
({
Bill
.
create
({
...
...
client/src/service/utils/auth.ts
View file @
0a689b0a
...
@@ -179,10 +179,10 @@ export const authApp = async ({
...
@@ -179,10 +179,10 @@ export const authApp = async ({
authOwner
?:
boolean
;
authOwner
?:
boolean
;
reserveDetail
?:
boolean
;
// focus reserve detail
reserveDetail
?:
boolean
;
// focus reserve detail
})
=>
{
})
=>
{
// 获取
model
数据
// 获取
app
数据
const
app
=
await
App
.
findById
<
AppSchema
>
(
appId
);
const
app
=
await
App
.
findById
<
AppSchema
>
(
appId
);
if
(
!
app
)
{
if
(
!
app
)
{
return
Promise
.
reject
(
'
模型不存在
'
);
return
Promise
.
reject
(
'
App is not exists
'
);
}
}
/*
/*
...
...
client/src/service/utils/chat/saveChat.ts
View file @
0a689b0a
...
@@ -31,35 +31,45 @@ export async function saveChat({
...
@@ -31,35 +31,45 @@ export async function saveChat({
'_id'
'_id'
);
);
const
promise
=
[];
if
(
chatHistory
)
{
if
(
chatHistory
)
{
await
Chat
.
findOneAndUpdate
(
promise
.
push
(
{
chatId
},
Chat
.
findOneAndUpdate
(
{
{
chatId
},
$push
:
{
{
content
:
{
$push
:
{
$each
:
content
content
:
{
}
$each
:
content
},
}
title
:
content
[
0
].
value
.
slice
(
0
,
20
),
},
updateTime
:
new
Date
()
title
:
content
[
0
].
value
.
slice
(
0
,
20
),
}
updateTime
:
new
Date
()
}
)
);
);
}
else
{
}
else
{
await
Chat
.
create
({
promise
.
push
(
chatId
,
Chat
.
create
({
userId
,
chatId
,
appId
,
userId
,
variables
,
appId
,
title
:
content
[
0
].
value
.
slice
(
0
,
20
),
variables
,
source
,
title
:
content
[
0
].
value
.
slice
(
0
,
20
),
shareId
,
source
,
content
:
content
shareId
,
});
content
:
content
})
);
}
}
if
(
isOwner
&&
source
===
ChatSourceEnum
.
online
)
{
if
(
isOwner
&&
source
===
ChatSourceEnum
.
online
)
{
App
.
findByIdAndUpdate
(
appId
,
{
promise
.
push
(
updateTime
:
new
Date
()
App
.
findByIdAndUpdate
(
appId
,
{
});
updateTime
:
new
Date
()
})
);
}
}
await
Promise
.
all
(
promise
);
}
}
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