mirror of
https://github.com/langgenius/dify.git
synced 2026-06-17 06:21:07 +08:00
Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: yyh <yuanyouhuilyz@gmail.com> Co-authored-by: Joel <iamjoel007@gmail.com> Co-authored-by: hjlarry <hjlarry@163.com> Co-authored-by: fatelei <fatelei@gmail.com> Co-authored-by: Asuka Minato <i@asukaminato.eu.org> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Xiyuan Chen <52963600+GareArc@users.noreply.github.com> Co-authored-by: gigglewang <gigglewang@dify.ai> Co-authored-by: Yunlu Wen <yunlu.wen@dify.ai> Co-authored-by: chariri <w@chariri.moe> Co-authored-by: Evan <2869018789@qq.com> Co-authored-by: yyh <92089059+lyzno1@users.noreply.github.com>
72 lines
1.9 KiB
TypeScript
72 lines
1.9 KiB
TypeScript
import { PLUGIN_TYPE_SEARCH_MAP } from './marketplace/constants'
|
|
|
|
export type LegacyPluginsSearchParams = Record<string, string | string[] | undefined>
|
|
|
|
const INSTALLED_PLUGINS_TAB = 'plugins'
|
|
const MARKETPLACE_TAB = 'discover'
|
|
|
|
const integrationPluginPathByTab = new Map<string, string>([
|
|
['trigger', '/integrations/trigger'],
|
|
['agent-strategy', '/integrations/agent-strategy'],
|
|
['extension', '/integrations/extension'],
|
|
])
|
|
|
|
const getIntegrationPluginPathByTab = (tab: string) => {
|
|
return integrationPluginPathByTab.get(tab)
|
|
}
|
|
|
|
const marketplacePluginTabs = new Set<string>([
|
|
MARKETPLACE_TAB,
|
|
...Object.values(PLUGIN_TYPE_SEARCH_MAP),
|
|
])
|
|
|
|
const getFirstSearchParamValue = (value: string | string[] | undefined) => {
|
|
if (Array.isArray(value))
|
|
return value[0]
|
|
|
|
return value
|
|
}
|
|
|
|
const buildMarketplaceRedirectPath = (
|
|
searchParams: LegacyPluginsSearchParams,
|
|
tab: string,
|
|
) => {
|
|
const preservedSearchParams = new URLSearchParams()
|
|
|
|
Object.entries(searchParams).forEach(([key, value]) => {
|
|
if (key === 'tab' || value === undefined)
|
|
return
|
|
|
|
if (Array.isArray(value)) {
|
|
value.forEach(item => preservedSearchParams.append(key, item))
|
|
return
|
|
}
|
|
|
|
preservedSearchParams.set(key, value)
|
|
})
|
|
|
|
if (tab !== MARKETPLACE_TAB && !preservedSearchParams.has('category'))
|
|
preservedSearchParams.set('category', tab)
|
|
|
|
const query = preservedSearchParams.toString()
|
|
return query ? `/marketplace?${query}` : '/marketplace'
|
|
}
|
|
|
|
export const getLegacyPluginRedirectPath = (
|
|
searchParams: LegacyPluginsSearchParams = {},
|
|
) => {
|
|
const tab = getFirstSearchParamValue(searchParams.tab)
|
|
|
|
if (!tab || tab === INSTALLED_PLUGINS_TAB)
|
|
return '/integrations'
|
|
|
|
const integrationPluginPath = getIntegrationPluginPathByTab(tab)
|
|
if (integrationPluginPath)
|
|
return integrationPluginPath
|
|
|
|
if (marketplacePluginTabs.has(tab))
|
|
return buildMarketplaceRedirectPath(searchParams, tab)
|
|
|
|
return undefined
|
|
}
|