Skip to content

Commit

Permalink
Merge branch 'dev' into analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
mikecao committed Apr 16, 2024
2 parents 8451e32 + 0ef62d0 commit a0f9a3c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 31 deletions.
34 changes: 14 additions & 20 deletions src/lib/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export function parseDateRange(value: string | object, locale = 'en-US'): DateRa
switch (unit) {
case 'hour':
return {
startDate: subHours(startOfHour(now), num),
startDate: num ? subHours(startOfHour(now), num - 1) : startOfHour(now),
endDate: endOfHour(now),
offset: 0,
num: num || 1,
Expand All @@ -163,35 +163,37 @@ export function parseDateRange(value: string | object, locale = 'en-US'): DateRa
};
case 'day':
return {
startDate: subDays(startOfDay(now), num),
endDate: subDays(endOfDay(now), num ? 1 : 0),
startDate: num ? subDays(startOfDay(now), num - 1) : startOfDay(now),
endDate: endOfDay(now),
unit: num ? 'day' : 'hour',
offset: 0,
num: num || 1,
value,
};
case 'week':
return {
startDate: subWeeks(startOfWeek(now, { locale: dateLocale }), num),
endDate: subWeeks(endOfWeek(now, { locale: dateLocale }), num),
startDate: num
? subWeeks(startOfWeek(now, { locale: dateLocale }), num - 1)
: startOfWeek(now, { locale: dateLocale }),
endDate: endOfWeek(now, { locale: dateLocale }),
unit: 'day',
offset: 0,
num: num || 1,
value,
};
case 'month':
return {
startDate: subMonths(startOfMonth(now), num),
endDate: subMonths(endOfMonth(now), num ? 1 : 0),
startDate: num ? subMonths(startOfMonth(now), num - 1) : startOfMonth(now),
endDate: endOfMonth(now),
unit: num ? 'month' : 'day',
offset: 0,
num: num || 1,
value,
};
case 'year':
return {
startDate: subYears(startOfYear(now), num),
endDate: subYears(endOfYear(now), num),
startDate: num ? subYears(startOfYear(now), num - 1) : startOfYear(now),
endDate: endOfYear(now),
unit: 'month',
offset: 0,
num: num || 1,
Expand Down Expand Up @@ -286,19 +288,11 @@ export function getDateFromString(str: string) {
export function getDateArray(data: any[], startDate: Date, endDate: Date, unit: string) {
const arr = [];
const { diff, add, start } = DATE_FUNCTIONS[unit];
const n = diff(endDate, startDate) + 1;
const n = diff(endDate, startDate);

function findData(date: Date) {
const d = data.find(({ x }) => {
return start(getDateFromString(x)).getTime() === date.getTime();
});

return d?.y || 0;
}

for (let i = 0; i < n; i++) {
for (let i = 0; i <= n; 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 });
}
Expand Down
11 changes: 0 additions & 11 deletions src/pages/api/auth/login.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import redis from '@umami/redis-client';
import debug from 'debug';
import { saveAuth } from 'lib/auth';
import { secret } from 'lib/crypto';
import { useValidate } from 'lib/middleware';
Expand All @@ -16,9 +15,6 @@ import {
import { getUserByUsername } from 'queries';
import * as yup from 'yup';
import { ROLES } from 'lib/constants';
import { getIpAddress } from 'lib/detect';

const log = debug('umami:auth');

export interface LoginRequestBody {
username: string;
Expand Down Expand Up @@ -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');
}

Expand Down

0 comments on commit a0f9a3c

Please sign in to comment.