Sonarr/frontend/src/Utilities/requestAction.js

42 lines
872 B
JavaScript
Raw Normal View History

2018-01-13 02:01:27 +00:00
import $ from 'jquery';
import _ from 'lodash';
2019-03-03 19:29:12 +00:00
import createAjaxRequest from './createAjaxRequest';
2018-01-13 02:01:27 +00:00
function flattenProviderData(providerData) {
return _.reduce(Object.keys(providerData), (result, key) => {
const property = providerData[key];
if (key === 'fields') {
result[key] = property;
} else {
result[key] = property.value;
}
return result;
}, {});
}
function requestAction(payload) {
const {
provider,
action,
providerData,
queryParams
} = payload;
const ajaxOptions = {
url: `/${provider}/action/${action}`,
contentType: 'application/json',
method: 'POST',
data: JSON.stringify(flattenProviderData(providerData))
};
if (queryParams) {
ajaxOptions.url += `?${$.param(queryParams, true)}`;
}
2019-03-03 19:29:12 +00:00
return createAjaxRequest(ajaxOptions).request;
2018-01-13 02:01:27 +00:00
}
export default requestAction;