X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/282b04b762cf6366209074333bfd623e3cba58c5..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 b301a72755..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[]; @@ -23,6 +24,7 @@ export interface ListArguments { } export interface ListResults { + clusterId?: string; kind: string; offset: number; limit: number; @@ -37,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; } @@ -53,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)); @@ -92,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 ); } @@ -100,7 +102,7 @@ export class CommonService { get(uuid: string) { return CommonService.defaultResponse( this.serverApi - .get(this.resourceType + uuid), + .get(this.resourceType + '/' + uuid), this.actions ); } @@ -112,20 +114,37 @@ 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 ); } -} \ No newline at end of file +}