mirror of
https://github.com/kremalicious/umami.git
synced 2024-06-30 21:51:59 +02:00
52 lines
1.0 KiB
JavaScript
52 lines
1.0 KiB
JavaScript
import { getWebsite, getSession, createSession } from 'lib/db';
|
|
import { hash, parseSessionRequest } from 'lib/utils';
|
|
import { allowPost } from 'lib/middleware';
|
|
|
|
export default async (req, res) => {
|
|
await allowPost(req, res);
|
|
|
|
let result = { success: 0 };
|
|
|
|
const {
|
|
website_id,
|
|
session_id,
|
|
hostname,
|
|
browser,
|
|
os,
|
|
screen,
|
|
language,
|
|
country,
|
|
} = await parseSessionRequest(req);
|
|
|
|
if (website_id && session_id) {
|
|
const website = await getWebsite(website_id);
|
|
|
|
if (website) {
|
|
const session = await getSession(session_id);
|
|
const time = Date.now();
|
|
|
|
if (!session) {
|
|
await createSession(website_id, session_id, {
|
|
hostname,
|
|
browser,
|
|
os,
|
|
screen,
|
|
language,
|
|
country,
|
|
});
|
|
}
|
|
|
|
result = {
|
|
...result,
|
|
success: 1,
|
|
session_id,
|
|
website_id,
|
|
time,
|
|
hash: hash(`${website_id}${session_id}${time}`),
|
|
};
|
|
}
|
|
}
|
|
|
|
res.status(200).json(result);
|
|
};
|