mirror of
https://github.com/langgenius/dify.git
synced 2026-09-07 18:36:02 +08:00
Co-authored-by: zxhlyh <jasonapring2015@outlook.com> Co-authored-by: fatelei <fatelei@gmail.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: CodingOnStar <hanxujiang@dify.com> Co-authored-by: Cursor <cursoragent@cursor.com> Co-authored-by: 姜涵煦 <hanxujiang@jianghanxudeMacBook-Pro-2.local> Co-authored-by: L1nSn0w <l1nsn0w@qq.com> Co-authored-by: yyh <92089059+lyzno1@users.noreply.github.com>
72 lines
2.1 KiB
TypeScript
72 lines
2.1 KiB
TypeScript
import type { PluginBanner } from '@dify/contracts/marketplace'
|
|
import type { SearchParams } from 'nuqs'
|
|
import type { MarketplaceViewProps } from './view'
|
|
import { getLocaleOnServer } from '@/i18n-config/server'
|
|
import { fetchPluginBanners } from './home/banners'
|
|
import { HydrateQueryClient } from './hydration-server'
|
|
import { prefetchMarketplaceDehydratedState } from './prefetch-marketplace-dehydrated-state'
|
|
import { withinServerBudget } from './server-budget'
|
|
import { MarketplaceView } from './view'
|
|
|
|
type MarketplaceProps = Omit<MarketplaceViewProps, 'banners'> & {
|
|
language?: string
|
|
/**
|
|
* Pass the search params from the request to prefetch data on the server.
|
|
*/
|
|
searchParams?: Promise<SearchParams>
|
|
}
|
|
|
|
const Marketplace = async ({
|
|
language,
|
|
searchParams,
|
|
variant = 'default',
|
|
...viewProps
|
|
}: MarketplaceProps) => {
|
|
let trendingBanners: PluginBanner[] = []
|
|
|
|
if (variant === 'home') {
|
|
const locale = language ?? (await getLocaleOnServer())
|
|
const prefetch = prefetchMarketplaceDehydratedState(searchParams)
|
|
|
|
// Banners are decoration on a page whose point is the catalog. Overlap
|
|
// them with the catalog prefetch so the document waits at most one budget.
|
|
// A late banner resolution just misses this render; nothing waits on it.
|
|
await withinServerBudget(
|
|
Promise.all([
|
|
fetchPluginBanners(locale)
|
|
.then((banners) => {
|
|
trendingBanners = banners
|
|
})
|
|
.catch(() => {
|
|
// Keep the homepage available if Marketplace banner delivery is down.
|
|
}),
|
|
prefetch,
|
|
]),
|
|
)
|
|
|
|
return (
|
|
<HydrateQueryClient searchParams={undefined} prefetchedState={await prefetch}>
|
|
<MarketplaceView
|
|
{...viewProps}
|
|
banners={trendingBanners}
|
|
language={language}
|
|
variant={variant}
|
|
/>
|
|
</HydrateQueryClient>
|
|
)
|
|
}
|
|
|
|
return (
|
|
<HydrateQueryClient searchParams={searchParams}>
|
|
<MarketplaceView
|
|
{...viewProps}
|
|
banners={trendingBanners}
|
|
language={language}
|
|
variant={variant}
|
|
/>
|
|
</HydrateQueryClient>
|
|
)
|
|
}
|
|
|
|
export default Marketplace
|