From cd50689a04d402d661fde6531ab6a9056fe0ed84 Mon Sep 17 00:00:00 2001 From: Wilson Wong Date: Wed, 6 Sep 2023 11:05:38 -0700 Subject: [PATCH] SC-3335, bug: stop loading files into browser memory before upload --- frontend/src/services/objectService.ts | 57 ++------------------------ 1 file changed, 3 insertions(+), 54 deletions(-) diff --git a/frontend/src/services/objectService.ts b/frontend/src/services/objectService.ts index 967a884d..69d9dae3 100644 --- a/frontend/src/services/objectService.ts +++ b/frontend/src/services/objectService.ts @@ -1,6 +1,5 @@ import { comsAxios } from './interceptors'; import { setDispositionHeader } from '@/utils/utils'; -import ConfigService from './configService'; import type { AxiosRequestConfig } from 'axios'; import type { GetMetadataOptions, GetObjectTaggingOptions, MetadataPair, SearchObjectsOptions, Tag } from '@/types'; @@ -55,8 +54,7 @@ export default { ); } - const fd = await object.arrayBuffer(); - return comsAxios(axiosOptions).put(PATH, fd, config); + return comsAxios(axiosOptions).put(PATH, object, config); }, /** @@ -228,55 +226,7 @@ export default { searchObjects(params: SearchObjectsOptions = {}, headers: any = {},) { // remove objectId array if its first element is undefined if (params.objectId && params.objectId[0] === undefined) delete params.objectId; - - if (params.objectId) { - /** - * split calls to COMS if query params (eg objectId's) - * will cause url length to excede 2000 characters - * see: https://stackoverflow.com/questions/417142/what-is-the-maximum-length-of-a-url-in-different-browsers - * - * TODO: consider creating a utils function - * eg: `divideParam(params, attr)` - * ... - * return Promise.all(divideParam(params, objectId) - * .map(zparam => comsAxios().get(PATH, {params: zparam, headers: headers}); - */ - let urlLimit = 2000; - - const baseUrl = new URL(`${new ConfigService().getConfig().coms.apiPath}${PATH}`).toString(); - urlLimit -= baseUrl.length; // subtract baseUrl length - if (params.deleteMarker) urlLimit -= 19; // subtract `deleteMarker=false` - if (params.latest) urlLimit -= 13; // subtract `latest=false` - if (params.bucketId) urlLimit -= 48; // subtract a single bucketId `bucketId[]=` - // if tagset parameters passed - if (params.tagset) { - type TagsetObjectEntries = { - [K in keyof Tag]: [K, Tag[K]]; - }[keyof Tag][]; - for (const [key, value] of Object.entries(params.tagset) as TagsetObjectEntries) { - urlLimit -= (10 + key.length + value.length); - } - } - - // number of allowed objectId's in each group - 48 chars for each objectId (&objectId[]=) - const space = urlLimit; - const groupSize = Math.floor(space / 48); - - // loop through each group and push COMS result to `groups` array - const iterations = Math.ceil(params.objectId.length / groupSize); - const groups = []; - for (let i = 0; i < iterations; i++) { - const ids = params.objectId.slice(i * groupSize, ((i * groupSize) + groupSize)); - groups.push(comsAxios().get(PATH, { params: { ...params, objectId: ids }, headers: headers })); - } - // await for all calls to COMS to resolve and map results into one array - return Promise.all(groups) - .then((results) => ({ data: results.flatMap(result => result.data) })); - } - // else just call COMS once - else { - return comsAxios().get(PATH, { params: params, headers: headers }); - } + return comsAxios().get(PATH, { params: params, headers: headers }); }, /** @@ -354,7 +304,6 @@ export default { ); } - const fd = await object.arrayBuffer(); - return comsAxios(axiosOptions).put(`${PATH}/${objectId}`, fd, config); + return comsAxios(axiosOptions).put(`${PATH}/${objectId}`, object, config); }, };