diff --git a/packages/core/services/FileService/HttpFileService/index.ts b/packages/core/services/FileService/HttpFileService/index.ts index 2b5f81ad..e20a4bb7 100644 --- a/packages/core/services/FileService/HttpFileService/index.ts +++ b/packages/core/services/FileService/HttpFileService/index.ts @@ -20,7 +20,7 @@ interface Config extends ConnectionConfig { * Service responsible for fetching file related metadata. */ export default class HttpFileService extends HttpServiceBase implements FileService { - private static readonly CACHE_ENDPOINT_VERSION = "3.0"; + private static readonly CACHE_ENDPOINT_VERSION = "v3.0"; private static readonly ENDPOINT_VERSION = "3.0"; public static readonly BASE_FILES_URL = `file-explorer-service/${HttpFileService.ENDPOINT_VERSION}/files`; public static readonly BASE_FILE_COUNT_URL = `${HttpFileService.BASE_FILES_URL}/count`; @@ -138,13 +138,16 @@ export default class HttpFileService extends HttpServiceBase implements FileServ ): Promise<{ cacheFileStatuses: { [fileId: string]: string } }> { const requestUrl = `${this.aicsLoadBalancerBaseUrl}/${HttpFileService.BASE_FILE_CACHE_URL}${this.pathSuffix}`; const requestBody = JSON.stringify({ fileIds }); + const headers = { + "Content-Type": "application/json", + "X-User-Id": "brian.whitney", // TODO: Make this not my user + }; try { - const cacheStatuses = await this.rawPost<{ + const cacheStatuses = await this.rawPut<{ cacheFileStatuses: { [fileId: string]: string }; - }>(requestUrl, requestBody); - - return cacheStatuses; // Return the entire response object + }>(requestUrl, requestBody, headers); + return cacheStatuses; } catch (error) { console.error("Failed to cache files:", error); throw new Error("Unable to complete the caching request."); diff --git a/packages/core/services/HttpServiceBase/index.ts b/packages/core/services/HttpServiceBase/index.ts index 4d10b3c6..3516272f 100644 --- a/packages/core/services/HttpServiceBase/index.ts +++ b/packages/core/services/HttpServiceBase/index.ts @@ -195,6 +195,32 @@ export default class HttpServiceBase { return response.data; } + public async rawPut( + url: string, + body: string, + headers: { [key: string]: string } = {} + ): Promise { + const encodedUrl = HttpServiceBase.encodeURI(url); + const config = { headers: { ...headers } }; + + let response; + try { + // Retry policy wrapped around axios PUT + response = await retry.execute(() => this.httpClient.put(encodedUrl, body, config)); + } catch (err) { + if (axios.isAxiosError(err) && err?.response?.data?.message) { + throw new Error(JSON.stringify(err.response.data.message)); + } + throw err; + } + + if (response.status >= 400 || response.data === undefined) { + throw new Error(`Request for ${encodedUrl} failed`); + } + + return response.data; + } + public async post(url: string, body: string): Promise> { const encodedUrl = HttpServiceBase.encodeURI(url); const config = { headers: { "Content-Type": "application/json" } };