X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/0aea0fe49faebf703226d662012aae71904a5a30..59cc1b248e39a17bbf46449add178d957b167b9a:/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 212f2f4d03..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; } @@ -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 ); }