mirror of
https://github.com/umami-software/umami.git
synced 2025-12-06 01:18:00 +01:00
Initial commit.
This commit is contained in:
commit
f7f0c05e12
27 changed files with 13028 additions and 0 deletions
28
pages/api/session.js
Normal file
28
pages/api/session.js
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
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 } = 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);
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue