Skip to content

Commit

Permalink
Encode query parameters in H5GroveProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
loichuder committed Aug 5, 2021
1 parent 6ea9269 commit 9bd0489
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 4 additions & 7 deletions src/h5web/providers/h5grove/h5grove-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
ProviderError,
} from '../models';
import { ProviderApi } from '../api';
import { isDatasetResponse, isGroupResponse } from './utils';
import { encodeQueryParams, isDatasetResponse, isGroupResponse } from './utils';
import type {
H5GroveAttrValuesResponse,
H5GroveDataResponse,
Expand Down Expand Up @@ -50,7 +50,7 @@ export class H5GroveApi extends ProviderApi {
const { data } = await handleAxiosError(
() =>
this.client.get<H5GroveEntityResponse>(
`/meta/?file=${this.filepath}&path=${path}`
`/meta/?${encodeQueryParams({ file: this.filepath, path })}`
),
404,
ProviderError.NotFound
Expand All @@ -69,7 +69,7 @@ export class H5GroveApi extends ProviderApi {
}

const { data } = await this.client.get<H5GroveAttrValuesResponse>(
`/attr/?file=${this.filepath}&path=${path}`
`/attr/?${encodeQueryParams({ file: this.filepath, path })}`
);

this.attrValuesCache.set(path, data);
Expand All @@ -79,11 +79,8 @@ export class H5GroveApi extends ProviderApi {
private async fetchData(
params: ValueRequestParams
): Promise<H5GroveDataResponse> {
const { path, selection = '' } = params;
const { data } = await this.cancellableFetchValue<H5GroveDataResponse>(
`/data/?file=${this.filepath}&path=${path}${
selection && `&selection=${selection}`
}`,
`/data/?${encodeQueryParams({ file: this.filepath, ...params })}`,
params
);
return data;
Expand Down
4 changes: 4 additions & 0 deletions src/h5web/providers/h5grove/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@ export function isDatasetResponse(
): response is H5GroveDatasetReponse {
return response.type === EntityKind.Dataset;
}

export function encodeQueryParams(params: Record<string, string>) {
return new URLSearchParams(params).toString();
}

0 comments on commit 9bd0489

Please sign in to comment.