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
371e0e36
authored
May 15, 2023
by
archer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
perf: error show
parent
e7d3a8e2
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
53 additions
and
32 deletions
+53
-32
src/components/Layout/index.tsx
+1
-1
src/pages/_error.tsx
+3
-1
src/pages/api/model/data/pushModelDataCsv.ts
+8
-0
src/pages/chat/components/Empty.tsx
+7
-0
src/pages/chat/index.tsx
+13
-17
src/pages/chat/share.tsx
+8
-10
src/pages/login/index.tsx
+1
-1
src/pages/model/components/detail/index.tsx
+10
-1
src/pages/model/index.tsx
+1
-1
src/utils/tools.ts
+1
-0
No files found.
src/components/Layout/index.tsx
View file @
371e0e36
...
@@ -78,6 +78,6 @@ export default Layout;
...
@@ -78,6 +78,6 @@ export default Layout;
Layout
.
getInitialProps
=
({
req
}:
any
)
=>
{
Layout
.
getInitialProps
=
({
req
}:
any
)
=>
{
return
{
return
{
isPcDevice
:
!
/Mobile/
.
test
(
req
?
req
.
headers
[
'user-agent'
]
:
navigator
.
userAgent
)
isPcDevice
:
!
/Mobile/
.
test
(
req
?.
headers
?.[
'user-agent'
]
)
};
};
};
};
src/pages/_error.tsx
View file @
371e0e36
...
@@ -4,7 +4,9 @@ function Error({ errStr }: { errStr: string }) {
...
@@ -4,7 +4,9 @@ function Error({ errStr }: { errStr: string }) {
Error
.
getInitialProps
=
({
res
,
err
}:
{
res
:
any
;
err
:
any
})
=>
{
Error
.
getInitialProps
=
({
res
,
err
}:
{
res
:
any
;
err
:
any
})
=>
{
console
.
log
(
err
);
console
.
log
(
err
);
return
{
errStr
:
JSON
.
stringify
(
err
)
};
return
{
errStr
:
`部分系统不兼容,导致页面崩溃。如果可以,请联系作者,反馈下具体操作和页面。大部分是 苹果 的 safari 浏览器导致,可以尝试更换 chrome 浏览器。`
};
};
};
export
default
Error
;
export
default
Error
;
src/pages/api/model/data/pushModelDataCsv.ts
View file @
371e0e36
...
@@ -89,3 +89,11 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
...
@@ -89,3 +89,11 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
});
});
}
}
}
}
export
const
config
=
{
api
:
{
bodyParser
:
{
sizeLimit
:
'100mb'
}
}
};
src/pages/chat/components/Empty.tsx
View file @
371e0e36
...
@@ -5,8 +5,10 @@ import Markdown from '@/components/Markdown';
...
@@ -5,8 +5,10 @@ import Markdown from '@/components/Markdown';
import
{
LOGO_ICON
}
from
'@/constants/chat'
;
import
{
LOGO_ICON
}
from
'@/constants/chat'
;
const
Empty
=
({
const
Empty
=
({
showChatProblem
,
model
:
{
name
,
intro
,
avatar
}
model
:
{
name
,
intro
,
avatar
}
}:
{
}:
{
showChatProblem
:
boolean
;
model
:
{
model
:
{
name
:
string
;
name
:
string
;
intro
:
string
;
intro
:
string
;
...
@@ -43,6 +45,9 @@ const Empty = ({
...
@@ -43,6 +45,9 @@ const Empty = ({
<
Box
whiteSpace=
{
'pre-line'
}
>
{
intro
}
</
Box
>
<
Box
whiteSpace=
{
'pre-line'
}
>
{
intro
}
</
Box
>
</
Card
>
</
Card
>
)
}
)
}
{
showChatProblem
&&
(
<>
{
/* version intro */
}
{
/* version intro */
}
<
Card
p=
{
4
}
mb=
{
10
}
>
<
Card
p=
{
4
}
mb=
{
10
}
>
<
Markdown
source=
{
versionIntro
}
/>
<
Markdown
source=
{
versionIntro
}
/>
...
@@ -50,6 +55,8 @@ const Empty = ({
...
@@ -50,6 +55,8 @@ const Empty = ({
<
Card
p=
{
4
}
>
<
Card
p=
{
4
}
>
<
Markdown
source=
{
chatProblem
}
/>
<
Markdown
source=
{
chatProblem
}
/>
</
Card
>
</
Card
>
</>
)
}
</
Box
>
</
Box
>
);
);
};
};
...
...
src/pages/chat/index.tsx
View file @
371e0e36
...
@@ -36,12 +36,11 @@ import { useToast } from '@/hooks/useToast';
...
@@ -36,12 +36,11 @@ import { useToast } from '@/hooks/useToast';
import
{
useScreen
}
from
'@/hooks/useScreen'
;
import
{
useScreen
}
from
'@/hooks/useScreen'
;
import
{
useQuery
}
from
'@tanstack/react-query'
;
import
{
useQuery
}
from
'@tanstack/react-query'
;
import
dynamic
from
'next/dynamic'
;
import
dynamic
from
'next/dynamic'
;
import
{
useCopyData
,
voiceBroadcast
,
formatLinkTextToHtml
}
from
'@/utils/tools'
;
import
{
useCopyData
,
voiceBroadcast
,
hasVoiceApi
}
from
'@/utils/tools'
;
import
{
streamFetch
}
from
'@/api/fetch'
;
import
{
streamFetch
}
from
'@/api/fetch'
;
import
MyIcon
from
'@/components/Icon'
;
import
MyIcon
from
'@/components/Icon'
;
import
{
throttle
}
from
'lodash'
;
import
{
throttle
}
from
'lodash'
;
import
{
Types
}
from
'mongoose'
;
import
{
Types
}
from
'mongoose'
;
import
Markdown
from
'@/components/Markdown'
;
import
{
LOGO_ICON
}
from
'@/constants/chat'
;
import
{
LOGO_ICON
}
from
'@/constants/chat'
;
import
{
ChatModelMap
}
from
'@/constants/model'
;
import
{
ChatModelMap
}
from
'@/constants/model'
;
import
{
useChatStore
}
from
'@/store/chat'
;
import
{
useChatStore
}
from
'@/store/chat'
;
...
@@ -50,19 +49,16 @@ import { fileDownload } from '@/utils/file';
...
@@ -50,19 +49,16 @@ import { fileDownload } from '@/utils/file';
import
{
htmlTemplate
}
from
'@/constants/common'
;
import
{
htmlTemplate
}
from
'@/constants/common'
;
import
{
useUserStore
}
from
'@/store/user'
;
import
{
useUserStore
}
from
'@/store/user'
;
import
Loading
from
'@/components/Loading'
;
import
Loading
from
'@/components/Loading'
;
import
Markdown
from
'@/components/Markdown'
;
import
Empty
from
'./components/Empty'
;
const
PhoneSliderBar
=
dynamic
(()
=>
import
(
'./components/PhoneSliderBar'
),
{
const
PhoneSliderBar
=
dynamic
(()
=>
import
(
'./components/PhoneSliderBar'
),
{
loading
:
()
=>
<
Loading
fixed=
{
false
}
/>,
ssr
:
false
ssr
:
false
});
});
const
History
=
dynamic
(()
=>
import
(
'./components/History'
),
{
const
History
=
dynamic
(()
=>
import
(
'./components/History'
),
{
loading
:
()
=>
<
Loading
fixed=
{
false
}
/>,
loading
:
()
=>
<
Loading
fixed=
{
false
}
/>,
ssr
:
false
ssr
:
false
});
});
const
Empty
=
dynamic
(()
=>
import
(
'./components/Empty'
),
{
loading
:
()
=>
<
Loading
fixed=
{
false
}
/>,
ssr
:
false
});
import
styles
from
'./index.module.scss'
;
import
styles
from
'./index.module.scss'
;
...
@@ -77,7 +73,6 @@ const Chat = ({
...
@@ -77,7 +73,6 @@ const Chat = ({
chatId
:
string
;
chatId
:
string
;
isPcDevice
:
boolean
;
isPcDevice
:
boolean
;
})
=>
{
})
=>
{
const
hasVoiceApi
=
typeof
window
===
'undefined'
?
false
:
!!
window
.
speechSynthesis
;
const
router
=
useRouter
();
const
router
=
useRouter
();
const
theme
=
useTheme
();
const
theme
=
useTheme
();
...
@@ -627,7 +622,6 @@ const Chat = ({
...
@@ -627,7 +622,6 @@ const Chat = ({
chatData.model.canUse,
chatData.model.canUse,
chatData.modelId,
chatData.modelId,
delChatRecord,
delChatRecord,
hasVoiceApi,
onclickCopy,
onclickCopy,
router,
router,
theme.borders.base
theme.borders.base
...
@@ -714,7 +708,7 @@ const Chat = ({
...
@@ -714,7 +708,7 @@ const Chat = ({
justifyContent={'space-between'}
justifyContent={'space-between'}
py={[3, 5]}
py={[3, 5]}
px={5}
px={5}
borderBottom={'1px solid
'}
borderBottom={'1px solid'}
borderBottomColor={useColorModeValue('gray.200', 'gray.700')}
borderBottomColor={useColorModeValue('gray.200', 'gray.700')}
color={useColorModeValue('myGray.900', 'white')}
color={useColorModeValue('myGray.900', 'white')}
>
>
...
@@ -790,7 +784,10 @@ const Chat = ({
...
@@ -790,7 +784,10 @@ const Chat = ({
order: 1,
order: 1,
mr: ['6px', 2],
mr: ['6px', 2],
cursor: 'pointer',
cursor: 'pointer',
onClick: () => isPc && router.push(`/model?modelId=${chatData.modelId}`)
onClick: () =>
isPc &&
chatData.model.canUse &&
router.push(`/model?modelId=${chatData.modelId}`)
}
}
: {
: {
order: 3,
order: 3,
...
@@ -856,17 +853,16 @@ const Chat = ({
...
@@ -856,17 +853,16 @@ const Chat = ({
bg={'myBlue.300'}
bg={'myBlue.300'}
onContextMenu={(e) => onclickContextMenu(e, item)}
onContextMenu={(e) => onclickContextMenu(e, item)}
>
>
<Box
<Box as={'p'}>{item.value}</Box>
as={'p'}
dangerouslySetInnerHTML={{ __html: formatLinkTextToHtml(item.value) }}
/>
</Card>
</Card>
</Box>
</Box>
)}
)}
</Flex>
</Flex>
</Flex>
</Flex>
))}
))}
{chatData.history.length === 0 && <Empty model={chatData.model} />}
{chatData.history.length === 0 && (
<Empty model={chatData.model} showChatProblem={true} />
)}
</Box>
</Box>
</Box>
</Box>
{/* 发送区 */}
{/* 发送区 */}
...
@@ -1012,7 +1008,7 @@ Chat.getInitialProps = ({ query, req }: any) => {
...
@@ -1012,7 +1008,7 @@ Chat.getInitialProps = ({ query, req }: any) => {
return
{
return
{
modelId
:
query
?.
modelId
||
''
,
modelId
:
query
?.
modelId
||
''
,
chatId
:
query
?.
chatId
||
''
,
chatId
:
query
?.
chatId
||
''
,
isPcDevice
:
!
/Mobile/
.
test
(
req
?
req
.
headers
[
'user-agent'
]
:
navigator
.
userAgent
)
isPcDevice
:
!
/Mobile/
.
test
(
req
?.
headers
?.[
'user-agent'
]
)
};
};
};
};
...
...
src/pages/chat/share.tsx
View file @
371e0e36
...
@@ -34,12 +34,11 @@ import { useToast } from '@/hooks/useToast';
...
@@ -34,12 +34,11 @@ import { useToast } from '@/hooks/useToast';
import
{
useScreen
}
from
'@/hooks/useScreen'
;
import
{
useScreen
}
from
'@/hooks/useScreen'
;
import
{
useQuery
}
from
'@tanstack/react-query'
;
import
{
useQuery
}
from
'@tanstack/react-query'
;
import
dynamic
from
'next/dynamic'
;
import
dynamic
from
'next/dynamic'
;
import
{
useCopyData
,
voiceBroadcast
}
from
'@/utils/tools'
;
import
{
useCopyData
,
voiceBroadcast
,
hasVoiceApi
}
from
'@/utils/tools'
;
import
{
streamFetch
}
from
'@/api/fetch'
;
import
{
streamFetch
}
from
'@/api/fetch'
;
import
MyIcon
from
'@/components/Icon'
;
import
MyIcon
from
'@/components/Icon'
;
import
{
throttle
}
from
'lodash'
;
import
{
throttle
}
from
'lodash'
;
import
{
Types
}
from
'mongoose'
;
import
{
Types
}
from
'mongoose'
;
import
Markdown
from
'@/components/Markdown'
;
import
{
LOGO_ICON
}
from
'@/constants/chat'
;
import
{
LOGO_ICON
}
from
'@/constants/chat'
;
import
{
useChatStore
}
from
'@/store/chat'
;
import
{
useChatStore
}
from
'@/store/chat'
;
import
{
useLoading
}
from
'@/hooks/useLoading'
;
import
{
useLoading
}
from
'@/hooks/useLoading'
;
...
@@ -47,15 +46,13 @@ import { fileDownload } from '@/utils/file';
...
@@ -47,15 +46,13 @@ import { fileDownload } from '@/utils/file';
import
{
htmlTemplate
}
from
'@/constants/common'
;
import
{
htmlTemplate
}
from
'@/constants/common'
;
import
{
useUserStore
}
from
'@/store/user'
;
import
{
useUserStore
}
from
'@/store/user'
;
import
Loading
from
'@/components/Loading'
;
import
Loading
from
'@/components/Loading'
;
import
Markdown
from
'@/components/Markdown'
;
import
Empty
from
'./components/Empty'
;
const
ShareHistory
=
dynamic
(()
=>
import
(
'./components/ShareHistory'
),
{
const
ShareHistory
=
dynamic
(()
=>
import
(
'./components/ShareHistory'
),
{
loading
:
()
=>
<
Loading
fixed=
{
false
}
/>,
loading
:
()
=>
<
Loading
fixed=
{
false
}
/>,
ssr
:
false
ssr
:
false
});
});
const
Empty
=
dynamic
(()
=>
import
(
'./components/Empty'
),
{
loading
:
()
=>
<
Loading
fixed=
{
false
}
/>,
ssr
:
false
});
import
styles
from
'./index.module.scss'
;
import
styles
from
'./index.module.scss'
;
...
@@ -70,7 +67,6 @@ const Chat = ({
...
@@ -70,7 +67,6 @@ const Chat = ({
historyId
:
string
;
historyId
:
string
;
isPcDevice
:
boolean
;
isPcDevice
:
boolean
;
})
=>
{
})
=>
{
const
hasVoiceApi
=
typeof
window
===
'undefined'
?
false
:
!!
window
.
speechSynthesis
;
const
router
=
useRouter
();
const
router
=
useRouter
();
const
theme
=
useTheme
();
const
theme
=
useTheme
();
...
@@ -536,7 +532,7 @@ const Chat = ({
...
@@ -536,7 +532,7 @@ const Chat = ({
<MenuItem onClick={() => delShareChatHistoryItemById(historyId, index)}>删除</MenuItem>
<MenuItem onClick={() => delShareChatHistoryItemById(historyId, index)}>删除</MenuItem>
</MenuList>
</MenuList>
),
),
[delShareChatHistoryItemById, h
asVoiceApi, h
istoryId, onclickCopy, theme.borders.base]
[delShareChatHistoryItemById, historyId, onclickCopy, theme.borders.base]
);
);
return (
return (
...
@@ -754,7 +750,9 @@ const Chat = ({
...
@@ -754,7 +750,9 @@ const Chat = ({
</Flex>
</Flex>
</Flex>
</Flex>
))}
))}
{shareChatData.history.length === 0 && <Empty model={shareChatData.model} />}
{shareChatData.history.length === 0 && (
<Empty model={shareChatData.model} showChatProblem={false} />
)}
</Box>
</Box>
</Box>
</Box>
{/* 发送区 */}
{/* 发送区 */}
...
@@ -926,7 +924,7 @@ Chat.getInitialProps = ({ query, req }: any) => {
...
@@ -926,7 +924,7 @@ Chat.getInitialProps = ({ query, req }: any) => {
return
{
return
{
shareId
:
query
?.
shareId
||
''
,
shareId
:
query
?.
shareId
||
''
,
historyId
:
query
?.
historyId
||
''
,
historyId
:
query
?.
historyId
||
''
,
isPcDevice
:
!
/Mobile/
.
test
(
req
?
req
.
headers
[
'user-agent'
]
:
navigator
.
userAgent
)
isPcDevice
:
!
/Mobile/
.
test
(
req
?.
headers
?.[
'user-agent'
]
)
};
};
};
};
...
...
src/pages/login/index.tsx
View file @
371e0e36
...
@@ -117,6 +117,6 @@ export default Login;
...
@@ -117,6 +117,6 @@ export default Login;
Login
.
getInitialProps
=
({
query
,
req
}:
any
)
=>
{
Login
.
getInitialProps
=
({
query
,
req
}:
any
)
=>
{
return
{
return
{
isPcDevice
:
!
/Mobile/
.
test
(
req
?
req
.
headers
[
'user-agent'
]
:
navigator
.
userAgent
)
isPcDevice
:
!
/Mobile/
.
test
(
req
?.
headers
?.[
'user-agent'
]
)
};
};
};
};
src/pages/model/components/detail/index.tsx
View file @
371e0e36
...
@@ -45,6 +45,11 @@ const ModelDetail = ({ modelId, isPc }: { modelId: string; isPc: boolean }) => {
...
@@ -45,6 +45,11 @@ const ModelDetail = ({ modelId, isPc }: { modelId: string; isPc: boolean }) => {
[
modelDetail
.
userId
,
userInfo
?.
_id
]
[
modelDetail
.
userId
,
userInfo
?.
_id
]
);
);
const
canRead
=
useMemo
(
()
=>
isOwner
||
isLoading
||
modelDetail
.
share
.
isShareDetail
,
[
isLoading
,
isOwner
,
modelDetail
.
share
.
isShareDetail
]
);
/* 点击删除 */
/* 点击删除 */
const
handleDelModel
=
useCallback
(
async
()
=>
{
const
handleDelModel
=
useCallback
(
async
()
=>
{
if
(
!
modelDetail
)
return
;
if
(
!
modelDetail
)
return
;
...
@@ -129,7 +134,7 @@ const ModelDetail = ({ modelId, isPc }: { modelId: string; isPc: boolean }) => {
...
@@ -129,7 +134,7 @@ const ModelDetail = ({ modelId, isPc }: { modelId: string; isPc: boolean }) => {
};
};
},
[
router
]);
},
[
router
]);
return
(
return
canRead
?
(
<
Box
h=
{
'100%'
}
p=
{
5
}
overflow=
{
'overlay'
}
position=
{
'relative'
}
>
<
Box
h=
{
'100%'
}
p=
{
5
}
overflow=
{
'overlay'
}
position=
{
'relative'
}
>
{
/* 头部 */
}
{
/* 头部 */
}
<
Card
px=
{
6
}
py=
{
3
}
>
<
Card
px=
{
6
}
py=
{
3
}
>
...
@@ -196,6 +201,10 @@ const ModelDetail = ({ modelId, isPc }: { modelId: string; isPc: boolean }) => {
...
@@ -196,6 +201,10 @@ const ModelDetail = ({ modelId, isPc }: { modelId: string; isPc: boolean }) => {
</
Grid
>
</
Grid
>
<
Loading
loading=
{
isLoading
}
fixed=
{
false
}
/>
<
Loading
loading=
{
isLoading
}
fixed=
{
false
}
/>
</
Box
>
</
Box
>
)
:
(
<
Box
h=
{
'100%'
}
p=
{
5
}
>
无权查看模型配置
</
Box
>
);
);
};
};
...
...
src/pages/model/index.tsx
View file @
371e0e36
...
@@ -46,6 +46,6 @@ export default Model;
...
@@ -46,6 +46,6 @@ export default Model;
Model
.
getInitialProps
=
({
query
,
req
}:
any
)
=>
{
Model
.
getInitialProps
=
({
query
,
req
}:
any
)
=>
{
return
{
return
{
modelId
:
query
?.
modelId
||
''
,
modelId
:
query
?.
modelId
||
''
,
isPcDevice
:
!
/Mobile/
.
test
(
req
?
req
.
headers
[
'user-agent'
]
:
navigator
.
userAgent
)
isPcDevice
:
!
/Mobile/
.
test
(
req
?.
headers
?.[
'user-agent'
]
)
};
};
};
};
src/utils/tools.ts
View file @
371e0e36
...
@@ -89,6 +89,7 @@ export const formatTimeToChatTime = (time: Date) => {
...
@@ -89,6 +89,7 @@ export const formatTimeToChatTime = (time: Date) => {
return
target
.
format
(
'YYYY/M/D'
);
return
target
.
format
(
'YYYY/M/D'
);
};
};
export
const
hasVoiceApi
=
typeof
window
!==
'undefined'
&&
'speechSynthesis'
in
window
;
/**
/**
* voice broadcast
* voice broadcast
*/
*/
...
...
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