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
a43fc4ef
Commit
a43fc4ef
authored
Jul 10, 2023
by
StyleZhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add X-App-Code to allow_headers
parent
438ad600
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
43 additions
and
8 deletions
+43
-8
app.py
api/app.py
+1
-1
passport.py
api/controllers/web/passport.py
+1
-1
index.tsx
web/app/components/share/chat/index.tsx
+32
-3
base.ts
web/service/base.ts
+3
-3
share.ts
web/service/share.ts
+6
-0
No files found.
api/app.py
View file @
a43fc4ef
...
...
@@ -155,7 +155,7 @@ def register_blueprints(app):
resources
=
{
r"/*"
:
{
"origins"
:
app
.
config
[
'WEB_API_CORS_ALLOW_ORIGINS'
]}},
supports_credentials
=
True
,
allow_headers
=
[
'Content-Type'
,
'Authorization'
],
allow_headers
=
[
'Content-Type'
,
'Authorization'
,
'X-App-Code'
],
methods
=
[
'GET'
,
'PUT'
,
'POST'
,
'DELETE'
,
'OPTIONS'
,
'PATCH'
],
expose_headers
=
[
'X-Version'
,
'X-Env'
]
)
...
...
api/controllers/web/passport.py
View file @
a43fc4ef
...
...
@@ -40,7 +40,7 @@ class PassportResource(Resource):
payload
=
{
"iss"
:
site
.
app_id
,
'sub'
:
'Web API Passport'
,
"aud"
:
end_user
.
id
,
#
"aud": end_user.id,
'app_id'
:
site
.
app_id
,
'end_user_id'
:
end_user
.
id
,
}
...
...
web/app/components/share/chat/index.tsx
View file @
a43fc4ef
...
...
@@ -6,6 +6,7 @@ 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
useConversation
from
'./hooks/use-conversation'
...
...
@@ -14,7 +15,20 @@ import { ToastContext } from '@/app/components/base/toast'
import
Sidebar
from
'@/app/components/share/chat/sidebar'
import
ConfigSence
from
'@/app/components/share/chat/config-scence'
import
Header
from
'@/app/components/share/header'
import
{
delConversation
,
fetchAppInfo
,
fetchAppParams
,
fetchChatList
,
fetchConversations
,
fetchSuggestedQuestions
,
pinConversation
,
sendChatMessage
,
stopChatMessageResponding
,
unpinConversation
,
updateFeedback
}
from
'@/service/share'
import
{
delConversation
,
fetchAccessToken
,
fetchAppInfo
,
fetchAppParams
,
fetchChatList
,
fetchConversations
,
fetchSuggestedQuestions
,
pinConversation
,
sendChatMessage
,
stopChatMessageResponding
,
unpinConversation
,
updateFeedback
,
}
from
'@/service/share'
import
type
{
ConversationItem
,
SiteInfo
}
from
'@/models/share'
import
type
{
PromptConfig
,
SuggestedQuestionsAfterAnswerConfig
}
from
'@/models/debug'
import
type
{
Feedbacktype
,
IChatItem
}
from
'@/app/components/app/chat'
...
...
@@ -54,6 +68,7 @@ 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'
)
...
...
@@ -296,7 +311,21 @@ const Main: FC<IMainProps> = ({
return
fetchConversations
(
isInstalledApp
,
installedAppInfo
?.
id
,
undefined
,
undefined
,
100
)
}
const
fetchInitData
=
()
=>
{
const
fetchAndSetAccessToken
=
async
()
=>
{
const
res
=
await
fetchAccessToken
(
params
.
token
)
localStorage
.
setItem
(
'accessToken'
,
res
.
access_token
)
fetchInitData
()
}
const
fetchInitData
=
async
()
=>
{
let
appData
:
any
=
{}
try
{
appData
=
await
fetchAppInfo
()
}
catch
(
e
:
any
)
{
if
(
e
.
code
===
'unauthorized'
)
await
fetchAndSetAccessToken
()
}
return
Promise
.
all
([
isInstalledApp
?
{
app_id
:
installedAppInfo
?.
id
,
...
...
@@ -307,7 +336,7 @@ const Main: FC<IMainProps> = ({
},
plan
:
'basic'
,
}
:
fetchAppInfo
()
,
fetchAllConversations
(),
fetchAppParams
(
isInstalledApp
,
installedAppInfo
?.
id
)])
:
appData
,
fetchAllConversations
(),
fetchAppParams
(
isInstalledApp
,
installedAppInfo
?.
id
)])
}
// init
...
...
web/service/base.ts
View file @
a43fc4ef
...
...
@@ -141,8 +141,8 @@ const baseFetch = (
)
=>
{
const
options
=
Object
.
assign
({},
baseOptions
,
fetchOptions
)
if
(
isPublicAPI
)
{
const
sharedToken
=
globalThis
.
location
.
pathname
.
split
(
'/'
).
slice
(
-
1
)[
0
]
options
.
headers
.
set
(
'Authorization'
,
`
b
earer
${
sharedToken
}
`
)
const
sharedToken
=
localStorage
.
getItem
(
'accessToken'
)
||
''
options
.
headers
.
set
(
'Authorization'
,
`
B
earer
${
sharedToken
}
`
)
}
if
(
deleteContentType
)
{
...
...
@@ -194,7 +194,7 @@ const baseFetch = (
case
401
:
{
if
(
isPublicAPI
)
{
Toast
.
notify
({
type
:
'error'
,
message
:
'Invalid token'
})
return
return
bodyJson
.
then
((
data
:
any
)
=>
Promise
.
reject
(
data
))
}
const
loginUrl
=
`
${
globalThis
.
location
.
origin
}
/signin`
if
(
IS_CE_EDITION
)
{
...
...
web/service/share.ts
View file @
a43fc4ef
...
...
@@ -118,3 +118,9 @@ export const fetchSuggestedQuestions = (messageId: string, isInstalledApp: boole
export
const
audioToText
=
(
url
:
string
,
isPublicAPI
:
boolean
,
body
:
FormData
)
=>
{
return
(
getAction
(
'post'
,
!
isPublicAPI
))(
url
,
{
body
},
{
bodyStringify
:
false
,
deleteContentType
:
true
})
as
Promise
<
{
text
:
string
}
>
}
export
const
fetchAccessToken
=
async
(
appCode
:
string
)
=>
{
const
headers
=
new
Headers
()
headers
.
append
(
'X-App-Code'
,
appCode
)
return
get
(
'/passport'
,
{
headers
})
as
Promise
<
{
access_token
:
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