mirror of
https://github.com/umami-software/umami.git
synced 2026-02-22 05:25:36 +01:00
Compare commits
2 commits
f073fb1996
...
504c459090
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
504c459090 | ||
|
|
dfe969cabe |
3 changed files with 13 additions and 8 deletions
|
|
@ -24,9 +24,9 @@ export async function GET(request: Request, { params }: { params: Promise<{ link
|
||||||
|
|
||||||
export async function POST(request: Request, { params }: { params: Promise<{ linkId: string }> }) {
|
export async function POST(request: Request, { params }: { params: Promise<{ linkId: string }> }) {
|
||||||
const schema = z.object({
|
const schema = z.object({
|
||||||
name: z.string(),
|
name: z.string().optional(),
|
||||||
url: z.string(),
|
url: z.string().optional(),
|
||||||
slug: z.string(),
|
slug: z.string().min(8).optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const { auth, body, error } = await parseRequest(request, schema);
|
const { auth, body, error } = await parseRequest(request, schema);
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,8 @@ export async function GET(request: Request, { params }: { params: Promise<{ pixe
|
||||||
|
|
||||||
export async function POST(request: Request, { params }: { params: Promise<{ pixelId: string }> }) {
|
export async function POST(request: Request, { params }: { params: Promise<{ pixelId: string }> }) {
|
||||||
const schema = z.object({
|
const schema = z.object({
|
||||||
name: z.string(),
|
name: z.string().optional(),
|
||||||
slug: z.string().min(8),
|
slug: z.string().min(8).optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const { auth, body, error } = await parseRequest(request, schema);
|
const { auth, body, error } = await parseRequest(request, schema);
|
||||||
|
|
|
||||||
|
|
@ -82,6 +82,8 @@ export async function POST(request: Request) {
|
||||||
id,
|
id,
|
||||||
} = payload;
|
} = payload;
|
||||||
|
|
||||||
|
const sourceId = websiteId || pixelId || linkId;
|
||||||
|
|
||||||
// Cache check
|
// Cache check
|
||||||
let cache: Cache | null = null;
|
let cache: Cache | null = null;
|
||||||
|
|
||||||
|
|
@ -128,13 +130,13 @@ export async function POST(request: Request) {
|
||||||
const sessionSalt = hash(startOfMonth(createdAt).toUTCString());
|
const sessionSalt = hash(startOfMonth(createdAt).toUTCString());
|
||||||
const visitSalt = hash(startOfHour(createdAt).toUTCString());
|
const visitSalt = hash(startOfHour(createdAt).toUTCString());
|
||||||
|
|
||||||
const sessionId = id ? uuid(websiteId, id) : uuid(websiteId, ip, userAgent, sessionSalt);
|
const sessionId = id ? uuid(sourceId, id) : uuid(sourceId, ip, userAgent, sessionSalt);
|
||||||
|
|
||||||
// Create a session if not found
|
// Create a session if not found
|
||||||
if (!clickhouse.enabled && !cache?.sessionId) {
|
if (!clickhouse.enabled && !cache?.sessionId) {
|
||||||
await createSession({
|
await createSession({
|
||||||
id: sessionId,
|
id: sessionId,
|
||||||
websiteId,
|
websiteId: sourceId,
|
||||||
browser,
|
browser,
|
||||||
os,
|
os,
|
||||||
device,
|
device,
|
||||||
|
|
@ -206,7 +208,7 @@ export async function POST(request: Request) {
|
||||||
: EVENT_TYPE.pageView;
|
: EVENT_TYPE.pageView;
|
||||||
|
|
||||||
await saveEvent({
|
await saveEvent({
|
||||||
websiteId: websiteId || linkId || pixelId,
|
websiteId: sourceId,
|
||||||
sessionId,
|
sessionId,
|
||||||
visitId,
|
visitId,
|
||||||
eventType,
|
eventType,
|
||||||
|
|
@ -270,6 +272,9 @@ export async function POST(request: Request) {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const error = serializeError(e);
|
const error = serializeError(e);
|
||||||
|
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.log(error);
|
||||||
|
|
||||||
return serverError({ errorObject: error });
|
return serverError({ errorObject: error });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue