You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Radarr/frontend/src/Utilities/requestAction.js

42 lines
872 B

import $ from 'jquery';
import _ from 'lodash';
import createAjaxRequest from './createAjaxRequest';
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)}`;
}
return createAjaxRequest(ajaxOptions).request;
}
export default requestAction;