mirror of
https://github.com/langgenius/dify.git
synced 2026-04-27 11:06:46 +08:00
feat: Add APP_VERSION to headers for marketplace API requests
This commit is contained in:
parent
a061215e42
commit
4ea8fddf1a
@ -7,6 +7,7 @@ import type {
|
|||||||
PluginsSearchParams,
|
PluginsSearchParams,
|
||||||
} from '@/app/components/plugins/marketplace/types'
|
} from '@/app/components/plugins/marketplace/types'
|
||||||
import {
|
import {
|
||||||
|
APP_VERSION,
|
||||||
MARKETPLACE_API_PREFIX,
|
MARKETPLACE_API_PREFIX,
|
||||||
} from '@/config'
|
} from '@/config'
|
||||||
import { getMarketplaceUrl } from '@/utils/var'
|
import { getMarketplaceUrl } from '@/utils/var'
|
||||||
@ -49,11 +50,15 @@ export const getMarketplacePluginsByCollectionId = async (collectionId: string,
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const url = `${MARKETPLACE_API_PREFIX}/collections/${collectionId}/plugins`
|
const url = `${MARKETPLACE_API_PREFIX}/collections/${collectionId}/plugins`
|
||||||
|
const headers = new Headers({
|
||||||
|
'X-Dify-Version': APP_VERSION,
|
||||||
|
})
|
||||||
const marketplaceCollectionPluginsData = await globalThis.fetch(
|
const marketplaceCollectionPluginsData = await globalThis.fetch(
|
||||||
url,
|
url,
|
||||||
{
|
{
|
||||||
cache: 'no-store',
|
cache: 'no-store',
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
headers,
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
category: query?.category,
|
category: query?.category,
|
||||||
exclude: query?.exclude,
|
exclude: query?.exclude,
|
||||||
@ -83,7 +88,10 @@ export const getMarketplaceCollectionsAndPlugins = async (query?: CollectionsAnd
|
|||||||
marketplaceUrl += `&condition=${query.condition}`
|
marketplaceUrl += `&condition=${query.condition}`
|
||||||
if (query?.type)
|
if (query?.type)
|
||||||
marketplaceUrl += `&type=${query.type}`
|
marketplaceUrl += `&type=${query.type}`
|
||||||
const marketplaceCollectionsData = await globalThis.fetch(marketplaceUrl, { cache: 'no-store' })
|
const headers = new Headers({
|
||||||
|
'X-Dify-Version': APP_VERSION,
|
||||||
|
})
|
||||||
|
const marketplaceCollectionsData = await globalThis.fetch(marketplaceUrl, { headers, cache: 'no-store' })
|
||||||
const marketplaceCollectionsDataJson = await marketplaceCollectionsData.json()
|
const marketplaceCollectionsDataJson = await marketplaceCollectionsData.json()
|
||||||
marketplaceCollections = marketplaceCollectionsDataJson.data.collections
|
marketplaceCollections = marketplaceCollectionsDataJson.data.collections
|
||||||
await Promise.all(marketplaceCollections.map(async (collection: MarketplaceCollection) => {
|
await Promise.all(marketplaceCollections.map(async (collection: MarketplaceCollection) => {
|
||||||
|
|||||||
@ -3,6 +3,7 @@ import { AgentStrategy } from '@/types/app'
|
|||||||
import { PromptRole } from '@/models/debug'
|
import { PromptRole } from '@/models/debug'
|
||||||
import { PipelineInputVarType } from '@/models/pipeline'
|
import { PipelineInputVarType } from '@/models/pipeline'
|
||||||
import { DatasetAttr } from '@/types/feature'
|
import { DatasetAttr } from '@/types/feature'
|
||||||
|
import pkg from '../package.json'
|
||||||
|
|
||||||
const getBooleanConfig = (envVar: string | undefined, dataAttrKey: DatasetAttr, defaultValue: boolean = true) => {
|
const getBooleanConfig = (envVar: string | undefined, dataAttrKey: DatasetAttr, defaultValue: boolean = true) => {
|
||||||
if (envVar !== undefined && envVar !== '')
|
if (envVar !== undefined && envVar !== '')
|
||||||
@ -296,4 +297,6 @@ export const VALUE_SELECTOR_DELIMITER = '@@@'
|
|||||||
|
|
||||||
export const validPassword = /^(?=.*[a-zA-Z])(?=.*\d)\S{8,}$/
|
export const validPassword = /^(?=.*[a-zA-Z])(?=.*\d)\S{8,}$/
|
||||||
|
|
||||||
|
export const APP_VERSION = pkg.version
|
||||||
|
|
||||||
export const RAG_PIPELINE_PREVIEW_CHUNK_NUM = 20
|
export const RAG_PIPELINE_PREVIEW_CHUNK_NUM = 20
|
||||||
|
|||||||
@ -2,7 +2,7 @@ import type { AfterResponseHook, BeforeErrorHook, BeforeRequestHook, Hooks } fro
|
|||||||
import ky from 'ky'
|
import ky from 'ky'
|
||||||
import type { IOtherOptions } from './base'
|
import type { IOtherOptions } from './base'
|
||||||
import Toast from '@/app/components/base/toast'
|
import Toast from '@/app/components/base/toast'
|
||||||
import { API_PREFIX, MARKETPLACE_API_PREFIX, PUBLIC_API_PREFIX } from '@/config'
|
import { API_PREFIX, APP_VERSION, MARKETPLACE_API_PREFIX, PUBLIC_API_PREFIX } from '@/config'
|
||||||
import { getInitialTokenV2, isTokenV1 } from '@/app/components/share/utils'
|
import { getInitialTokenV2, isTokenV1 } from '@/app/components/share/utils'
|
||||||
import { getProcessedSystemVariablesFromUrlParams } from '@/app/components/base/chat/utils'
|
import { getProcessedSystemVariablesFromUrlParams } from '@/app/components/base/chat/utils'
|
||||||
|
|
||||||
@ -151,6 +151,10 @@ async function base<T>(url: string, options: FetchOptionType = {}, otherOptions:
|
|||||||
if (deleteContentType)
|
if (deleteContentType)
|
||||||
(headers as any).delete('Content-Type')
|
(headers as any).delete('Content-Type')
|
||||||
|
|
||||||
|
// ! For Marketplace API, help to filter tags added in new version
|
||||||
|
if (isMarketplaceAPI)
|
||||||
|
(headers as any).set('X-Dify-Version', APP_VERSION)
|
||||||
|
|
||||||
const client = baseClient.extend({
|
const client = baseClient.extend({
|
||||||
hooks: {
|
hooks: {
|
||||||
...baseHooks,
|
...baseHooks,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user