mirror of
https://github.com/langgenius/dify.git
synced 2026-05-21 09:17:27 +08:00
58 lines
1.5 KiB
TypeScript
58 lines
1.5 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 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'
|
|
|
|
if (marketplacePluginTabs.has(tab))
|
|
return buildMarketplaceRedirectPath(searchParams, tab)
|
|
|
|
return undefined
|
|
}
|