bigbuffet-rw/app/soapbox/actions/instance.js

63 lines
1.5 KiB
JavaScript
Raw Normal View History

2020-04-01 13:05:52 -07:00
import api from '../api';
import { get } from 'lodash';
import { parseVersion } from 'soapbox/utils/features';
2020-04-01 13:05:52 -07:00
export const INSTANCE_FETCH_SUCCESS = 'INSTANCE_FETCH_SUCCESS';
export const INSTANCE_FETCH_FAIL = 'INSTANCE_FETCH_FAIL';
export const NODEINFO_FETCH_SUCCESS = 'NODEINFO_FETCH_SUCCESS';
export const NODEINFO_FETCH_FAIL = 'NODEINFO_FETCH_FAIL';
2020-04-01 13:05:52 -07:00
export function fetchInstance() {
return (dispatch, getState) => {
2021-07-27 12:40:41 -07:00
return api(getState).get('/api/v1/instance').then(response => {
2020-04-01 13:05:52 -07:00
dispatch(importInstance(response.data));
const v = parseVersion(get(response.data, 'version'));
if (v.software === 'Pleroma' && !get(response.data, ['pleroma', 'metadata'])) {
dispatch(fetchNodeinfo()); // Pleroma < 2.1 backwards compatibility
}
2020-04-01 13:05:52 -07:00
}).catch(error => {
dispatch(instanceFail(error));
});
};
}
export function fetchNodeinfo() {
return (dispatch, getState) => {
api(getState).get('/nodeinfo/2.1.json').then(response => {
dispatch(importNodeinfo(response.data));
}).catch(error => {
dispatch(nodeinfoFail(error));
});
};
}
2020-04-01 13:05:52 -07:00
export function importInstance(instance) {
return {
type: INSTANCE_FETCH_SUCCESS,
2020-04-14 11:44:40 -07:00
instance,
2020-04-01 13:05:52 -07:00
};
}
export function instanceFail(error) {
return {
type: INSTANCE_FETCH_FAIL,
2020-04-01 13:05:52 -07:00
error,
skipAlert: true,
};
2021-08-03 12:22:51 -07:00
}
export function importNodeinfo(nodeinfo) {
return {
type: NODEINFO_FETCH_SUCCESS,
nodeinfo,
};
}
export function nodeinfoFail(error) {
return {
type: NODEINFO_FETCH_FAIL,
error,
skipAlert: true,
};
2021-08-03 12:22:51 -07:00
}