Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function uploadDataset() {
if (datasetPreferences.upload.name.length === 0) return;
if (datasetPreferences.upload.files.length === 0) return;
let body = new FormData();
body.append('metadata', JSON.stringify(Object.assign({}, datasetPreferences.upload, {files: undefined})));
datasetPreferences.upload.files.forEach(file => body.append('files', file));
// initial upload
let response = await m.request({
method: "POST",
url: "user-workspaces/upload-dataset",
body,
});
if (response.success) {
location.reload(); // Restart! Should load the new dataset
return;
} else {
// clear files list
// MS: commented this out... if it fails, shouldn't we keep the state so the user can fix it?
// datasetPreferences.upload.files = [];
}
console.log('Upload dataset response: ' + response.message);
export async function makeRequest(url, data) {
// console.log('url:', url);
// console.log('POST:', data);
let res;
try {
res = await m.request(url, {method: 'POST', data: data});
// console.log('response:', res);
// oftentimes rook fails with a {warning: '...'} JSON
if (res && 'warning' in res && Object.keys(res).length === 1) {
// alertWarn('Warning: ' + res.warning);
solverD3M.end_ta3_search(false, res.warning);
}
} catch(err) {
solverD3M.end_ta3_search(false, err);
cdb(err);
alertError(`Error: call to ${url} failed`);
}
/*
// call end_ta3_search if status != OK
// status may be in different places for different calls though, and this is not worth doing at the moment
let myreg = /d3m-service/g;
load: function(patient_pkey, doctor_pkey) {
return m.request({
method: "GET",
url: "/api/sec_pulse/" + patient_pkey + "/" + doctor_pkey,
// withCredentials: true,
})
.then(function(result) {
PatientDetails.error = ""
PatientDetails.pulseList = result.data
})
.catch(function(e) {
console.log(e)
PatientDetails.error = e.message
PatientDetails.pulseList = []
})
},
controller: function() {
var self = this;
self.banner = m.prop();
self.bannerLoaded = m.prop(false);
// Load banner
var domain = lodashGet(window, 'contextVars.apiV2Domain', '');
var bannerUrl = domain + '_/banners/current/';
var bannerPromise = m.request({method: 'GET', url: bannerUrl}, background=true);
bannerPromise.then(function(result){
self.banner(result.data);
self.bannerLoaded(true);
}, function(error) {
Raven.captureMessage('Error in request to ' + bannerUrl, {
extra: {error: error}
});
});
},
view : function(ctrl) {
'type': currentTab
};
function updateActorListing(data) {
if ('source' in data) app.subsetMetadata['Actor']['<source>'] = data.source || [];
if ('target' in data) app.subsetMetadata['Actor'][''] = data.target || [];
scrolledPageSize = defaultPageSize;
loadDataHelper(currentTab, "full", defaultPageSize);
waitForQuery--;
m.redraw();
}
let failedUpdateActorListing = () => waitForQuery--;
waitForQuery++;
m.redraw();
m.request({
url: app.subsetURL,
data: query,
method: 'POST'
}).then(updateActorListing).catch(failedUpdateActorListing);
}
private static makeRequest(url: string,
method: string,
apiVersion?: ApiVersion,
options?: Partial): Promise> {
const headers = this.buildHeaders(method, apiVersion, options);
let payload: any;
if (options && options.payload) {
payload = options.payload;
}
return m.request({
url,
method,
headers,
body: payload,
extract: _.identity,
deserialize: _.identity,
config: (xhr) => {
if (options && options.xhrHandle) {
options.xhrHandle(xhr);
}
}
}).then((xhr: XMLHttpRequest) => {
return ApiResult.from(xhr);
}).catch((reason) => {
const unknownError = "There was an unknown error performing the operation.";
try {
const createReward = (projectId, rewardData) => m.request({
method: 'POST',
url: `/projects/${projectId}/rewards.json`,
data: {
reward: rewardData
},
config: h.setCsrfToken
});
private static makeRequest(url: string,
method: string,
apiVersion?: ApiVersion,
options?: Partial): Promise> {
const headers = this.buildHeaders(method, apiVersion, options);
let payload: any;
if (options && options.payload) {
payload = options.payload;
}
return m.request({
url,
method,
headers,
body: payload,
extract: _.identity,
deserialize: _.identity,
config: (xhr) => {
if (options && options.xhrHandle) {
options.xhrHandle(xhr);
}
}
}).then((xhr: XMLHttpRequest) => {
return ApiResult.from(xhr);
}).catch((reason) => {
const unknownError = "There was an unknown error performing the operation.";
try {
const getData = pageNum =>
m.request({
method: "GET",
url: "data/paging/page-" + pageNum + ".json"
});
const updateContributionData = (contribution_id, project_id) => {
const contributionData = {
anonymous: fields.anonymous(),
payer_document: fields.ownerDocument(),
payer_name: fields.completeName(),
address_attributes: fields.address().getFields(),
card_owner_document: creditCardFields.cardOwnerDocument()
};
return m.request({
method: 'PUT',
url: `/projects/${project_id}/contributions/${contribution_id}.json`,
data: { contribution: contributionData },
config: setCsrfToken
})
.catch((error) => {
h.captureException(error);
throw error;
});
};