mirror of
https://github.com/langgenius/dify.git
synced 2026-07-26 14:18:35 +08:00
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: GareArc <garethcxy@dify.ai>
54 lines
1.2 KiB
TypeScript
54 lines
1.2 KiB
TypeScript
import type { DeploymentEdition } from '@dify/contracts/api/console/system-features/types.gen'
|
|
|
|
const EXCLUDED_ANALYTICS_PATH_SEGMENTS = [
|
|
'/agent',
|
|
'/chat',
|
|
'/chatbot',
|
|
'/completion',
|
|
'/workflow',
|
|
'/webapp-reset-password',
|
|
'/webapp-signin',
|
|
] as const
|
|
|
|
type CloudAnalyticsRequest = {
|
|
cookieYesSiteKey: string | undefined
|
|
deploymentEdition: DeploymentEdition
|
|
isProd: boolean
|
|
pathname: string
|
|
requestHost: string | null
|
|
webPrefix: string | undefined
|
|
}
|
|
|
|
export function isCloudAnalyticsPath(pathname: string) {
|
|
return !EXCLUDED_ANALYTICS_PATH_SEGMENTS.some(
|
|
(segment) => pathname === segment || pathname.startsWith(`${segment}/`),
|
|
)
|
|
}
|
|
|
|
export function isCloudAnalyticsRequest({
|
|
cookieYesSiteKey,
|
|
deploymentEdition,
|
|
isProd,
|
|
pathname,
|
|
requestHost,
|
|
webPrefix,
|
|
}: CloudAnalyticsRequest) {
|
|
if (
|
|
deploymentEdition !== 'CLOUD' ||
|
|
!isProd ||
|
|
!cookieYesSiteKey?.trim() ||
|
|
!requestHost ||
|
|
!webPrefix
|
|
)
|
|
return false
|
|
if (!isCloudAnalyticsPath(pathname)) return false
|
|
|
|
try {
|
|
const expectedHost = new URL(webPrefix).host.toLowerCase()
|
|
const currentHost = requestHost.split(',')[0]?.trim().toLowerCase()
|
|
return currentHost === expectedHost
|
|
} catch {
|
|
return false
|
|
}
|
|
}
|