mirror of
https://github.com/kremalicious/umami.git
synced 2024-11-15 01:35:17 +01:00
35 lines
751 B
JavaScript
35 lines
751 B
JavaScript
import { getWebsite, getSession, createSession } from 'lib/db';
|
|
import { hash, parseSessionRequest } from 'lib/utils';
|
|
|
|
export default async (req, res) => {
|
|
let result = { time: Date.now() };
|
|
const {
|
|
website_id,
|
|
session_id,
|
|
browser,
|
|
os,
|
|
screen,
|
|
language,
|
|
country,
|
|
} = await parseSessionRequest(req);
|
|
|
|
const website = await getWebsite(website_id);
|
|
|
|
if (website) {
|
|
const session = await getSession(session_id);
|
|
|
|
if (!session) {
|
|
await createSession(website_id, session_id, { browser, os, screen, language, country });
|
|
}
|
|
|
|
result = {
|
|
...result,
|
|
session_id,
|
|
website_id,
|
|
hash: hash(`${website_id}${session_id}${result.time}`),
|
|
};
|
|
}
|
|
|
|
res.status(200).json(result);
|
|
};
|