mirror of
https://github.com/kremalicious/umami.git
synced 2024-11-22 09:57:00 +01:00
Merge pull request #2479 from enfiniteio/feat/api-send-visitor-ip
Allow setting visitor IP when registering event through API
This commit is contained in:
commit
474113fe32
@ -215,6 +215,7 @@ export const UUID_REGEX =
|
|||||||
/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/;
|
/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/;
|
||||||
export const HOSTNAME_REGEX =
|
export const HOSTNAME_REGEX =
|
||||||
/^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9-]*[A-Za-z0-9])$/;
|
/^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9-]*[A-Za-z0-9])$/;
|
||||||
|
export const IP_REGEX = /^((25[0-5]|(2[0-4]|1[0-9]|[1-9]|)[0-9])(\.(?!$)|$)){4}$/;
|
||||||
|
|
||||||
export const DESKTOP_SCREEN_WIDTH = 1920;
|
export const DESKTOP_SCREEN_WIDTH = 1920;
|
||||||
export const LAPTOP_SCREEN_WIDTH = 1024;
|
export const LAPTOP_SCREEN_WIDTH = 1024;
|
||||||
|
@ -123,7 +123,7 @@ export async function getLocation(ip, req) {
|
|||||||
|
|
||||||
export async function getClientInfo(req: NextApiRequestCollect, { screen }) {
|
export async function getClientInfo(req: NextApiRequestCollect, { screen }) {
|
||||||
const userAgent = req.headers['user-agent'];
|
const userAgent = req.headers['user-agent'];
|
||||||
const ip = getIpAddress(req);
|
const ip = req.body.payload.ip || getIpAddress(req);
|
||||||
const location = await getLocation(ip, req);
|
const location = await getLocation(ip, req);
|
||||||
const country = location?.country;
|
const country = location?.country;
|
||||||
const subdivision1 = location?.subdivision1;
|
const subdivision1 = location?.subdivision1;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import ipaddr from 'ipaddr.js';
|
import ipaddr from 'ipaddr.js';
|
||||||
import isbot from 'isbot';
|
import isbot from 'isbot';
|
||||||
import { COLLECTION_TYPE, HOSTNAME_REGEX } from 'lib/constants';
|
import { COLLECTION_TYPE, HOSTNAME_REGEX, IP_REGEX } from 'lib/constants';
|
||||||
import { secret } from 'lib/crypto';
|
import { secret } from 'lib/crypto';
|
||||||
import { getIpAddress } from 'lib/detect';
|
import { getIpAddress } from 'lib/detect';
|
||||||
import { useCors, useSession, useValidate } from 'lib/middleware';
|
import { useCors, useSession, useValidate } from 'lib/middleware';
|
||||||
@ -14,6 +14,7 @@ export interface CollectRequestBody {
|
|||||||
payload: {
|
payload: {
|
||||||
data: { [key: string]: any };
|
data: { [key: string]: any };
|
||||||
hostname: string;
|
hostname: string;
|
||||||
|
ip: string;
|
||||||
language: string;
|
language: string;
|
||||||
referrer: string;
|
referrer: string;
|
||||||
screen: string;
|
screen: string;
|
||||||
@ -53,6 +54,7 @@ const schema = {
|
|||||||
.shape({
|
.shape({
|
||||||
data: yup.object(),
|
data: yup.object(),
|
||||||
hostname: yup.string().matches(HOSTNAME_REGEX).max(100),
|
hostname: yup.string().matches(HOSTNAME_REGEX).max(100),
|
||||||
|
ip: yup.string().matches(IP_REGEX),
|
||||||
language: yup.string().max(35),
|
language: yup.string().max(35),
|
||||||
referrer: yup.string().max(500),
|
referrer: yup.string().max(500),
|
||||||
screen: yup.string().max(11),
|
screen: yup.string().max(11),
|
||||||
|
Loading…
Reference in New Issue
Block a user