Frontend fixes
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { randUserName, randPastDate, randIp, randPassword, randUuid, randNumber } from '@ngneat/falso';
|
||||
import { randUserName, randRecentDate, randIp, randPassword, randUuid, randNumber } from '@ngneat/falso';
|
||||
import { r } from 'react-router/dist/development/fog-of-war-Cm1iXIp7';
|
||||
|
||||
export interface LoginAttempt {
|
||||
readonly date: string;
|
||||
@@ -23,16 +24,18 @@ export interface StatsResult {
|
||||
count: number;
|
||||
}
|
||||
|
||||
export type StatsType = 'password' | 'username' | 'ip' | 'country' | 'attempts';
|
||||
|
||||
export interface ApiaryAPI {
|
||||
live(fn: (a: LoginAttempt) => void): void;
|
||||
stats(statsType: string, limit: number): Promise<StatsResult[]>;
|
||||
stats(statsType: StatsType, limit: number): Promise<StatsResult[]>;
|
||||
query(queryType: string, query: string): Promise<LoginAttempt[]>;
|
||||
totals(): Promise<TotalStats>;
|
||||
}
|
||||
|
||||
function fakeLoginAttempt(): LoginAttempt {
|
||||
return {
|
||||
date: randPastDate().toISOString(),
|
||||
date: randRecentDate({days: 2}).toISOString(),
|
||||
remoteIP: randIp().toString(),
|
||||
username: randUserName().toString(),
|
||||
password: randPassword().toString(),
|
||||
@@ -51,8 +54,18 @@ export class DummyApiaryAPIClient implements ApiaryAPI {
|
||||
|
||||
return () => { clearInterval(interval) }
|
||||
}
|
||||
async stats(_type: string, limit: number): Promise<StatsResult[]> {
|
||||
async stats(_type: StatsType, limit: number): Promise<StatsResult[]> {
|
||||
const stats = Array.from({ length: limit }, () => {
|
||||
switch (_type) {
|
||||
case 'password':
|
||||
return { name: randPassword().toString(), count: randNumber().valueOf() }
|
||||
case 'username':
|
||||
return { name: randUserName().toString(), count: randNumber().valueOf() }
|
||||
case 'ip':
|
||||
return { name: randIp().toString(), count: randNumber().valueOf() }
|
||||
case 'country':
|
||||
return { name: 'NO', count: randNumber().valueOf() }
|
||||
}
|
||||
return { name: randUserName().toString(), count: randNumber().valueOf() }
|
||||
});
|
||||
return Promise.resolve(stats);
|
||||
@@ -83,7 +96,7 @@ export class ApiaryAPIClient implements ApiaryAPI {
|
||||
es.close();
|
||||
}
|
||||
}
|
||||
async stats(statsType: string, limit: number): Promise<StatsResult[]> {
|
||||
async stats(statsType: StatsType, limit: number): Promise<StatsResult[]> {
|
||||
const resp = await fetch(`/api/stats?type=${statsType}&limit=${limit}`)
|
||||
if (!resp.ok) {
|
||||
throw new Error('Failed to fetch query')
|
||||
|
Reference in New Issue
Block a user