2020-04-01 13:05:52 -07:00
|
|
|
import api from '../api';
|
2020-05-31 10:01:21 -07:00
|
|
|
import { get } from 'lodash';
|
|
|
|
import { parseVersion } from 'soapbox/utils/features';
|
2020-04-01 13:05:52 -07:00
|
|
|
|
2020-06-03 12:24:53 -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));
|
2020-05-31 10:01:21 -07:00
|
|
|
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));
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-05-31 10:01:21 -07:00
|
|
|
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 {
|
2020-06-03 12:24:53 -07:00
|
|
|
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 {
|
2020-06-03 12:24:53 -07:00
|
|
|
type: INSTANCE_FETCH_FAIL,
|
2020-04-01 13:05:52 -07:00
|
|
|
error,
|
|
|
|
skipAlert: true,
|
|
|
|
};
|
2021-08-03 12:22:51 -07:00
|
|
|
}
|
2020-05-31 10:01:21 -07:00
|
|
|
|
|
|
|
export function importNodeinfo(nodeinfo) {
|
|
|
|
return {
|
2020-06-03 12:24:53 -07:00
|
|
|
type: NODEINFO_FETCH_SUCCESS,
|
2020-05-31 10:01:21 -07:00
|
|
|
nodeinfo,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function nodeinfoFail(error) {
|
|
|
|
return {
|
2020-06-03 12:24:53 -07:00
|
|
|
type: NODEINFO_FETCH_FAIL,
|
2020-05-31 10:01:21 -07:00
|
|
|
error,
|
|
|
|
skipAlert: true,
|
|
|
|
};
|
2021-08-03 12:22:51 -07:00
|
|
|
}
|