X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/9b29a65b9f9f02b338445c12b5d08b292f797c1c..f4d717705f9824add63e7d0730f486f58a93cf83:/src/services/common-service/common-service.ts diff --git a/src/services/common-service/common-service.ts b/src/services/common-service/common-service.ts index 07ff398a4a..d811782127 100644 --- a/src/services/common-service/common-service.ts +++ b/src/services/common-service/common-service.ts @@ -6,6 +6,7 @@ import * as _ from "lodash"; import { AxiosInstance, AxiosPromise } from "axios"; import * as uuid from "uuid/v4"; import { ApiActions } from "~/services/api/api-actions"; +import * as QueryString from "query-string"; interface Errors { errors: string[]; @@ -38,7 +39,7 @@ export class CommonService { constructor(serverApi: AxiosInstance, resourceType: string, actions: ApiActions) { this.serverApi = serverApi; - this.resourceType = '/' + resourceType + '/'; + this.resourceType = '/' + resourceType; this.actions = actions; } @@ -54,7 +55,7 @@ export class CommonService { .map(key => [key, mapFn(key)]) .reduce((newValue, [key, newKey]) => ({ ...newValue, - [newKey]: CommonService.mapKeys(mapFn)(value[key]) + [newKey]: (key === 'items') ? CommonService.mapKeys(mapFn)(value[key]) : value[key] }), {}); case _.isArray(value): return value.map(CommonService.mapKeys(mapFn)); @@ -93,7 +94,7 @@ export class CommonService { delete(uuid: string): Promise { return CommonService.defaultResponse( this.serverApi - .delete(this.resourceType + uuid), + .delete(this.resourceType + '/' + uuid), this.actions ); } @@ -101,7 +102,7 @@ export class CommonService { get(uuid: string) { return CommonService.defaultResponse( this.serverApi - .get(this.resourceType + uuid), + .get(this.resourceType + '/' + uuid), this.actions ); } @@ -113,19 +114,36 @@ export class CommonService { filters: filters ? `[${filters}]` : undefined, order: order ? order : undefined }; - return CommonService.defaultResponse( - this.serverApi - .get(this.resourceType, { - params: CommonService.mapKeys(_.snakeCase)(params) + + if (QueryString.stringify(params).length <= 1500) { + return CommonService.defaultResponse( + this.serverApi.get(this.resourceType, { params }), + this.actions + ); + } else { + // Using the POST special case to avoid URI length 414 errors. + const formData = new FormData(); + formData.append("_method", "GET"); + Object.keys(params).map(key => { + if (params[key] !== undefined) { + formData.append(key, params[key]); + } + }); + return CommonService.defaultResponse( + this.serverApi.post(this.resourceType, formData, { + params: { + _method: 'GET' + } }), - this.actions - ); + this.actions + ); + } } update(uuid: string, data: Partial) { return CommonService.defaultResponse( this.serverApi - .put(this.resourceType + uuid, data && CommonService.mapKeys(_.snakeCase)(data)), + .put(this.resourceType + '/' + uuid, data && CommonService.mapKeys(_.snakeCase)(data)), this.actions ); }