From ac7b44e86276819be34ed91eea0b108747fa2c66 Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Sun, 14 Apr 2024 01:44:17 +0800 Subject: [PATCH] feat: telemetry add force to improve url fetch logic --- src/server/model/telemetry.ts | 15 ++++++--------- src/server/router/telemetry.ts | 6 ++++-- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/server/model/telemetry.ts b/src/server/model/telemetry.ts index 94a132b..396fb52 100644 --- a/src/server/model/telemetry.ts +++ b/src/server/model/telemetry.ts @@ -6,20 +6,17 @@ import { prisma } from './_client'; import { BaseQueryFilters, getDateQuery, - getTimestampIntervalQuery, parseTelemetryFilters, } from '../utils/prisma'; import { SESSION_COLUMNS } from '../utils/const'; export async function recordTelemetryEvent(req: Request) { - const { - url = req.headers.referer, - name, - title, - start, - fullNum, - ...others - } = req.query; + const { name, title, start, fullNum, force, ...others } = req.query; + + const url = + req.query.url && force === 'true' + ? req.query.url + : req.headers.referer ?? req.query.url; if (!(url && typeof url === 'string')) { return; diff --git a/src/server/router/telemetry.ts b/src/server/router/telemetry.ts index f8722d3..4db4c3f 100644 --- a/src/server/router/telemetry.ts +++ b/src/server/router/telemetry.ts @@ -58,7 +58,8 @@ telemetryRouter.get( '/:workspaceId/:telemetryId.gif', validate( query('name').optional().isString(), - query('url').optional().isURL() + query('url').optional().isURL(), + query('force').optional().isBoolean() ), async (req, res) => { if (env.isTest) { @@ -85,7 +86,8 @@ telemetryRouter.get( query('url').optional().isURL(), query('title').optional().isString(), query('start').optional().isNumeric(), - query('fullNum').optional().isBoolean() + query('fullNum').optional().isBoolean(), + query('force').optional().isBoolean() ), async (req, res) => { const title = req.query.title || 'visitor';