mirror of
https://github.com/kremalicious/umami.git
synced 2025-02-01 12:29:35 +01:00
Added types for session data.
This commit is contained in:
parent
32cfb74c49
commit
4ca4be4445
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "umami",
|
||||
"version": "2.11.2",
|
||||
"version": "2.12.0",
|
||||
"description": "A simple, fast, privacy-focused alternative to Google Analytics.",
|
||||
"author": "Umami Software, Inc. <hello@umami.is>",
|
||||
"license": "MIT",
|
||||
|
@ -132,7 +132,7 @@ export async function getClientInfo(req: NextApiRequestCollect) {
|
||||
const subdivision2 = location?.subdivision2;
|
||||
const city = location?.city;
|
||||
const browser = browserName(userAgent);
|
||||
const os = detectOS(userAgent);
|
||||
const os = detectOS(userAgent) as string;
|
||||
const device = getDevice(req.body?.payload?.screen, os);
|
||||
|
||||
return { userAgent, browser, os, ip, country, subdivision1, subdivision2, city, device };
|
||||
|
@ -4,7 +4,7 @@ import redis from '@umami/redis-client';
|
||||
import { getAuthToken, parseShareToken } from 'lib/auth';
|
||||
import { ROLES } from 'lib/constants';
|
||||
import { secret } from 'lib/crypto';
|
||||
import { findSession } from 'lib/session';
|
||||
import { getSession } from 'lib/session';
|
||||
import {
|
||||
badRequest,
|
||||
createMiddleware,
|
||||
@ -27,7 +27,7 @@ export const useCors = createMiddleware(
|
||||
|
||||
export const useSession = createMiddleware(async (req, res, next) => {
|
||||
try {
|
||||
const session = await findSession(req as NextApiRequestCollect);
|
||||
const session = await getSession(req as NextApiRequestCollect);
|
||||
|
||||
if (!session) {
|
||||
log('useSession: Session not found');
|
||||
|
@ -6,23 +6,9 @@ import { createSession } from 'queries';
|
||||
import cache from './cache';
|
||||
import clickhouse from './clickhouse';
|
||||
import { loadSession, loadWebsite } from './load';
|
||||
import { SessionData } from 'lib/types';
|
||||
|
||||
export async function findSession(req: NextApiRequestCollect): Promise<{
|
||||
id: any;
|
||||
websiteId: string;
|
||||
visitId: string;
|
||||
hostname: string;
|
||||
browser: string;
|
||||
os: any;
|
||||
device: string;
|
||||
screen: string;
|
||||
language: string;
|
||||
country: any;
|
||||
subdivision1: any;
|
||||
subdivision2: any;
|
||||
city: any;
|
||||
ownerId: string;
|
||||
}> {
|
||||
export async function getSession(req: NextApiRequestCollect): Promise<SessionData> {
|
||||
const { payload } = req.body;
|
||||
|
||||
if (!payload) {
|
||||
@ -35,6 +21,7 @@ export async function findSession(req: NextApiRequestCollect): Promise<{
|
||||
if (cacheToken) {
|
||||
const result = await parseToken(cacheToken, secret());
|
||||
|
||||
// Token is valid
|
||||
if (result) {
|
||||
await checkUserBlock(result?.ownerId);
|
||||
|
||||
@ -45,7 +32,6 @@ export async function findSession(req: NextApiRequestCollect): Promise<{
|
||||
// Verify payload
|
||||
const { website: websiteId, hostname, screen, language } = payload;
|
||||
|
||||
// Check the hostname value for legality to eliminate dirty data
|
||||
const validHostnameRegex = /^[\w-.]+$/;
|
||||
if (!validHostnameRegex.test(hostname)) {
|
||||
throw new Error('Invalid hostname.');
|
||||
@ -78,7 +64,7 @@ export async function findSession(req: NextApiRequestCollect): Promise<{
|
||||
visitId,
|
||||
hostname,
|
||||
browser,
|
||||
os: os as any,
|
||||
os,
|
||||
device,
|
||||
screen,
|
||||
language,
|
||||
|
@ -230,3 +230,20 @@ export interface RealtimeData {
|
||||
countries?: any[];
|
||||
visitors?: any[];
|
||||
}
|
||||
|
||||
export interface SessionData {
|
||||
id: string;
|
||||
websiteId: string;
|
||||
visitId: string;
|
||||
hostname: string;
|
||||
browser: string;
|
||||
os: string;
|
||||
device: string;
|
||||
screen: string;
|
||||
language: string;
|
||||
country: string;
|
||||
subdivision1: string;
|
||||
subdivision2: string;
|
||||
city: string;
|
||||
ownerId: string;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user