bigbuffet-rw/app/soapbox/actions/backups.ts

32 lines
1.2 KiB
TypeScript
Raw Normal View History

2021-01-07 12:17:06 -08:00
import api from '../api';
import type { AppDispatch, RootState } from 'soapbox/store';
2021-01-07 12:17:06 -08:00
export const BACKUPS_FETCH_REQUEST = 'BACKUPS_FETCH_REQUEST';
export const BACKUPS_FETCH_SUCCESS = 'BACKUPS_FETCH_SUCCESS';
export const BACKUPS_FETCH_FAIL = 'BACKUPS_FETCH_FAIL';
export const BACKUPS_CREATE_REQUEST = 'BACKUPS_CREATE_REQUEST';
export const BACKUPS_CREATE_SUCCESS = 'BACKUPS_CREATE_SUCCESS';
export const BACKUPS_CREATE_FAIL = 'BACKUPS_CREATE_FAIL';
export const fetchBackups = () =>
(dispatch: AppDispatch, getState: () => RootState) => {
2021-01-07 12:17:06 -08:00
dispatch({ type: BACKUPS_FETCH_REQUEST });
return api(getState).get('/api/v1/pleroma/backups').then(({ data: backups }) =>
dispatch({ type: BACKUPS_FETCH_SUCCESS, backups }),
).catch(error => {
2021-01-07 12:17:06 -08:00
dispatch({ type: BACKUPS_FETCH_FAIL, error });
});
};
export const createBackup = () =>
(dispatch: AppDispatch, getState: () => RootState) => {
2021-01-07 12:17:06 -08:00
dispatch({ type: BACKUPS_CREATE_REQUEST });
return api(getState).post('/api/v1/pleroma/backups').then(({ data: backups }) =>
dispatch({ type: BACKUPS_CREATE_SUCCESS, backups }),
).catch(error => {
2021-01-07 12:17:06 -08:00
dispatch({ type: BACKUPS_CREATE_FAIL, error });
});
};