mirror of
https://github.com/umami-software/umami.git
synced 2026-02-09 23:27:12 +01:00
Update device filtering.
This commit is contained in:
parent
e17c9da3d5
commit
9d09d89aef
5 changed files with 32 additions and 26 deletions
|
|
@ -3,7 +3,13 @@ import { browserName, detectOS } from 'detect-browser';
|
|||
import isLocalhost from 'is-localhost-ip';
|
||||
import maxmind from 'maxmind';
|
||||
import geolite2 from 'geolite2-redist';
|
||||
import { DESKTOP_OS, MOBILE_OS, DESKTOP_SCREEN_WIDTH, MOBILE_SCREEN_WIDTH } from './constants';
|
||||
import {
|
||||
DESKTOP_OS,
|
||||
MOBILE_OS,
|
||||
DESKTOP_SCREEN_WIDTH,
|
||||
LAPTOP_SCREEN_WIDTH,
|
||||
MOBILE_SCREEN_WIDTH,
|
||||
} from './constants';
|
||||
|
||||
export function getIpAddress(req) {
|
||||
// Cloudflare
|
||||
|
|
@ -15,6 +21,8 @@ export function getIpAddress(req) {
|
|||
}
|
||||
|
||||
export function getDevice(screen, browser, os) {
|
||||
if (!screen) return;
|
||||
|
||||
const [width] = screen.split('x');
|
||||
|
||||
if (DESKTOP_OS.includes(os)) {
|
||||
|
|
@ -28,6 +36,16 @@ export function getDevice(screen, browser, os) {
|
|||
}
|
||||
return 'mobile';
|
||||
}
|
||||
|
||||
if (width >= DESKTOP_SCREEN_WIDTH) {
|
||||
return 'desktop';
|
||||
} else if (width >= LAPTOP_SCREEN_WIDTH) {
|
||||
return 'laptop';
|
||||
} else if (width >= MOBILE_SCREEN_WIDTH) {
|
||||
return 'tablet';
|
||||
} else {
|
||||
return 'mobile';
|
||||
}
|
||||
}
|
||||
|
||||
export async function getCountry(req, ip) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue