(req: Request, url: string)
| 80 | } |
| 81 | |
| 82 | async function findSession(req: Request, url: string) { |
| 83 | const { hostname } = new URL(url); |
| 84 | const workspaceId = req.params.workspaceId; |
| 85 | if (!workspaceId) { |
| 86 | throw new Error('Not found workspaceId'); |
| 87 | } |
| 88 | |
| 89 | const { |
| 90 | userAgent, |
| 91 | browser, |
| 92 | os, |
| 93 | ip, |
| 94 | country, |
| 95 | subdivision1, |
| 96 | subdivision2, |
| 97 | city, |
| 98 | longitude, |
| 99 | latitude, |
| 100 | accuracyRadius, |
| 101 | } = await getRequestInfo(req); |
| 102 | |
| 103 | const sessionId = hashUuid(workspaceId, hostname, ip, userAgent!); |
| 104 | |
| 105 | let session = await loadSession(sessionId); |
| 106 | if (!session) { |
| 107 | session = await prisma.telemetrySession.upsert({ |
| 108 | where: { id: sessionId }, |
| 109 | create: { |
| 110 | id: sessionId, |
| 111 | workspaceId, |
| 112 | hostname, |
| 113 | browser, |
| 114 | os, |
| 115 | ip, |
| 116 | country, |
| 117 | subdivision1, |
| 118 | subdivision2, |
| 119 | city, |
| 120 | longitude, |
| 121 | latitude, |
| 122 | accuracyRadius, |
| 123 | }, |
| 124 | update: {}, |
| 125 | }); |
| 126 | } |
| 127 | |
| 128 | return session; |
| 129 | } |
| 130 | |
| 131 | const { get: getTelemetrySessionFromCache, del: delTelemetrySessionCache } = |
| 132 | buildQueryWithCache('telemetrySession', async (sessionId: string): Promise<TelemetrySession | null> => { |
no test coverage detected