Fix api path slash cleanup

This commit is contained in:
Zoe Roux 2024-05-19 21:47:09 +02:00
parent da13535e3e
commit 9048927c89
No known key found for this signature in database

View File

@ -33,8 +33,9 @@ import { type Page, Paged } from "./page";
export let lastUsedUrl: string = null!;
const cleanSlash = (str: string | null) => {
const cleanSlash = (str: string | null, keepFirst = false) => {
if (!str) return null;
if (keepFirst) return str.replace(/\/$/g, "");
return str.replace(/^\/|\/$/g, "");
};
@ -59,7 +60,7 @@ export const queryFn = async <Parser extends z.ZodTypeAny>(
lastUsedUrl = url!;
const token = iToken === undefined && context.authenticated !== false ? await getToken() : iToken;
const path = [cleanSlash(url)]
const path = [cleanSlash(url, true)]
.concat(
"path" in context
? (context.path as string[])