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
f65a7282
authored
Jul 28, 2023
by
archer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
perf: share link
parent
36b234c4
Hide whitespace changes
Inline
Side-by-side
Showing
22 changed files
with
173 additions
and
40 deletions
+173
-40
client/public/js/iframe.js
+66
-0
client/src/components/Icon/icons/outlink/iframe.svg
+2
-0
client/src/components/Icon/icons/outlink/iframe.svg:Zone.Identifier
+0
-0
client/src/components/Icon/icons/outlink/share.svg
+2
-0
client/src/components/Icon/index.tsx
+3
-1
client/src/components/Radio/index.tsx
+10
-2
client/src/constants/chat.ts
+5
-0
client/src/pages/api/app/del.ts
+2
-2
client/src/pages/api/chat/shareChat/create.ts
+2
-2
client/src/pages/api/chat/shareChat/delete.ts
+2
-2
client/src/pages/api/chat/shareChat/init.ts
+2
-2
client/src/pages/api/chat/shareChat/list.ts
+2
-2
client/src/pages/api/openapi/v1/chat/completions.ts
+2
-1
client/src/pages/app/detail/components/BasicEdit/index.tsx
+2
-2
client/src/pages/app/detail/components/OutLink.tsx
+51
-8
client/src/pages/app/detail/index.tsx
+4
-4
client/src/pages/chat/share.tsx
+2
-2
client/src/service/events/pushBill.ts
+2
-2
client/src/service/models/outLink.ts
+8
-4
client/src/service/mongo.ts
+1
-1
client/src/service/utils/auth.ts
+2
-2
client/src/types/mongoSchema.d.ts
+1
-1
No files found.
client/public/js/iframe.js
0 → 100644
View file @
f65a7282
async
function
embedChatbot
()
{
const
t
=
window
.
difyChatbotConfig
;
if
(
t
&&
t
.
token
)
{
var
e
=
!!
t
.
isDev
;
const
o
=
t
.
baseUrl
||
`https://
${
e
?
'dev.'
:
''
}
udify.app`
,
n
=
`<svg
id="openIcon"
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
fill-rule="evenodd"
clip-rule="evenodd"
d="M7.7586 2L16.2412 2C17.0462 1.99999 17.7105 1.99998 18.2517 2.04419C18.8138 2.09012 19.3305 2.18868 19.8159 2.43598C20.5685 2.81947 21.1804 3.43139 21.5639 4.18404C21.8112 4.66937 21.9098 5.18608 21.9557 5.74818C21.9999 6.28937 21.9999 6.95373 21.9999 7.7587L22 14.1376C22.0004 14.933 22.0007 15.5236 21.8636 16.0353C21.4937 17.4156 20.4155 18.4938 19.0352 18.8637C18.7277 18.9461 18.3917 18.9789 17.9999 18.9918L17.9999 20.371C18 20.6062 18 20.846 17.9822 21.0425C17.9651 21.2305 17.9199 21.5852 17.6722 21.8955C17.3872 22.2525 16.9551 22.4602 16.4983 22.4597C16.1013 22.4593 15.7961 22.273 15.6386 22.1689C15.474 22.06 15.2868 21.9102 15.1031 21.7632L12.69 19.8327C12.1714 19.4178 12.0174 19.3007 11.8575 19.219C11.697 19.137 11.5262 19.0771 11.3496 19.0408C11.1737 19.0047 10.9803 19 10.3162 19H7.75858C6.95362 19 6.28927 19 5.74808 18.9558C5.18598 18.9099 4.66928 18.8113 4.18394 18.564C3.43129 18.1805 2.81937 17.5686 2.43588 16.816C2.18859 16.3306 2.09002 15.8139 2.0441 15.2518C1.99988 14.7106 1.99989 14.0463 1.9999 13.2413V7.75868C1.99989 6.95372 1.99988 6.28936 2.0441 5.74818C2.09002 5.18608 2.18859 4.66937 2.43588 4.18404C2.81937 3.43139 3.43129 2.81947 4.18394 2.43598C4.66928 2.18868 5.18598 2.09012 5.74808 2.04419C6.28927 1.99998 6.95364 1.99999 7.7586 2ZM10.5073 7.5C10.5073 6.67157 9.83575 6 9.00732 6C8.1789 6 7.50732 6.67157 7.50732 7.5C7.50732 8.32843 8.1789 9 9.00732 9C9.83575 9 10.5073 8.32843 10.5073 7.5ZM16.6073 11.7001C16.1669 11.3697 15.5426 11.4577 15.2105 11.8959C15.1488 11.9746 15.081 12.0486 15.0119 12.1207C14.8646 12.2744 14.6432 12.4829 14.3566 12.6913C13.7796 13.111 12.9818 13.5001 12.0073 13.5001C11.0328 13.5001 10.235 13.111 9.65799 12.6913C9.37138 12.4829 9.15004 12.2744 9.00274 12.1207C8.93366 12.0486 8.86581 11.9745 8.80418 11.8959C8.472 11.4577 7.84775 11.3697 7.40732 11.7001C6.96549 12.0314 6.87595 12.6582 7.20732 13.1001C7.20479 13.0968 7.21072 13.1043 7.22094 13.1171C7.24532 13.1478 7.29407 13.2091 7.31068 13.2289C7.36932 13.2987 7.45232 13.3934 7.55877 13.5045C7.77084 13.7258 8.08075 14.0172 8.48165 14.3088C9.27958 14.8891 10.4818 15.5001 12.0073 15.5001C13.5328 15.5001 14.735 14.8891 15.533 14.3088C15.9339 14.0172 16.2438 13.7258 16.4559 13.5045C16.5623 13.3934 16.6453 13.2987 16.704 13.2289C16.7333 13.1939 16.7567 13.165 16.7739 13.1432C17.1193 12.6969 17.0729 12.0493 16.6073 11.7001ZM15.0073 6C15.8358 6 16.5073 6.67157 16.5073 7.5C16.5073 8.32843 15.8358 9 15.0073 9C14.1789 9 13.5073 8.32843 13.5073 7.5C13.5073 6.67157 14.1789 6 15.0073 6Z"
fill="white"
/>
</svg>`
,
i
=
`<svg
id="closeIcon"
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M18 18L6 6M6 18L18 6"
stroke="white"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
/>
</svg>`
;
if
(
!
document
.
getElementById
(
'dify-chatbot-bubble-button'
))
{
e
=
document
.
createElement
(
'div'
);
(
e
.
id
=
'dify-chatbot-bubble-button'
),
(
e
.
style
.
cssText
=
'position: fixed; bottom: 1rem; right: 1rem; width: 50px; height: 50px; border-radius: 25px; background-color: #155EEF; box-shadow: rgba(0, 0, 0, 0.2) 0px 4px 8px 0px; cursor: pointer; z-index: 2147483647; transition: all 0.2s ease-in-out 0s; left: unset; transform: scale(1); :hover {transform: scale(1.1);}'
);
const
d
=
document
.
createElement
(
'div'
);
(
d
.
style
.
cssText
=
'display: flex; align-items: center; justify-content: center; width: 100%; height: 100%; z-index: 2147483647;'
),
(
d
.
innerHTML
=
n
),
e
.
appendChild
(
d
),
document
.
body
.
appendChild
(
e
),
e
.
addEventListener
(
'click'
,
function
()
{
var
e
=
document
.
getElementById
(
'dify-chatbot-bubble-window'
);
e
?
'none'
===
e
.
style
.
display
?
((
e
.
style
.
display
=
'block'
),
(
d
.
innerHTML
=
i
))
:
((
e
.
style
.
display
=
'none'
),
(
d
.
innerHTML
=
n
))
:
(((
e
=
document
.
createElement
(
'iframe'
)).
allow
=
'fullscreen;microphone'
),
(
e
.
title
=
'dify chatbot bubble window'
),
(
e
.
id
=
'dify-chatbot-bubble-window'
),
(
e
.
src
=
o
+
'/chatbot/'
+
t
.
token
),
(
e
.
style
.
cssText
=
'border: none; position: fixed; flex-direction: column; justify-content: space-between; box-shadow: rgba(150, 150, 150, 0.2) 0px 10px 30px 0px, rgba(150, 150, 150, 0.2) 0px 0px 0px 1px; bottom: 5rem; right: 1rem; width: 24rem; height: 40rem; border-radius: 0.75rem; display: flex; z-index: 2147483647; overflow: hidden; left: unset; background-color: #F3F4F6;'
),
document
.
body
.
appendChild
(
e
),
(
d
.
innerHTML
=
i
));
});
}
}
else
console
.
error
(
'difyChatbotConfig is empty or token is not provided'
);
}
document
.
body
.
onload
=
embedChatbot
;
client/src/components/Icon/icons/outlink/iframe.svg
0 → 100644
View file @
f65a7282
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg
t=
"1690507072538"
class=
"icon"
viewBox=
"0 0 1194 1024"
version=
"1.1"
xmlns=
"http://www.w3.org/2000/svg"
p-id=
"2735"
xmlns:xlink=
"http://www.w3.org/1999/xlink"
width=
"74.625"
height=
"64"
><path
d=
"M1095.111111 47.388444A66.389333 66.389333 0 0 1 1161.443556 113.777778v796.444444a66.389333 66.389333 0 0 1-66.332445 66.389334H99.555556A66.389333 66.389333 0 0 1 33.166222 910.222222V113.777778A66.389333 66.389333 0 0 1 99.555556 47.388444h995.555555z m-33.223111 199.111112H132.721778a33.166222 33.166222 0 0 0-33.166222 33.223111v597.333333a33.166222 33.166222 0 0 0 33.166222 33.166222h929.166222a33.166222 33.166222 0 0 0 33.223111-33.166222v-597.333333a33.223111 33.223111 0 0 0-33.223111-33.223111zM165.888 113.777778a33.166222 33.166222 0 1 0 0 66.389333 33.166222 33.166222 0 0 0 0-66.389333z m99.555556 0a33.166222 33.166222 0 1 0 0 66.389333 33.166222 33.166222 0 0 0 0-66.389333z m99.555555 0a33.166222 33.166222 0 1 0 0 66.389333 33.166222 33.166222 0 0 0 0-66.389333z"
fill=
"#21D4ED"
p-id=
"2736"
></path><path
d=
"M530.944 445.610667H995.555556c22.129778 0 33.166222 11.093333 33.166222 33.223111v331.832889c0 22.129778-11.036444 33.166222-33.166222 33.166222H530.944c-22.129778 0-33.166222-11.036444-33.166222-33.166222V478.833778c0-22.186667 11.036444-33.223111 33.166222-33.223111z"
fill=
"#21D4ED"
p-id=
"2737"
></path></svg>
\ No newline at end of file
client/src/components/Icon/icons/outlink/iframe.svg:Zone.Identifier
0 → 100644
View file @
f65a7282
client/src/components/Icon/icons/outlink/share.svg
0 → 100644
View file @
f65a7282
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg
t=
"1690507057466"
class=
"icon"
viewBox=
"0 0 1024 1024"
version=
"1.1"
xmlns=
"http://www.w3.org/2000/svg"
p-id=
"2581"
xmlns:xlink=
"http://www.w3.org/1999/xlink"
width=
"64"
height=
"64"
><path
d=
"M816 416a174.816 174.816 0 0 1-133.6-62.624l-219.616 104.672a222.944 222.944 0 0 1-1.216 174.656l173.696 89.984A179.84 179.84 0 1 1 611.2 784l-185.056-96a224 224 0 1 1 2.912-284.8l221.44-105.6A175.552 175.552 0 1 1 816 416z"
fill=
"#3399FF"
p-id=
"2582"
></path></svg>
\ No newline at end of file
client/src/components/Icon/index.tsx
View file @
f65a7282
...
@@ -70,7 +70,9 @@ const map = {
...
@@ -70,7 +70,9 @@ const map = {
loginoutLight
:
require
(
'./icons/light/loginout.svg'
).
default
,
loginoutLight
:
require
(
'./icons/light/loginout.svg'
).
default
,
chatModelTag
:
require
(
'./icons/light/chatModelTag.svg'
).
default
,
chatModelTag
:
require
(
'./icons/light/chatModelTag.svg'
).
default
,
language_en
:
require
(
'./icons/language/en.svg'
).
default
,
language_en
:
require
(
'./icons/language/en.svg'
).
default
,
language_zh
:
require
(
'./icons/language/zh.svg'
).
default
language_zh
:
require
(
'./icons/language/zh.svg'
).
default
,
outlink_share
:
require
(
'./icons/outlink/share.svg'
).
default
,
outlink_iframe
:
require
(
'./icons/outlink/iframe.svg'
).
default
};
};
export
type
IconName
=
keyof
typeof
map
;
export
type
IconName
=
keyof
typeof
map
;
...
...
client/src/components/Radio/index.tsx
View file @
f65a7282
...
@@ -6,12 +6,20 @@ import MyIcon from '@/components/Icon';
...
@@ -6,12 +6,20 @@ import MyIcon from '@/components/Icon';
// @ts-ignore
// @ts-ignore
interface
Props
extends
GridProps
{
interface
Props
extends
GridProps
{
list
:
{
icon
?:
string
;
title
:
string
;
desc
?:
string
;
value
:
string
|
number
}[];
list
:
{
icon
?:
string
;
title
:
string
;
desc
?:
string
;
value
:
string
|
number
}[];
iconSize
?:
string
;
align
?:
'top'
|
'center'
;
align
?:
'top'
|
'center'
;
value
:
string
|
number
;
value
:
string
|
number
;
onChange
:
(
e
:
string
|
number
)
=>
void
;
onChange
:
(
e
:
string
|
number
)
=>
void
;
}
}
const
MyRadio
=
({
list
,
value
,
align
=
'center'
,
onChange
,
...
props
}:
Props
)
=>
{
const
MyRadio
=
({
list
,
value
,
align
=
'center'
,
iconSize
=
'18px'
,
onChange
,
...
props
}:
Props
)
=>
{
const
theme
=
useTheme
();
const
theme
=
useTheme
();
return
(
return
(
<
Grid
gridGap=
{
[
3
,
5
]
}
fontSize=
{
[
'sm'
,
'md'
]
}
{
...
props
}
>
<
Grid
gridGap=
{
[
3
,
5
]
}
fontSize=
{
[
'sm'
,
'md'
]
}
{
...
props
}
>
...
@@ -60,7 +68,7 @@ const MyRadio = ({ list, value, align = 'center', onChange, ...props }: Props) =
...
@@ -60,7 +68,7 @@ const MyRadio = ({ list, value, align = 'center', onChange, ...props }: Props) =
}
}
}
}
onClick=
{
()
=>
onChange
(
item
.
value
)
}
onClick=
{
()
=>
onChange
(
item
.
value
)
}
>
>
{
!!
item
.
icon
&&
<
MyIcon
mr=
{
'14px'
}
name=
{
item
.
icon
as
any
}
w=
{
'18px'
}
/>
}
{
!!
item
.
icon
&&
<
MyIcon
mr=
{
'14px'
}
name=
{
item
.
icon
as
any
}
w=
{
iconSize
}
/>
}
<
Box
>
<
Box
>
<
Box
>
{
item
.
title
}
</
Box
>
<
Box
>
{
item
.
title
}
</
Box
>
{
!!
item
.
desc
&&
(
{
!!
item
.
desc
&&
(
...
...
client/src/constants/chat.ts
View file @
f65a7282
...
@@ -57,5 +57,10 @@ export enum ChatModuleEnum {
...
@@ -57,5 +57,10 @@ export enum ChatModuleEnum {
'CQ'
=
'Classify Question'
'CQ'
=
'Classify Question'
}
}
export
enum
OutLinkTypeEnum
{
'share'
=
'share'
,
'iframe'
=
'iframe'
}
export
const
HUMAN_ICON
=
`https://fastgpt.run/icon/human.png`
;
export
const
HUMAN_ICON
=
`https://fastgpt.run/icon/human.png`
;
export
const
LOGO_ICON
=
`https://fastgpt.run/icon/logo.png`
;
export
const
LOGO_ICON
=
`https://fastgpt.run/icon/logo.png`
;
client/src/pages/api/app/del.ts
View file @
f65a7282
import
type
{
NextApiRequest
,
NextApiResponse
}
from
'next'
;
import
type
{
NextApiRequest
,
NextApiResponse
}
from
'next'
;
import
{
jsonRes
}
from
'@/service/response'
;
import
{
jsonRes
}
from
'@/service/response'
;
import
{
Chat
,
App
,
connectToDatabase
,
Collection
,
ShareChat
}
from
'@/service/mongo'
;
import
{
Chat
,
App
,
connectToDatabase
,
Collection
,
OutLink
}
from
'@/service/mongo'
;
import
{
authUser
}
from
'@/service/utils/auth'
;
import
{
authUser
}
from
'@/service/utils/auth'
;
import
{
authApp
}
from
'@/service/utils/auth'
;
import
{
authApp
}
from
'@/service/utils/auth'
;
...
@@ -35,7 +35,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
...
@@ -35,7 +35,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
});
});
// 删除分享链接
// 删除分享链接
await
ShareChat
.
deleteMany
({
await
OutLink
.
deleteMany
({
appId
appId
});
});
...
...
client/src/pages/api/chat/shareChat/create.ts
View file @
f65a7282
import
type
{
NextApiRequest
,
NextApiResponse
}
from
'next'
;
import
type
{
NextApiRequest
,
NextApiResponse
}
from
'next'
;
import
{
jsonRes
}
from
'@/service/response'
;
import
{
jsonRes
}
from
'@/service/response'
;
import
{
connectToDatabase
,
ShareChat
}
from
'@/service/mongo'
;
import
{
connectToDatabase
,
OutLink
}
from
'@/service/mongo'
;
import
{
authApp
,
authUser
}
from
'@/service/utils/auth'
;
import
{
authApp
,
authUser
}
from
'@/service/utils/auth'
;
import
type
{
ShareChatEditType
}
from
'@/types/app'
;
import
type
{
ShareChatEditType
}
from
'@/types/app'
;
import
{
customAlphabet
}
from
'nanoid'
;
import
{
customAlphabet
}
from
'nanoid'
;
...
@@ -23,7 +23,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
...
@@ -23,7 +23,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
});
});
const
shareId
=
nanoid
();
const
shareId
=
nanoid
();
await
ShareChat
.
create
({
await
OutLink
.
create
({
shareId
,
shareId
,
userId
,
userId
,
appId
,
appId
,
...
...
client/src/pages/api/chat/shareChat/delete.ts
View file @
f65a7282
import
type
{
NextApiRequest
,
NextApiResponse
}
from
'next'
;
import
type
{
NextApiRequest
,
NextApiResponse
}
from
'next'
;
import
{
jsonRes
}
from
'@/service/response'
;
import
{
jsonRes
}
from
'@/service/response'
;
import
{
connectToDatabase
,
ShareChat
}
from
'@/service/mongo'
;
import
{
connectToDatabase
,
OutLink
}
from
'@/service/mongo'
;
import
{
authUser
}
from
'@/service/utils/auth'
;
import
{
authUser
}
from
'@/service/utils/auth'
;
/* delete a shareChat by shareChatId */
/* delete a shareChat by shareChatId */
...
@@ -14,7 +14,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
...
@@ -14,7 +14,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
const
{
userId
}
=
await
authUser
({
req
,
authToken
:
true
});
const
{
userId
}
=
await
authUser
({
req
,
authToken
:
true
});
await
ShareChat
.
findOneAndRemove
({
await
OutLink
.
findOneAndRemove
({
_id
:
id
,
_id
:
id
,
userId
userId
});
});
...
...
client/src/pages/api/chat/shareChat/init.ts
View file @
f65a7282
import
type
{
NextApiRequest
,
NextApiResponse
}
from
'next'
;
import
type
{
NextApiRequest
,
NextApiResponse
}
from
'next'
;
import
{
jsonRes
}
from
'@/service/response'
;
import
{
jsonRes
}
from
'@/service/response'
;
import
{
connectToDatabase
,
ShareChat
,
User
}
from
'@/service/mongo'
;
import
{
connectToDatabase
,
OutLink
,
User
}
from
'@/service/mongo'
;
import
type
{
InitShareChatResponse
}
from
'@/api/response/chat'
;
import
type
{
InitShareChatResponse
}
from
'@/api/response/chat'
;
import
{
authApp
}
from
'@/service/utils/auth'
;
import
{
authApp
}
from
'@/service/utils/auth'
;
import
{
HUMAN_ICON
}
from
'@/constants/chat'
;
import
{
HUMAN_ICON
}
from
'@/constants/chat'
;
...
@@ -20,7 +20,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
...
@@ -20,7 +20,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
await
connectToDatabase
();
await
connectToDatabase
();
// get shareChat
// get shareChat
const
shareChat
=
await
ShareChat
.
findOne
({
shareId
});
const
shareChat
=
await
OutLink
.
findOne
({
shareId
});
if
(
!
shareChat
)
{
if
(
!
shareChat
)
{
return
jsonRes
(
res
,
{
return
jsonRes
(
res
,
{
...
...
client/src/pages/api/chat/shareChat/list.ts
View file @
f65a7282
import
type
{
NextApiRequest
,
NextApiResponse
}
from
'next'
;
import
type
{
NextApiRequest
,
NextApiResponse
}
from
'next'
;
import
{
jsonRes
}
from
'@/service/response'
;
import
{
jsonRes
}
from
'@/service/response'
;
import
{
connectToDatabase
,
ShareChat
}
from
'@/service/mongo'
;
import
{
connectToDatabase
,
OutLink
}
from
'@/service/mongo'
;
import
{
authUser
}
from
'@/service/utils/auth'
;
import
{
authUser
}
from
'@/service/utils/auth'
;
import
{
hashPassword
}
from
'@/service/utils/tools'
;
import
{
hashPassword
}
from
'@/service/utils/tools'
;
...
@@ -15,7 +15,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
...
@@ -15,7 +15,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
const
{
userId
}
=
await
authUser
({
req
,
authToken
:
true
});
const
{
userId
}
=
await
authUser
({
req
,
authToken
:
true
});
const
data
=
await
ShareChat
.
find
({
const
data
=
await
OutLink
.
find
({
appId
,
appId
,
userId
userId
}).
sort
({
}).
sort
({
...
...
client/src/pages/api/openapi/v1/chat/completions.ts
View file @
f65a7282
...
@@ -198,7 +198,8 @@ export default withNextCors(async function handler(req: NextApiRequest, res: Nex
...
@@ -198,7 +198,8 @@ export default withNextCors(async function handler(req: NextApiRequest, res: Nex
appId
,
appId
,
userId
,
userId
,
source
:
authType
===
'apikey'
?
BillSourceEnum
.
api
:
BillSourceEnum
.
fastgpt
,
source
:
authType
===
'apikey'
?
BillSourceEnum
.
api
:
BillSourceEnum
.
fastgpt
,
response
:
responseData
response
:
responseData
,
shareId
});
});
}
catch
(
err
:
any
)
{
}
catch
(
err
:
any
)
{
if
(
stream
)
{
if
(
stream
)
{
...
...
client/src/pages/app/detail/components/BasicEdit/index.tsx
View file @
f65a7282
...
@@ -261,12 +261,12 @@ const Settings = ({ appId }: { appId: string }) => {
...
@@ -261,12 +261,12 @@ const Settings = ({ appId }: { appId: string }) => {
router
.
replace
({
router
.
replace
({
query
:
{
query
:
{
appId
,
appId
,
currentTab
:
'
share
'
currentTab
:
'
outLink
'
}
}
});
});
}
}
}
}
>
>
分享
外接
</
Button
>
</
Button
>
<
Button
<
Button
size=
{
[
'sm'
,
'md'
]
}
size=
{
[
'sm'
,
'md'
]
}
...
...
client/src/pages/app/detail/components/
Share
.tsx
→
client/src/pages/app/detail/components/
OutLink
.tsx
View file @
f65a7282
...
@@ -14,7 +14,8 @@ import {
...
@@ -14,7 +14,8 @@ import {
ModalFooter
,
ModalFooter
,
ModalBody
,
ModalBody
,
FormControl
,
FormControl
,
Input
Input
,
useTheme
}
from
'@chakra-ui/react'
;
}
from
'@chakra-ui/react'
;
import
{
QuestionOutlineIcon
}
from
'@chakra-ui/icons'
;
import
{
QuestionOutlineIcon
}
from
'@chakra-ui/icons'
;
import
MyIcon
from
'@/components/Icon'
;
import
MyIcon
from
'@/components/Icon'
;
...
@@ -30,6 +31,7 @@ import { useRequest } from '@/hooks/useRequest';
...
@@ -30,6 +31,7 @@ import { useRequest } from '@/hooks/useRequest';
import
{
formatPrice
}
from
'@/utils/user'
;
import
{
formatPrice
}
from
'@/utils/user'
;
import
MyTooltip
from
'@/components/MyTooltip'
;
import
MyTooltip
from
'@/components/MyTooltip'
;
import
MyModal
from
'@/components/MyModal'
;
import
MyModal
from
'@/components/MyModal'
;
import
MyRadio
from
'@/components/Radio'
;
const
Share
=
({
appId
}:
{
appId
:
string
})
=>
{
const
Share
=
({
appId
}:
{
appId
:
string
})
=>
{
const
{
Loading
,
setIsLoading
}
=
useLoading
();
const
{
Loading
,
setIsLoading
}
=
useLoading
();
...
@@ -49,8 +51,6 @@ const Share = ({ appId }: { appId: string }) => {
...
@@ -49,8 +51,6 @@ const Share = ({ appId }: { appId: string }) => {
defaultValues
:
defaultShareChat
defaultValues
:
defaultShareChat
});
});
const
[
refresh
,
setRefresh
]
=
useState
(
false
);
const
{
const
{
isFetching
,
isFetching
,
data
:
shareChatList
=
[],
data
:
shareChatList
=
[],
...
@@ -77,7 +77,7 @@ const Share = ({ appId }: { appId: string }) => {
...
@@ -77,7 +77,7 @@ const Share = ({ appId }: { appId: string }) => {
<
Box
position=
{
'relative'
}
pt=
{
[
0
,
5
,
8
]
}
px=
{
[
5
,
8
]
}
minH=
{
'50vh'
}
>
<
Box
position=
{
'relative'
}
pt=
{
[
0
,
5
,
8
]
}
px=
{
[
5
,
8
]
}
minH=
{
'50vh'
}
>
<
Flex
justifyContent=
{
'space-between'
}
>
<
Flex
justifyContent=
{
'space-between'
}
>
<
Box
fontWeight=
{
'bold'
}
>
<
Box
fontWeight=
{
'bold'
}
>
免登录
聊天
窗口
免登录窗口
<
MyTooltip
<
MyTooltip
forceShow
forceShow
label=
"可以直接分享该模型给其他用户去进行对话,对方无需登录即可直接进行对话。注意,这个功能会消耗你账号的tokens。请保管好链接和密码。"
label=
"可以直接分享该模型给其他用户去进行对话,对方无需登录即可直接进行对话。注意,这个功能会消耗你账号的tokens。请保管好链接和密码。"
...
@@ -97,7 +97,7 @@ const Share = ({ appId }: { appId: string }) => {
...
@@ -97,7 +97,7 @@ const Share = ({ appId }: { appId: string }) => {
:
{}
)}
:
{}
)}
onClick=
{
onOpenCreateShareChat
}
onClick=
{
onOpenCreateShareChat
}
>
>
创建新
窗口
创建新
链接
</
Button
>
</
Button
>
</
Flex
>
</
Flex
>
<
TableContainer
mt=
{
3
}
>
<
TableContainer
mt=
{
3
}
>
...
@@ -118,7 +118,7 @@ const Share = ({ appId }: { appId: string }) => {
...
@@ -118,7 +118,7 @@ const Share = ({ appId }: { appId: string }) => {
<
Td
>
{
item
.
lastTime
?
formatTimeToChatTime
(
item
.
lastTime
)
:
'未使用'
}
</
Td
>
<
Td
>
{
item
.
lastTime
?
formatTimeToChatTime
(
item
.
lastTime
)
:
'未使用'
}
</
Td
>
<
Td
>
<
Td
>
<
Flex
>
<
Flex
>
<
MyTooltip
label=
{
'复制分享
地址
'
}
>
<
MyTooltip
label=
{
'复制分享
链接
'
}
>
<
MyIcon
<
MyIcon
mr=
{
3
}
mr=
{
3
}
name=
"copy"
name=
"copy"
...
@@ -127,7 +127,7 @@ const Share = ({ appId }: { appId: string }) => {
...
@@ -127,7 +127,7 @@ const Share = ({ appId }: { appId: string }) => {
_hover=
{
{
color
:
'myBlue.600'
}
}
_hover=
{
{
color
:
'myBlue.600'
}
}
onClick=
{
()
=>
{
onClick=
{
()
=>
{
const
url
=
`${location.origin}/chat/share?shareId=${item.shareId}`
;
const
url
=
`${location.origin}/chat/share?shareId=${item.shareId}`
;
copyData
(
url
,
'已复制分享
地址
'
);
copyData
(
url
,
'已复制分享
链接
'
);
}
}
}
}
/>
/>
</
MyTooltip
>
</
MyTooltip
>
...
@@ -205,4 +205,47 @@ const Share = ({ appId }: { appId: string }) => {
...
@@ -205,4 +205,47 @@ const Share = ({ appId }: { appId: string }) => {
);
);
};
};
export
default
Share
;
enum
LinkTypeEnum
{
share
=
'share'
,
iframe
=
'iframe'
}
const
OutLink
=
({
appId
}:
{
appId
:
string
})
=>
{
const
theme
=
useTheme
();
const
[
linkType
,
setLinkType
]
=
useState
<
`
${
LinkTypeEnum
}
`
>
(
LinkTypeEnum
.
share
);
return
(
<
Box
pt=
{
[
1
,
5
]
}
>
<
Box
fontWeight=
{
'bold'
}
fontSize=
{
[
'md'
,
'xl'
]
}
mb=
{
2
}
px=
{
[
4
,
8
]
}
>
外部使用途径
</
Box
>
<
Box
pb=
{
[
5
,
7
]
}
px=
{
[
4
,
8
]
}
borderBottom=
{
theme
.
borders
.
base
}
>
<
MyRadio
gridTemplateColumns=
{
[
'repeat(1,1fr)'
,
'repeat(2, 350px)'
]
}
iconSize=
{
'20px'
}
list=
{
[
{
icon
:
'outlink_share'
,
title
:
'免登录窗口'
,
desc
:
'分享链接给其他用户,无需登录即可直接进行使用'
,
value
:
LinkTypeEnum
.
share
}
//
{
// icon: 'outlink_iframe',
// title: '网页嵌入',
// desc: '嵌入到已有网页中,右下角会生成对话按键',
// value: LinkTypeEnum.iframe
//
}
]
}
value=
{
linkType
}
onChange=
{
(
e
)
=>
setLinkType
(
e
as
`${LinkTypeEnum}`
)
}
/>
</
Box
>
{
linkType
===
LinkTypeEnum
.
share
&&
<
Share
appId=
{
appId
}
/>
}
</
Box
>
);
};
export
default
OutLink
;
client/src/pages/app/detail/index.tsx
View file @
f65a7282
...
@@ -20,7 +20,7 @@ const AdEdit = dynamic(() => import('./components/AdEdit'), {
...
@@ -20,7 +20,7 @@ const AdEdit = dynamic(() => import('./components/AdEdit'), {
ssr
:
false
,
ssr
:
false
,
loading
:
()
=>
<
Loading
/>
loading
:
()
=>
<
Loading
/>
});
});
const
Share
=
dynamic
(()
=>
import
(
'./components/Share
'
),
{
const
OutLink
=
dynamic
(()
=>
import
(
'./components/OutLink
'
),
{
ssr
:
false
ssr
:
false
});
});
const
API
=
dynamic
(()
=>
import
(
'./components/API'
),
{
const
API
=
dynamic
(()
=>
import
(
'./components/API'
),
{
...
@@ -30,7 +30,7 @@ const API = dynamic(() => import('./components/API'), {
...
@@ -30,7 +30,7 @@ const API = dynamic(() => import('./components/API'), {
enum
TabEnum
{
enum
TabEnum
{
'basicEdit'
=
'basicEdit'
,
'basicEdit'
=
'basicEdit'
,
'adEdit'
=
'adEdit'
,
'adEdit'
=
'adEdit'
,
'
share'
=
'share
'
,
'
outLink'
=
'outLink
'
,
'API'
=
'API'
'API'
=
'API'
}
}
...
@@ -57,7 +57,7 @@ const AppDetail = ({ currentTab }: { currentTab: `${TabEnum}` }) => {
...
@@ -57,7 +57,7 @@ const AppDetail = ({ currentTab }: { currentTab: `${TabEnum}` }) => {
()
=>
[
()
=>
[
{
label
:
'简易配置'
,
id
:
TabEnum
.
basicEdit
,
icon
:
'overviewLight'
},
{
label
:
'简易配置'
,
id
:
TabEnum
.
basicEdit
,
icon
:
'overviewLight'
},
{
label
:
'高级编排'
,
id
:
TabEnum
.
adEdit
,
icon
:
'settingLight'
},
{
label
:
'高级编排'
,
id
:
TabEnum
.
adEdit
,
icon
:
'settingLight'
},
{
label
:
'
链接分享'
,
id
:
TabEnum
.
share
,
icon
:
'shareLight'
},
{
label
:
'
外部使用'
,
id
:
TabEnum
.
outLink
,
icon
:
'shareLight'
},
{
label
:
'API访问'
,
id
:
TabEnum
.
API
,
icon
:
'apiLight'
},
{
label
:
'API访问'
,
id
:
TabEnum
.
API
,
icon
:
'apiLight'
},
{
label
:
'立即对话'
,
id
:
'startChat'
,
icon
:
'chat'
}
{
label
:
'立即对话'
,
id
:
'startChat'
,
icon
:
'chat'
}
],
],
...
@@ -178,7 +178,7 @@ const AppDetail = ({ currentTab }: { currentTab: `${TabEnum}` }) => {
...
@@ -178,7 +178,7 @@ const AppDetail = ({ currentTab }: { currentTab: `${TabEnum}` }) => {
/>
/>
)
}
)
}
{
currentTab
===
TabEnum
.
API
&&
<
API
appId=
{
appId
}
/>
}
{
currentTab
===
TabEnum
.
API
&&
<
API
appId=
{
appId
}
/>
}
{
currentTab
===
TabEnum
.
share
&&
<
Share
appId=
{
appId
}
/>
}
{
currentTab
===
TabEnum
.
outLink
&&
<
OutLink
appId=
{
appId
}
/>
}
</
Box
>
</
Box
>
</
Flex
>
</
Flex
>
</
PageContainer
>
</
PageContainer
>
...
...
client/src/pages/chat/share.tsx
View file @
f65a7282
...
@@ -20,7 +20,7 @@ import ChatHeader from './components/ChatHeader';
...
@@ -20,7 +20,7 @@ import ChatHeader from './components/ChatHeader';
import
ChatHistorySlider
from
'./components/ChatHistorySlider'
;
import
ChatHistorySlider
from
'./components/ChatHistorySlider'
;
import
{
serviceSideProps
}
from
'@/utils/i18n'
;
import
{
serviceSideProps
}
from
'@/utils/i18n'
;
const
ShareChat
=
({
shareId
,
chatId
}:
{
shareId
:
string
;
chatId
:
string
})
=>
{
const
OutLink
=
({
shareId
,
chatId
}:
{
shareId
:
string
;
chatId
:
string
})
=>
{
const
router
=
useRouter
();
const
router
=
useRouter
();
const
{
toast
}
=
useToast
();
const
{
toast
}
=
useToast
();
const
{
isOpen
:
isOpenSlider
,
onClose
:
onCloseSlider
,
onOpen
:
onOpenSlider
}
=
useDisclosure
();
const
{
isOpen
:
isOpenSlider
,
onClose
:
onCloseSlider
,
onOpen
:
onOpenSlider
}
=
useDisclosure
();
...
@@ -250,4 +250,4 @@ export async function getServerSideProps(context: any) {
...
@@ -250,4 +250,4 @@ export async function getServerSideProps(context: any) {
};
};
}
}
export
default
ShareChat
;
export
default
OutLink
;
client/src/service/events/pushBill.ts
View file @
f65a7282
import
{
connectToDatabase
,
Bill
,
User
,
ShareChat
}
from
'../mongo'
;
import
{
connectToDatabase
,
Bill
,
User
,
OutLink
}
from
'../mongo'
;
import
{
BillSourceEnum
}
from
'@/constants/user'
;
import
{
BillSourceEnum
}
from
'@/constants/user'
;
import
{
getModel
}
from
'../utils/data'
;
import
{
getModel
}
from
'../utils/data'
;
import
{
ChatHistoryItemResType
}
from
'@/types/chat'
;
import
{
ChatHistoryItemResType
}
from
'@/types/chat'
;
...
@@ -59,7 +59,7 @@ export const updateShareChatBill = async ({
...
@@ -59,7 +59,7 @@ export const updateShareChatBill = async ({
total
:
number
;
total
:
number
;
})
=>
{
})
=>
{
try
{
try
{
await
ShareChat
.
findOneAndUpdate
(
await
OutLink
.
findOneAndUpdate
(
{
shareId
},
{
shareId
},
{
{
$inc
:
{
total
},
$inc
:
{
total
},
...
...
client/src/service/models/
shareChat
.ts
→
client/src/service/models/
outLink
.ts
View file @
f65a7282
import
{
Schema
,
model
,
models
,
Model
}
from
'mongoose'
;
import
{
Schema
,
model
,
models
,
Model
}
from
'mongoose'
;
import
{
ShareChatSchema
as
ShareChatSchemaType
}
from
'@/types/mongoSchema'
;
import
{
OutLinkSchema
as
SchmaType
}
from
'@/types/mongoSchema'
;
import
{
OutLinkTypeEnum
}
from
'@/constants/chat'
;
const
ShareChat
Schema
=
new
Schema
({
const
OutLink
Schema
=
new
Schema
({
shareId
:
{
shareId
:
{
type
:
String
,
type
:
String
,
required
:
true
required
:
true
...
@@ -16,6 +17,10 @@ const ShareChatSchema = new Schema({
...
@@ -16,6 +17,10 @@ const ShareChatSchema = new Schema({
ref
:
'model'
,
ref
:
'model'
,
required
:
true
required
:
true
},
},
type
:
{
type
:
String
,
default
:
OutLinkTypeEnum
.
share
},
name
:
{
name
:
{
type
:
String
,
type
:
String
,
required
:
true
required
:
true
...
@@ -29,5 +34,4 @@ const ShareChatSchema = new Schema({
...
@@ -29,5 +34,4 @@ const ShareChatSchema = new Schema({
}
}
});
});
export
const
ShareChat
:
Model
<
ShareChatSchemaType
>
=
export
const
OutLink
:
Model
<
SchmaType
>
=
models
[
'outlinks'
]
||
model
(
'outlinks'
,
OutLinkSchema
);
models
[
'shareChat'
]
||
model
(
'shareChat'
,
ShareChatSchema
);
client/src/service/mongo.ts
View file @
f65a7282
...
@@ -120,7 +120,7 @@ export * from './models/trainingData';
...
@@ -120,7 +120,7 @@ export * from './models/trainingData';
export
*
from
'./models/openapi'
;
export
*
from
'./models/openapi'
;
export
*
from
'./models/promotionRecord'
;
export
*
from
'./models/promotionRecord'
;
export
*
from
'./models/collection'
;
export
*
from
'./models/collection'
;
export
*
from
'./models/
shareChat
'
;
export
*
from
'./models/
outLink
'
;
export
*
from
'./models/kb'
;
export
*
from
'./models/kb'
;
export
*
from
'./models/inform'
;
export
*
from
'./models/inform'
;
export
*
from
'./models/image'
;
export
*
from
'./models/image'
;
client/src/service/utils/auth.ts
View file @
f65a7282
import
type
{
NextApiRequest
}
from
'next'
;
import
type
{
NextApiRequest
}
from
'next'
;
import
jwt
from
'jsonwebtoken'
;
import
jwt
from
'jsonwebtoken'
;
import
Cookie
from
'cookie'
;
import
Cookie
from
'cookie'
;
import
{
App
,
OpenApi
,
User
,
ShareChat
,
KB
}
from
'../mongo'
;
import
{
App
,
OpenApi
,
User
,
OutLink
,
KB
}
from
'../mongo'
;
import
type
{
AppSchema
}
from
'@/types/mongoSchema'
;
import
type
{
AppSchema
}
from
'@/types/mongoSchema'
;
import
{
formatPrice
}
from
'@/utils/user'
;
import
{
formatPrice
}
from
'@/utils/user'
;
import
{
ERROR_ENUM
}
from
'../errorCode'
;
import
{
ERROR_ENUM
}
from
'../errorCode'
;
...
@@ -216,7 +216,7 @@ export const authKb = async ({ kbId, userId }: { kbId: string; userId: string })
...
@@ -216,7 +216,7 @@ export const authKb = async ({ kbId, userId }: { kbId: string; userId: string })
export
const
authShareChat
=
async
({
shareId
}:
{
shareId
:
string
})
=>
{
export
const
authShareChat
=
async
({
shareId
}:
{
shareId
:
string
})
=>
{
// get shareChat
// get shareChat
const
shareChat
=
await
ShareChat
.
findOne
({
shareId
});
const
shareChat
=
await
OutLink
.
findOne
({
shareId
});
if
(
!
shareChat
)
{
if
(
!
shareChat
)
{
return
Promise
.
reject
(
'分享链接已失效'
);
return
Promise
.
reject
(
'分享链接已失效'
);
...
...
client/src/types/mongoSchema.d.ts
View file @
f65a7282
...
@@ -135,7 +135,7 @@ export interface PromotionRecordSchema {
...
@@ -135,7 +135,7 @@ export interface PromotionRecordSchema {
amount
:
number
;
amount
:
number
;
}
}
export
interface
ShareChat
Schema
{
export
interface
OutLink
Schema
{
_id
:
string
;
_id
:
string
;
shareId
:
string
;
shareId
:
string
;
userId
:
string
;
userId
:
string
;
...
...
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