feat: add tianji anonymous telemetry
This commit is contained in:
parent
e387b70c3a
commit
ceef5c4b71
@ -1,10 +1,17 @@
|
|||||||
|
import { once } from 'lodash-es';
|
||||||
import { AppRouterOutput, trpc } from '../api/trpc';
|
import { AppRouterOutput, trpc } from '../api/trpc';
|
||||||
|
import { anonymousTelemetryUrl } from '../utils/env';
|
||||||
|
|
||||||
const defaultGlobalConfig: AppRouterOutput['global']['config'] = {
|
const defaultGlobalConfig: AppRouterOutput['global']['config'] = {
|
||||||
allowRegister: false,
|
allowRegister: false,
|
||||||
alphaMode: false,
|
alphaMode: false,
|
||||||
|
disableAnonymousTelemetry: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const callAnonymousTelemetry = once(() => {
|
||||||
|
fetch(anonymousTelemetryUrl);
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch settings from server
|
* Fetch settings from server
|
||||||
*/
|
*/
|
||||||
@ -13,6 +20,11 @@ export function useGlobalConfig(): AppRouterOutput['global']['config'] {
|
|||||||
undefined,
|
undefined,
|
||||||
{
|
{
|
||||||
staleTime: 1000 * 60 * 60 * 1, // 1 hour
|
staleTime: 1000 * 60 * 60 * 1, // 1 hour
|
||||||
|
onSuccess(data) {
|
||||||
|
if (data.disableAnonymousTelemetry !== true) {
|
||||||
|
callAnonymousTelemetry();
|
||||||
|
}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -1 +1,5 @@
|
|||||||
|
import { version } from '@tianji/shared';
|
||||||
|
|
||||||
export const isDev = import.meta.env.MODE === 'development';
|
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}`;
|
||||||
|
@ -10,6 +10,7 @@ export default defineConfig({
|
|||||||
},
|
},
|
||||||
clearScreen: false,
|
clearScreen: false,
|
||||||
server: {
|
server: {
|
||||||
|
host: '0.0.0.0',
|
||||||
proxy: {
|
proxy: {
|
||||||
'/socket.io': {
|
'/socket.io': {
|
||||||
target: 'ws://localhost:12345',
|
target: 'ws://localhost:12345',
|
||||||
|
@ -21,6 +21,7 @@ export const globalRouter = router({
|
|||||||
amapToken: z.string().optional(),
|
amapToken: z.string().optional(),
|
||||||
mapboxToken: z.string().optional(),
|
mapboxToken: z.string().optional(),
|
||||||
alphaMode: z.boolean(),
|
alphaMode: z.boolean(),
|
||||||
|
disableAnonymousTelemetry: z.boolean(),
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
.query(async ({ input }) => {
|
.query(async ({ input }) => {
|
||||||
@ -30,6 +31,7 @@ export const globalRouter = router({
|
|||||||
amapToken: env.amapToken,
|
amapToken: env.amapToken,
|
||||||
mapboxToken: env.mapboxToken,
|
mapboxToken: env.mapboxToken,
|
||||||
alphaMode: env.alphaMode,
|
alphaMode: env.alphaMode,
|
||||||
|
disableAnonymousTelemetry: env.disableAnonymousTelemetry,
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
@ -11,6 +11,9 @@ export const env = {
|
|||||||
amapToken: process.env.AMAP_TOKEN,
|
amapToken: process.env.AMAP_TOKEN,
|
||||||
mapboxToken: process.env.MAPBOX_TOKEN,
|
mapboxToken: process.env.MAPBOX_TOKEN,
|
||||||
alphaMode: checkEnvTrusty(process.env.ALPHA_MODE),
|
alphaMode: checkEnvTrusty(process.env.ALPHA_MODE),
|
||||||
|
disableAnonymousTelemetry: checkEnvTrusty(
|
||||||
|
process.env.DISABLE_ANONYMOUS_TELEMETRY
|
||||||
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
export function checkEnvTrusty(env: string | undefined): boolean {
|
export function checkEnvTrusty(env: string | undefined): boolean {
|
||||||
|
Loading…
Reference in New Issue
Block a user