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 { 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();
|
||||
}
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -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}`;
|
||||
|
@ -10,6 +10,7 @@ export default defineConfig({
|
||||
},
|
||||
clearScreen: false,
|
||||
server: {
|
||||
host: '0.0.0.0',
|
||||
proxy: {
|
||||
'/socket.io': {
|
||||
target: 'ws://localhost:12345',
|
||||
|
@ -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,
|
||||
};
|
||||
}),
|
||||
});
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user