add redis placeholder

This commit is contained in:
Brian Cao 2022-08-25 23:12:47 -07:00
parent f1e0814f4b
commit 10cc6616c5
2 changed files with 12 additions and 40 deletions

View file

@ -1,6 +1,8 @@
import { getWebsiteByUuid, getSessionByUuid, createSession } from 'queries';
import { getJsonBody, getClientInfo } from 'lib/request';
import { uuid, isValidUuid, parseToken } from 'lib/crypto';
import { runAnalyticsQuery } from 'lib/db';
import { RELATIONAL, CLICKHOUSE } from 'lib/constants';
export async function getSession(req) {
const { payload } = getJsonBody(req);
@ -9,7 +11,6 @@ export async function getSession(req) {
throw new Error('Invalid request');
}
const { website: website_uuid, hostname, screen, language } = payload;
const cache = req.headers['x-umami-cache'];
if (cache) {
@ -20,24 +21,30 @@ export async function getSession(req) {
}
}
const { website: website_uuid, hostname, screen, language } = payload;
if (!isValidUuid(website_uuid)) {
throw new Error(`Invalid website: ${website_uuid}`);
}
const { userAgent, browser, os, ip, country, device } = await getClientInfo(req, payload);
const website = await getWebsiteByUuid(website_uuid);
if (!website) {
throw new Error(`Website not found: ${website_uuid}`);
}
const { userAgent, browser, os, ip, country, device } = await getClientInfo(req, payload);
const { website_id } = website;
const session_uuid = uuid(website_id, hostname, ip, userAgent);
let session = await getSessionByUuid(session_uuid);
// logic placeholder for redis
runAnalyticsQuery({
[RELATIONAL]: () => {},
[CLICKHOUSE]: () => {},
});
console.log('session here!: ', session);
let session = await getSessionByUuid(session_uuid);
if (!session) {
try {