mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-24 02:02:36 -04:00
Cleanup duplicated slash handling
This commit is contained in:
parent
e0935d7faa
commit
0124275d8c
@ -33,6 +33,11 @@ import { type Page, Paged } from "./page";
|
||||
|
||||
export let lastUsedUrl: string = null!;
|
||||
|
||||
const cleanSlash = (str: string | null) => {
|
||||
if (!str) return null;
|
||||
return str.replace(/^\/|\/$/g, "");
|
||||
};
|
||||
|
||||
export const queryFn = async <Parser extends z.ZodTypeAny>(
|
||||
context: {
|
||||
apiUrl?: string | null;
|
||||
@ -54,17 +59,16 @@ export const queryFn = async <Parser extends z.ZodTypeAny>(
|
||||
lastUsedUrl = url!;
|
||||
|
||||
const token = iToken === undefined && context.authenticated !== false ? await getToken() : iToken;
|
||||
const path = [url]
|
||||
const path = [cleanSlash(url)]
|
||||
.concat(
|
||||
"path" in context
|
||||
? (context.path as string[])
|
||||
: "pageParam" in context && context.pageParam
|
||||
? [context.pageParam as string]
|
||||
? [cleanSlash(context.pageParam as string)]
|
||||
: (context.queryKey as string[]),
|
||||
)
|
||||
.filter((x) => x)
|
||||
.join("/")
|
||||
.replace("//", "/")
|
||||
.replace("/?", "?");
|
||||
let resp: Response;
|
||||
try {
|
||||
|
@ -48,7 +48,7 @@ const query: QueryIdentifier<ServerInfo> = {
|
||||
export const ServerUrlPage: QueryPage = () => {
|
||||
const [_apiUrl, setApiUrl] = useState("");
|
||||
const apiUrl = cleanApiUrl(_apiUrl);
|
||||
const { data, error } = useFetch({ ...query, options: { apiUrl } });
|
||||
const { data, error } = useFetch({ ...query, options: { apiUrl, authenticated: false } });
|
||||
const router = useRouter();
|
||||
const { t } = useTranslation();
|
||||
const { css } = useYoshiki();
|
||||
|
Loading…
x
Reference in New Issue
Block a user