2018-04-05 19:13:32 +00:00
|
|
|
import createReducer from 'utils/createReducer';
|
2017-05-26 06:20:00 +00:00
|
|
|
import * as actions from './actions';
|
|
|
|
|
|
|
|
export const getSettings = state => state.settings;
|
|
|
|
|
2018-04-25 03:36:27 +00:00
|
|
|
export default createReducer(
|
|
|
|
{},
|
|
|
|
{
|
|
|
|
[actions.UPLOAD_CERT](state) {
|
|
|
|
state.uploadingCert = true;
|
|
|
|
},
|
2017-05-26 06:20:00 +00:00
|
|
|
|
2018-04-25 03:36:27 +00:00
|
|
|
[actions.socket.CERT_SUCCESS](state) {
|
|
|
|
state.uploadingCert = false;
|
|
|
|
delete state.certFile;
|
|
|
|
delete state.cert;
|
|
|
|
delete state.keyFile;
|
|
|
|
delete state.key;
|
|
|
|
},
|
2017-05-26 06:20:00 +00:00
|
|
|
|
2018-04-25 03:36:27 +00:00
|
|
|
[actions.socket.CERT_FAIL](state, action) {
|
|
|
|
state.uploadingCert = false;
|
|
|
|
state.certError = action.message;
|
|
|
|
},
|
2017-05-26 06:20:00 +00:00
|
|
|
|
2018-04-25 03:36:27 +00:00
|
|
|
[actions.SET_CERT_ERROR](state, action) {
|
|
|
|
state.uploadingCert = false;
|
|
|
|
state.certError = action.message;
|
|
|
|
},
|
2017-05-26 06:20:00 +00:00
|
|
|
|
2018-04-25 03:36:27 +00:00
|
|
|
[actions.SET_CERT](state, action) {
|
|
|
|
state.certFile = action.fileName;
|
|
|
|
state.cert = action.cert;
|
|
|
|
},
|
2017-05-26 06:20:00 +00:00
|
|
|
|
2018-04-25 03:36:27 +00:00
|
|
|
[actions.SET_KEY](state, action) {
|
|
|
|
state.keyFile = action.fileName;
|
|
|
|
state.key = action.key;
|
2018-10-15 06:56:17 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
[actions.SETTINGS_SET](state, { key, value, settings }) {
|
|
|
|
if (settings) {
|
2019-01-05 06:08:34 +00:00
|
|
|
Object.assign(state, settings);
|
2018-10-15 06:56:17 +00:00
|
|
|
} else {
|
|
|
|
state[key] = value;
|
|
|
|
}
|
2018-04-25 03:36:27 +00:00
|
|
|
}
|
2017-05-26 06:20:00 +00:00
|
|
|
}
|
2018-04-25 03:36:27 +00:00
|
|
|
);
|
2017-05-26 06:20:00 +00:00
|
|
|
|
|
|
|
export function setCertError(message) {
|
|
|
|
return {
|
|
|
|
type: actions.SET_CERT_ERROR,
|
|
|
|
message
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function uploadCert() {
|
|
|
|
return (dispatch, getState) => {
|
|
|
|
const { settings } = getState();
|
2018-04-25 03:36:27 +00:00
|
|
|
if (settings.cert && settings.key) {
|
2017-05-26 06:20:00 +00:00
|
|
|
dispatch({
|
|
|
|
type: actions.UPLOAD_CERT,
|
|
|
|
socket: {
|
|
|
|
type: 'cert',
|
|
|
|
data: {
|
2018-04-25 03:36:27 +00:00
|
|
|
cert: settings.cert,
|
|
|
|
key: settings.key
|
2017-05-26 06:20:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
dispatch(setCertError('Missing certificate or key'));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function setCert(fileName, cert) {
|
|
|
|
return {
|
|
|
|
type: actions.SET_CERT,
|
|
|
|
fileName,
|
2018-10-10 19:23:42 +00:00
|
|
|
cert: cert
|
2017-05-26 06:20:00 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function setKey(fileName, key) {
|
|
|
|
return {
|
|
|
|
type: actions.SET_KEY,
|
|
|
|
fileName,
|
2018-10-10 19:23:42 +00:00
|
|
|
key: key
|
2017-05-26 06:20:00 +00:00
|
|
|
};
|
|
|
|
}
|
2018-10-15 06:56:17 +00:00
|
|
|
|
|
|
|
export function setSetting(key, value) {
|
|
|
|
return {
|
|
|
|
type: actions.SETTINGS_SET,
|
|
|
|
key,
|
|
|
|
value,
|
|
|
|
socket: {
|
|
|
|
type: 'settings_set',
|
|
|
|
data: {
|
|
|
|
[key]: value
|
|
|
|
},
|
|
|
|
debounce: {
|
|
|
|
delay: 250,
|
|
|
|
key: `settings:${key}`
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function setSettings(settings, local = false) {
|
|
|
|
const action = {
|
|
|
|
type: actions.SETTINGS_SET,
|
|
|
|
settings
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!local) {
|
|
|
|
action.socket = {
|
|
|
|
type: 'settings_set',
|
|
|
|
data: settings
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return action;
|
|
|
|
}
|