mirror of
https://github.com/langgenius/dify.git
synced 2025-12-19 17:27:16 -05:00
feat: add datasource_parameters handling for API requests (#29757)
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
This commit is contained in:
@@ -140,6 +140,18 @@ class DataSourceNotionListApi(Resource):
|
|||||||
credential_id = request.args.get("credential_id", default=None, type=str)
|
credential_id = request.args.get("credential_id", default=None, type=str)
|
||||||
if not credential_id:
|
if not credential_id:
|
||||||
raise ValueError("Credential id is required.")
|
raise ValueError("Credential id is required.")
|
||||||
|
|
||||||
|
# Get datasource_parameters from query string (optional, for GitHub and other datasources)
|
||||||
|
datasource_parameters_str = request.args.get("datasource_parameters", default=None, type=str)
|
||||||
|
datasource_parameters = {}
|
||||||
|
if datasource_parameters_str:
|
||||||
|
try:
|
||||||
|
datasource_parameters = json.loads(datasource_parameters_str)
|
||||||
|
if not isinstance(datasource_parameters, dict):
|
||||||
|
raise ValueError("datasource_parameters must be a JSON object.")
|
||||||
|
except json.JSONDecodeError:
|
||||||
|
raise ValueError("Invalid datasource_parameters JSON format.")
|
||||||
|
|
||||||
datasource_provider_service = DatasourceProviderService()
|
datasource_provider_service = DatasourceProviderService()
|
||||||
credential = datasource_provider_service.get_datasource_credentials(
|
credential = datasource_provider_service.get_datasource_credentials(
|
||||||
tenant_id=current_tenant_id,
|
tenant_id=current_tenant_id,
|
||||||
@@ -187,7 +199,7 @@ class DataSourceNotionListApi(Resource):
|
|||||||
online_document_result: Generator[OnlineDocumentPagesMessage, None, None] = (
|
online_document_result: Generator[OnlineDocumentPagesMessage, None, None] = (
|
||||||
datasource_runtime.get_online_document_pages(
|
datasource_runtime.get_online_document_pages(
|
||||||
user_id=current_user.id,
|
user_id=current_user.id,
|
||||||
datasource_parameters={},
|
datasource_parameters=datasource_parameters,
|
||||||
provider_type=datasource_runtime.datasource_provider_type(),
|
provider_type=datasource_runtime.datasource_provider_type(),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -75,11 +75,17 @@ const OnlineDocuments = ({
|
|||||||
|
|
||||||
const getOnlineDocuments = useCallback(async () => {
|
const getOnlineDocuments = useCallback(async () => {
|
||||||
const { currentCredentialId } = dataSourceStore.getState()
|
const { currentCredentialId } = dataSourceStore.getState()
|
||||||
|
// Convert datasource_parameters to inputs format for the API
|
||||||
|
const inputs = Object.entries(nodeData.datasource_parameters || {}).reduce((acc, [key, value]) => {
|
||||||
|
acc[key] = typeof value === 'object' && value !== null && 'value' in value ? value.value : value
|
||||||
|
return acc
|
||||||
|
}, {} as Record<string, any>)
|
||||||
|
|
||||||
ssePost(
|
ssePost(
|
||||||
datasourceNodeRunURL,
|
datasourceNodeRunURL,
|
||||||
{
|
{
|
||||||
body: {
|
body: {
|
||||||
inputs: {},
|
inputs,
|
||||||
credential_id: currentCredentialId,
|
credential_id: currentCredentialId,
|
||||||
datasource_type: DatasourceType.onlineDocument,
|
datasource_type: DatasourceType.onlineDocument,
|
||||||
},
|
},
|
||||||
@@ -97,7 +103,7 @@ const OnlineDocuments = ({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}, [dataSourceStore, datasourceNodeRunURL])
|
}, [dataSourceStore, datasourceNodeRunURL, nodeData.datasource_parameters])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!currentCredentialId) return
|
if (!currentCredentialId) return
|
||||||
|
|||||||
Reference in New Issue
Block a user