Files
gsfdc/demo-dify/dify/web/app/(commonLayout)/plugins/page.tsx
T
wuzilongandCursor 6519682885 chore: 纳入本地 Dify 1.19.0 源码及品牌与免登改动
演示目录只保留可重建的源码。运行密钥、数据卷、依赖和带口令的本地配置不进入仓库。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-18 13:59:25 +08:00

66 lines
2.1 KiB
TypeScript

import type { LegacyPluginsSearchParams } from '@/app/components/plugins/plugin-routes'
import {
getFirstPackageIdFromSearchParams,
getInstallRedirectPathByPluginCategory,
getInstallRedirectPathFromSearchParams,
getLegacyPluginRedirectPath,
parseMarketplacePluginId,
shouldResolveInstallCategoryRedirect,
} from '@/app/components/plugins/plugin-routes'
import { getMarketplaceApiUrl } from '@/features/marketplace/api'
import { redirect } from '@/next/navigation'
type PluginListProps = {
searchParams?: Promise<LegacyPluginsSearchParams>
}
type MarketplaceManifestCategoryResponse = {
data?: {
plugin?: {
category?: string
}
}
}
const fetchPluginCategoryFromMarketplace = async (packageId: string) => {
try {
const pluginId = parseMarketplacePluginId(packageId)
const path = pluginId
? `/plugins/${encodeURIComponent(pluginId.org)}/${encodeURIComponent(pluginId.name)}`
: `/plugins/identifier?unique_identifier=${encodeURIComponent(packageId)}`
const response = await fetch(getMarketplaceApiUrl(path), { cache: 'no-store' })
if (!response.ok) return undefined
const payload = (await response.json()) as MarketplaceManifestCategoryResponse
return payload.data?.plugin?.category
} catch {
return undefined
}
}
const PluginList = async ({ searchParams }: PluginListProps) => {
const resolvedSearchParams = (await searchParams) ?? {}
const installRedirectPathFromSearchParams =
getInstallRedirectPathFromSearchParams(resolvedSearchParams)
if (installRedirectPathFromSearchParams) redirect(installRedirectPathFromSearchParams)
if (shouldResolveInstallCategoryRedirect(resolvedSearchParams)) {
const packageId = getFirstPackageIdFromSearchParams(resolvedSearchParams)
const category = packageId ? await fetchPluginCategoryFromMarketplace(packageId) : undefined
const installRedirectPath = getInstallRedirectPathByPluginCategory(
category,
resolvedSearchParams,
)
if (installRedirectPath) redirect(installRedirectPath)
}
const redirectPath = getLegacyPluginRedirectPath(resolvedSearchParams)
redirect(redirectPath)
}
export default PluginList