mirror of
https://github.com/langgenius/dify.git
synced 2026-09-07 01:43:41 +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>
49 lines
1.5 KiB
TypeScript
49 lines
1.5 KiB
TypeScript
import { useSyncExternalStore } from 'react'
|
|
|
|
export const PUBLIC_CREATOR_CENTER_URL = 'https://creators.dify.ai/'
|
|
|
|
const subscribe = () => () => {}
|
|
|
|
/**
|
|
* marketplace.dify.ai → creators.dify.ai
|
|
* marketplace.dify.dev → creators.dify.dev
|
|
* marketplace-staging.dify.dev → creators-staging.dify.dev
|
|
*/
|
|
export const rewriteMarketplaceOriginToCreators = (origin: string): string | null => {
|
|
if (!origin) return null
|
|
|
|
try {
|
|
const marketplaceUrl = new URL(origin)
|
|
const [service, ...domain] = marketplaceUrl.hostname.split('.')
|
|
if (!service?.startsWith('marketplace') || domain.length === 0) return null
|
|
|
|
marketplaceUrl.hostname = [service.replace(/^marketplace/, 'creators'), ...domain].join('.')
|
|
marketplaceUrl.pathname = '/'
|
|
marketplaceUrl.search = ''
|
|
marketplaceUrl.hash = ''
|
|
return marketplaceUrl.toString()
|
|
} catch {
|
|
return null
|
|
}
|
|
}
|
|
|
|
export const getCreatorCenterUrl = (marketplaceUrlPrefix: string, pageOrigin?: string): string => {
|
|
return (
|
|
rewriteMarketplaceOriginToCreators(pageOrigin ?? '') ||
|
|
rewriteMarketplaceOriginToCreators(marketplaceUrlPrefix) ||
|
|
PUBLIC_CREATOR_CENTER_URL
|
|
)
|
|
}
|
|
|
|
/**
|
|
* Prefer the current page origin when this is the standalone Marketplace, so a
|
|
* .dev deployment cannot inherit a baked-in .ai Creator Center URL.
|
|
*/
|
|
export const useCreatorCenterUrl = (marketplaceUrlPrefix: string) => {
|
|
return useSyncExternalStore(
|
|
subscribe,
|
|
() => getCreatorCenterUrl(marketplaceUrlPrefix, window.location.origin),
|
|
() => getCreatorCenterUrl(marketplaceUrlPrefix),
|
|
)
|
|
}
|