mirror of
https://github.com/apricote/Listory.git
synced 2026-01-13 21:21:02 +00:00
fix(frontend): fix encoding of queryparameters in api calls
We had a bug where the "+" before the timezone in ISO8601 strings was being parsed as " " in the server because it was not properly encoded. By using URLSearchParams to create our querystring we should be fine.
This commit is contained in:
parent
e2b927fca4
commit
40ce26eadd
2 changed files with 24 additions and 6 deletions
|
|
@ -5,6 +5,7 @@ import { ListenReportOptions } from "./entities/listen-report-options";
|
|||
import { Pagination } from "./entities/pagination";
|
||||
import { PaginationOptions } from "./entities/pagination-options";
|
||||
import { User } from "./entities/user";
|
||||
import { qs } from "../util/queryString";
|
||||
|
||||
export class UnauthenticatedError extends Error {}
|
||||
|
||||
|
|
@ -50,9 +51,12 @@ export const getRecentListens = async (
|
|||
): Promise<Pagination<Listen>> => {
|
||||
const { page, limit } = options;
|
||||
|
||||
const res = await fetch(`/api/v1/listens?page=${page}&limit=${limit}`, {
|
||||
headers: getDefaultHeaders(),
|
||||
});
|
||||
const res = await fetch(
|
||||
`/api/v1/listens?${qs({ page: page.toString(), limit: limit.toString() })}`,
|
||||
{
|
||||
headers: getDefaultHeaders(),
|
||||
}
|
||||
);
|
||||
|
||||
switch (res.status) {
|
||||
case 200: {
|
||||
|
|
@ -77,9 +81,11 @@ export const getListensReport = async (
|
|||
const { timeFrame, timeStart, timeEnd } = options;
|
||||
|
||||
const res = await fetch(
|
||||
`/api/v1/reports/listens?timeFrame=${timeFrame}&timeStart=${formatISO(
|
||||
timeStart
|
||||
)}&timeEnd=${formatISO(timeEnd)}`,
|
||||
`/api/v1/reports/listens?${qs({
|
||||
timeFrame,
|
||||
timeStart: formatISO(timeStart),
|
||||
timeEnd: formatISO(timeEnd),
|
||||
})}`,
|
||||
{
|
||||
headers: getDefaultHeaders(),
|
||||
}
|
||||
|
|
|
|||
12
frontend/src/util/queryString.ts
Normal file
12
frontend/src/util/queryString.ts
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
interface QueryParameters {
|
||||
[x: string]: string;
|
||||
}
|
||||
export const qs = (parameters: QueryParameters): string => {
|
||||
const queryParams = new URLSearchParams();
|
||||
|
||||
Object.entries(parameters).forEach(([key, value]) =>
|
||||
queryParams.append(key, value)
|
||||
);
|
||||
|
||||
return queryParams.toString();
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue