diff --git a/src/client/hooks/useConfig.ts b/src/client/hooks/useConfig.ts index 210a1b0..d87fdff 100644 --- a/src/client/hooks/useConfig.ts +++ b/src/client/hooks/useConfig.ts @@ -1,10 +1,17 @@ +import { once } from 'lodash-es'; import { AppRouterOutput, trpc } from '../api/trpc'; +import { anonymousTelemetryUrl } from '../utils/env'; const defaultGlobalConfig: AppRouterOutput['global']['config'] = { allowRegister: false, alphaMode: false, + disableAnonymousTelemetry: false, }; +const callAnonymousTelemetry = once(() => { + fetch(anonymousTelemetryUrl); +}); + /** * Fetch settings from server */ @@ -13,6 +20,11 @@ export function useGlobalConfig(): AppRouterOutput['global']['config'] { undefined, { staleTime: 1000 * 60 * 60 * 1, // 1 hour + onSuccess(data) { + if (data.disableAnonymousTelemetry !== true) { + callAnonymousTelemetry(); + } + }, } ); diff --git a/src/client/utils/env.ts b/src/client/utils/env.ts index 962a821..6bbf6f1 100644 --- a/src/client/utils/env.ts +++ b/src/client/utils/env.ts @@ -1 +1,5 @@ +import { version } from '@tianji/shared'; + export const isDev = import.meta.env.MODE === 'development'; + +export const anonymousTelemetryUrl = `https://tianji.moonrailgun.com/telemetry/clnzoxcy10001vy2ohi4obbi0/cltg3op5n007lrw4gvr3p8syj.gif?name=tianji-oss&url=${window.location.origin}&v=${version}`; diff --git a/src/client/vite.config.ts b/src/client/vite.config.ts index ed896ec..a0a80e7 100644 --- a/src/client/vite.config.ts +++ b/src/client/vite.config.ts @@ -10,6 +10,7 @@ export default defineConfig({ }, clearScreen: false, server: { + host: '0.0.0.0', proxy: { '/socket.io': { target: 'ws://localhost:12345', diff --git a/src/server/trpc/routers/global.ts b/src/server/trpc/routers/global.ts index e9f6baa..871406e 100644 --- a/src/server/trpc/routers/global.ts +++ b/src/server/trpc/routers/global.ts @@ -21,6 +21,7 @@ export const globalRouter = router({ amapToken: z.string().optional(), mapboxToken: z.string().optional(), alphaMode: z.boolean(), + disableAnonymousTelemetry: z.boolean(), }) ) .query(async ({ input }) => { @@ -30,6 +31,7 @@ export const globalRouter = router({ amapToken: env.amapToken, mapboxToken: env.mapboxToken, alphaMode: env.alphaMode, + disableAnonymousTelemetry: env.disableAnonymousTelemetry, }; }), }); diff --git a/src/server/utils/env.ts b/src/server/utils/env.ts index e47cce2..cdbf673 100644 --- a/src/server/utils/env.ts +++ b/src/server/utils/env.ts @@ -11,6 +11,9 @@ export const env = { amapToken: process.env.AMAP_TOKEN, mapboxToken: process.env.MAPBOX_TOKEN, alphaMode: checkEnvTrusty(process.env.ALPHA_MODE), + disableAnonymousTelemetry: checkEnvTrusty( + process.env.DISABLE_ANONYMOUS_TELEMETRY + ), }; export function checkEnvTrusty(env: string | undefined): boolean {