1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-25 12:56:41 +07:00

fetching backend stats

This commit is contained in:
Fedor Katurov 2020-06-09 12:35:54 +07:00
parent d260325592
commit be3401a4e5
5 changed files with 46 additions and 8 deletions

View file

@ -37,6 +37,6 @@ export const API = {
YOUTUBE: '/embed/youtube', YOUTUBE: '/embed/youtube',
}, },
BORIS: { BORIS: {
GET_GIT_LOG: 'http://vault48.org/stats/git.json', GET_BACKEND_STATS: '/stats',
}, },
}; };

View file

@ -1,3 +1,13 @@
import git from '~/stats/git.json'; import git from '~/stats/git.json';
import { API } from '~/constants/api';
import { api, resultMiddleware, errorMiddleware } from '~/utils/api';
import { IBorisState, IStatBackend } from './reducer';
import { IResultWithStatus } from '../types';
export const getBorisGitStats = (): Promise<any> => Promise.resolve(git); export const getBorisGitStats = (): Promise<IBorisState['stats']['git']> => Promise.resolve(git);
export const getBorisBackendStats = (): Promise<IResultWithStatus<IStatBackend>> =>
api
.get(API.BORIS.GET_BACKEND_STATS)
.then(resultMiddleware)
.catch(errorMiddleware);

View file

@ -7,9 +7,31 @@ export type IStatGitRow = {
timestamp: string; timestamp: string;
}; };
export type IStatBackend = {
users: {
total: number;
alive: number;
};
nodes: {
images: number;
audios: number;
videos: number;
texts: number;
total: number;
};
comments: {
total: number;
};
files: {
count: number;
size: number;
};
};
export type IBorisState = Readonly<{ export type IBorisState = Readonly<{
stats: { stats: {
git: IStatGitRow[]; git: IStatGitRow[];
backend: IStatBackend;
is_loading: boolean; is_loading: boolean;
}; };
}>; }>;
@ -17,6 +39,7 @@ export type IBorisState = Readonly<{
const BORIS_INITIAL_STATE: IBorisState = { const BORIS_INITIAL_STATE: IBorisState = {
stats: { stats: {
git: [], git: [],
backend: null,
is_loading: false, is_loading: false,
}, },
}; };

View file

@ -1,16 +1,21 @@
import { takeLatest, put, call } from 'redux-saga/effects'; import { takeLatest, put, call } from 'redux-saga/effects';
import { BORIS_ACTIONS } from './constants'; import { BORIS_ACTIONS } from './constants';
import { borisSet, borisSetStats } from './actions'; import { borisSetStats } from './actions';
import { getBorisGitStats } from './api'; import { getBorisGitStats, getBorisBackendStats } from './api';
import { Unwrap } from '../types';
function* loadStats() { function* loadStats() {
yield put(borisSetStats({ is_loading: true })); yield put(borisSetStats({ is_loading: true }));
try { try {
const git = yield getBorisGitStats(); const git: Unwrap<ReturnType<typeof getBorisGitStats>> = yield call(getBorisGitStats);
yield put(borisSetStats({ git, is_loading: false })); const backend: Unwrap<ReturnType<typeof getBorisBackendStats>> = yield call(
getBorisBackendStats
);
yield put(borisSetStats({ git, backend: backend.data, is_loading: false }));
} catch (e) { } catch (e) {
yield put(borisSetStats({ git: [], is_loading: false })); yield put(borisSetStats({ git: [], backend: null, is_loading: false }));
} }
} }

View file

@ -49,7 +49,7 @@ export interface IApiErrorResult {
export interface IResultWithStatus<T> { export interface IResultWithStatus<T> {
status: any; status: any;
data?: Partial<T> & IApiErrorResult; data?: T & IApiErrorResult;
error?: string; error?: string;
debug?: string; debug?: string;
} }