LCOV - code coverage report
Current view: top level - src/config - turnstile.ts Coverage Total Hit
Test: ComfyUI E2E Coverage Lines: 100.0 % 2 2
Test Date: 2026-11-17 04:17:53

            Line data    Source code
       1              : import {
       2              :   configValueOrDefault,
       3              :   remoteConfig
       4              : } from '@/platform/remoteConfig/remoteConfig'
       5              : 
       6              : /**
       7              :  * Cloudflare Turnstile always-pass test sitekey, used only in local dev so the
       8              :  * signup flow can be exercised without a real key.
       9              :  * @see https://developers.cloudflare.com/turnstile/troubleshooting/testing/
      10              :  */
      11              : const TURNSTILE_TEST_SITE_KEY = '1x00000000000000000000AA'
      12              : 
      13              : // Public per-environment sitekeys, baked at build time so a cloud build renders
      14              : // the widget even before (or without) remote config; remote config still
      15              : // overrides them, so keys rotate live without a rebuild.
      16              : const PROD_TURNSTILE_SITE_KEY = '0x4AAAAAADnYZPVOpFCL_zeo'
      17              : const STAGING_TURNSTILE_SITE_KEY = '0x4AAAAAADnYY4_Q0qxHZ5a7'
      18              : 
      19              : /**
      20              :  * Returns the Cloudflare Turnstile sitekey for the current environment.
      21              :  * - OSS / localhost never renders the cloud widget (server-side loopback
      22              :  *   exemption covers local signup); in dev it falls back to the always-pass test
      23              :  *   key so the flow is exercisable locally, otherwise ''.
      24              :  * - Cloud builds prefer the per-env sitekey delivered via remote config
      25              :  *   (`turnstile_sitekey`) and fall back to the build-time constant, so the widget
      26              :  *   still renders during a remote-config gap rather than silently disappearing.
      27              :  */
      28            2 : export function getTurnstileSiteKey(): string {
      29              :   const isCloudBuild = __DISTRIBUTION__ === 'cloud'
      30              :   if (!isCloudBuild) {
      31            2 :     return import.meta.env.DEV ? TURNSTILE_TEST_SITE_KEY : ''
      32              :   }
      33              : 
      34              :   return configValueOrDefault(
      35              :     remoteConfig.value,
      36              :     'turnstile_sitekey',
      37              :     __USE_PROD_CONFIG__ ? PROD_TURNSTILE_SITE_KEY : STAGING_TURNSTILE_SITE_KEY
      38              :   )
      39              : }
        

Generated by: LCOV version 2.0-1