1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-24 20:36:40 +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',
},
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 { 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;
};
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<{
stats: {
git: IStatGitRow[];
backend: IStatBackend;
is_loading: boolean;
};
}>;
@ -17,6 +39,7 @@ export type IBorisState = Readonly<{
const BORIS_INITIAL_STATE: IBorisState = {
stats: {
git: [],
backend: null,
is_loading: false,
},
};

View file

@ -1,16 +1,21 @@
import { takeLatest, put, call } from 'redux-saga/effects';
import { BORIS_ACTIONS } from './constants';
import { borisSet, borisSetStats } from './actions';
import { getBorisGitStats } from './api';
import { borisSetStats } from './actions';
import { getBorisGitStats, getBorisBackendStats } from './api';
import { Unwrap } from '../types';
function* loadStats() {
yield put(borisSetStats({ is_loading: true }));
try {
const git = yield getBorisGitStats();
yield put(borisSetStats({ git, is_loading: false }));
const git: Unwrap<ReturnType<typeof getBorisGitStats>> = yield call(getBorisGitStats);
const backend: Unwrap<ReturnType<typeof getBorisBackendStats>> = yield call(
getBorisBackendStats
);
yield put(borisSetStats({ git, backend: backend.data, is_loading: false }));
} 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> {
status: any;
data?: Partial<T> & IApiErrorResult;
data?: T & IApiErrorResult;
error?: string;
debug?: string;
}