mirror of
https://github.com/umami-software/umami.git
synced 2026-02-13 00:55:37 +01:00
Merge branch 'dev' into analytics
This commit is contained in:
commit
a0f9a3ce2b
2 changed files with 14 additions and 31 deletions
|
|
@ -154,7 +154,7 @@ export function parseDateRange(value: string | object, locale = 'en-US'): DateRa
|
||||||
switch (unit) {
|
switch (unit) {
|
||||||
case 'hour':
|
case 'hour':
|
||||||
return {
|
return {
|
||||||
startDate: subHours(startOfHour(now), num),
|
startDate: num ? subHours(startOfHour(now), num - 1) : startOfHour(now),
|
||||||
endDate: endOfHour(now),
|
endDate: endOfHour(now),
|
||||||
offset: 0,
|
offset: 0,
|
||||||
num: num || 1,
|
num: num || 1,
|
||||||
|
|
@ -163,8 +163,8 @@ export function parseDateRange(value: string | object, locale = 'en-US'): DateRa
|
||||||
};
|
};
|
||||||
case 'day':
|
case 'day':
|
||||||
return {
|
return {
|
||||||
startDate: subDays(startOfDay(now), num),
|
startDate: num ? subDays(startOfDay(now), num - 1) : startOfDay(now),
|
||||||
endDate: subDays(endOfDay(now), num ? 1 : 0),
|
endDate: endOfDay(now),
|
||||||
unit: num ? 'day' : 'hour',
|
unit: num ? 'day' : 'hour',
|
||||||
offset: 0,
|
offset: 0,
|
||||||
num: num || 1,
|
num: num || 1,
|
||||||
|
|
@ -172,8 +172,10 @@ export function parseDateRange(value: string | object, locale = 'en-US'): DateRa
|
||||||
};
|
};
|
||||||
case 'week':
|
case 'week':
|
||||||
return {
|
return {
|
||||||
startDate: subWeeks(startOfWeek(now, { locale: dateLocale }), num),
|
startDate: num
|
||||||
endDate: subWeeks(endOfWeek(now, { locale: dateLocale }), num),
|
? subWeeks(startOfWeek(now, { locale: dateLocale }), num - 1)
|
||||||
|
: startOfWeek(now, { locale: dateLocale }),
|
||||||
|
endDate: endOfWeek(now, { locale: dateLocale }),
|
||||||
unit: 'day',
|
unit: 'day',
|
||||||
offset: 0,
|
offset: 0,
|
||||||
num: num || 1,
|
num: num || 1,
|
||||||
|
|
@ -181,8 +183,8 @@ export function parseDateRange(value: string | object, locale = 'en-US'): DateRa
|
||||||
};
|
};
|
||||||
case 'month':
|
case 'month':
|
||||||
return {
|
return {
|
||||||
startDate: subMonths(startOfMonth(now), num),
|
startDate: num ? subMonths(startOfMonth(now), num - 1) : startOfMonth(now),
|
||||||
endDate: subMonths(endOfMonth(now), num ? 1 : 0),
|
endDate: endOfMonth(now),
|
||||||
unit: num ? 'month' : 'day',
|
unit: num ? 'month' : 'day',
|
||||||
offset: 0,
|
offset: 0,
|
||||||
num: num || 1,
|
num: num || 1,
|
||||||
|
|
@ -190,8 +192,8 @@ export function parseDateRange(value: string | object, locale = 'en-US'): DateRa
|
||||||
};
|
};
|
||||||
case 'year':
|
case 'year':
|
||||||
return {
|
return {
|
||||||
startDate: subYears(startOfYear(now), num),
|
startDate: num ? subYears(startOfYear(now), num - 1) : startOfYear(now),
|
||||||
endDate: subYears(endOfYear(now), num),
|
endDate: endOfYear(now),
|
||||||
unit: 'month',
|
unit: 'month',
|
||||||
offset: 0,
|
offset: 0,
|
||||||
num: num || 1,
|
num: num || 1,
|
||||||
|
|
@ -286,19 +288,11 @@ export function getDateFromString(str: string) {
|
||||||
export function getDateArray(data: any[], startDate: Date, endDate: Date, unit: string) {
|
export function getDateArray(data: any[], startDate: Date, endDate: Date, unit: string) {
|
||||||
const arr = [];
|
const arr = [];
|
||||||
const { diff, add, start } = DATE_FUNCTIONS[unit];
|
const { diff, add, start } = DATE_FUNCTIONS[unit];
|
||||||
const n = diff(endDate, startDate) + 1;
|
const n = diff(endDate, startDate);
|
||||||
|
|
||||||
function findData(date: Date) {
|
for (let i = 0; i <= n; i++) {
|
||||||
const d = data.find(({ x }) => {
|
|
||||||
return start(getDateFromString(x)).getTime() === date.getTime();
|
|
||||||
});
|
|
||||||
|
|
||||||
return d?.y || 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let i = 0; i < n; i++) {
|
|
||||||
const t = start(add(startDate, i));
|
const t = start(add(startDate, i));
|
||||||
const y = findData(t);
|
const y = data.find(({ x }) => start(getDateFromString(x)).getTime() === t.getTime())?.y || 0;
|
||||||
|
|
||||||
arr.push({ x: t, y });
|
arr.push({ x: t, y });
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
import redis from '@umami/redis-client';
|
import redis from '@umami/redis-client';
|
||||||
import debug from 'debug';
|
|
||||||
import { saveAuth } from 'lib/auth';
|
import { saveAuth } from 'lib/auth';
|
||||||
import { secret } from 'lib/crypto';
|
import { secret } from 'lib/crypto';
|
||||||
import { useValidate } from 'lib/middleware';
|
import { useValidate } from 'lib/middleware';
|
||||||
|
|
@ -16,9 +15,6 @@ import {
|
||||||
import { getUserByUsername } from 'queries';
|
import { getUserByUsername } from 'queries';
|
||||||
import * as yup from 'yup';
|
import * as yup from 'yup';
|
||||||
import { ROLES } from 'lib/constants';
|
import { ROLES } from 'lib/constants';
|
||||||
import { getIpAddress } from 'lib/detect';
|
|
||||||
|
|
||||||
const log = debug('umami:auth');
|
|
||||||
|
|
||||||
export interface LoginRequestBody {
|
export interface LoginRequestBody {
|
||||||
username: string;
|
username: string;
|
||||||
|
|
@ -68,13 +64,6 @@ export default async (
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
log(
|
|
||||||
`Login from ip ${getIpAddress(req)} with username "${username.replace(
|
|
||||||
/["\r\n]/g,
|
|
||||||
'',
|
|
||||||
)}" failed.`,
|
|
||||||
);
|
|
||||||
|
|
||||||
return unauthorized(res, 'message.incorrect-username-password');
|
return unauthorized(res, 'message.incorrect-username-password');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue