Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
dify
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ai-tech
dify
Commits
1bb32e49
Commit
1bb32e49
authored
Jul 11, 2023
by
StyleZhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: text-generation token
parent
6ba806e7
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
33 deletions
+27
-33
index.tsx
web/app/components/share/chat/index.tsx
+4
-28
index.tsx
web/app/components/share/text-generation/index.tsx
+5
-5
utils.ts
web/app/components/share/utils.ts
+18
-0
No files found.
web/app/components/share/chat/index.tsx
View file @
1bb32e49
...
...
@@ -6,9 +6,9 @@ import cn from 'classnames'
import
{
useTranslation
}
from
'react-i18next'
import
{
useContext
}
from
'use-context-selector'
import
produce
from
'immer'
import
{
useParams
}
from
'next/navigation'
import
{
useBoolean
,
useGetState
}
from
'ahooks'
import
AppUnavailable
from
'../../base/app-unavailable'
import
{
checkOrSetAccessToken
}
from
'../utils'
import
useConversation
from
'./hooks/use-conversation'
import
s
from
'./style.module.css'
import
{
ToastContext
}
from
'@/app/components/base/toast'
...
...
@@ -17,7 +17,6 @@ import ConfigSence from '@/app/components/share/chat/config-scence'
import
Header
from
'@/app/components/share/header'
import
{
delConversation
,
fetchAccessToken
,
fetchAppInfo
,
fetchAppParams
,
fetchChatList
,
...
...
@@ -68,7 +67,6 @@ const Main: FC<IMainProps> = ({
// in mobile, show sidebar by click button
const
[
isShowSidebar
,
{
setTrue
:
showSidebar
,
setFalse
:
hideSidebar
}]
=
useBoolean
(
false
)
// Can Use metadata(https://beta.nextjs.org/docs/api-reference/metadata) to set title. But it only works in server side client.
const
params
=
useParams
()
useEffect
(()
=>
{
if
(
siteInfo
?.
title
)
{
if
(
plan
!==
'basic'
)
...
...
@@ -311,31 +309,9 @@ const Main: FC<IMainProps> = ({
return
fetchConversations
(
isInstalledApp
,
installedAppInfo
?.
id
,
undefined
,
undefined
,
100
)
}
const
fetchAndSetAccessToken
=
async
()
=>
{
const
sharedToken
=
params
.
token
const
accessToken
=
localStorage
.
getItem
(
'token'
)
||
JSON
.
stringify
({
[
sharedToken
]:
''
})
let
accessTokenJson
=
{
[
sharedToken
]:
''
}
try
{
accessTokenJson
=
JSON
.
parse
(
accessToken
)
}
catch
(
e
)
{
}
const
res
=
await
fetchAccessToken
(
sharedToken
)
accessTokenJson
[
sharedToken
]
=
res
.
access_token
localStorage
.
setItem
(
'token'
,
JSON
.
stringify
(
accessTokenJson
))
location
.
reload
()
}
const
fetchInitData
=
async
()
=>
{
let
appData
:
any
=
{}
try
{
appData
=
await
fetchAppInfo
()
}
catch
(
e
:
any
)
{
if
(
e
.
code
===
'unauthorized'
)
await
fetchAndSetAccessToken
()
}
await
checkOrSetAccessToken
()
return
Promise
.
all
([
isInstalledApp
?
{
app_id
:
installedAppInfo
?.
id
,
...
...
@@ -346,7 +322,7 @@ const Main: FC<IMainProps> = ({
},
plan
:
'basic'
,
}
:
appData
,
fetchAllConversations
(),
fetchAppParams
(
isInstalledApp
,
installedAppInfo
?.
id
)])
:
fetchAppInfo
()
,
fetchAllConversations
(),
fetchAppParams
(
isInstalledApp
,
installedAppInfo
?.
id
)])
}
// init
...
...
web/app/components/share/text-generation/index.tsx
View file @
1bb32e49
...
...
@@ -7,6 +7,7 @@ import { useBoolean, useClickAway, useGetState } from 'ahooks'
import
{
XMarkIcon
}
from
'@heroicons/react/24/outline'
import
TabHeader
from
'../../base/tab-header'
import
Button
from
'../../base/button'
import
{
checkOrSetAccessToken
}
from
'../utils'
import
s
from
'./style.module.css'
import
RunBatch
from
'./run-batch'
import
useBreakpoints
,
{
MediaType
}
from
'@/hooks/use-breakpoints'
...
...
@@ -76,9 +77,6 @@ const TextGeneration: FC<IMainProps> = ({
const
res
:
any
=
await
doFetchSavedMessage
(
isInstalledApp
,
installedAppInfo
?.
id
)
setSavedMessages
(
res
.
data
)
}
useEffect
(()
=>
{
fetchSavedMessage
()
},
[])
const
handleSaveMessage
=
async
(
messageId
:
string
)
=>
{
await
saveMessage
(
messageId
,
isInstalledApp
,
installedAppInfo
?.
id
)
notify
({
type
:
'success'
,
message
:
t
(
'common.api.saved'
)
})
...
...
@@ -256,7 +254,9 @@ const TextGeneration: FC<IMainProps> = ({
setAllTaskList
(
newAllTaskList
)
}
const
fetchInitData
=
()
=>
{
const
fetchInitData
=
async
()
=>
{
await
checkOrSetAccessToken
()
return
Promise
.
all
([
isInstalledApp
?
{
app_id
:
installedAppInfo
?.
id
,
...
...
@@ -267,7 +267,7 @@ const TextGeneration: FC<IMainProps> = ({
},
plan
:
'basic'
,
}
:
fetchAppInfo
(),
fetchAppParams
(
isInstalledApp
,
installedAppInfo
?.
id
)])
:
fetchAppInfo
(),
fetchAppParams
(
isInstalledApp
,
installedAppInfo
?.
id
)
,
fetchSavedMessage
()
])
}
useEffect
(()
=>
{
...
...
web/app/components/share/utils.ts
0 → 100644
View file @
1bb32e49
import
{
fetchAccessToken
}
from
'@/service/share'
export
const
checkOrSetAccessToken
=
async
()
=>
{
const
sharedToken
=
globalThis
.
location
.
pathname
.
split
(
'/'
).
slice
(
-
1
)[
0
]
const
accessToken
=
localStorage
.
getItem
(
'token'
)
||
JSON
.
stringify
({
[
sharedToken
]:
''
})
let
accessTokenJson
=
{
[
sharedToken
]:
''
}
try
{
accessTokenJson
=
JSON
.
parse
(
accessToken
)
}
catch
(
e
)
{
}
if
(
!
accessTokenJson
[
sharedToken
])
{
const
res
=
await
fetchAccessToken
(
sharedToken
)
accessTokenJson
[
sharedToken
]
=
res
.
access_token
localStorage
.
setItem
(
'token'
,
JSON
.
stringify
(
accessTokenJson
))
}
}
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