mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-06-03 05:34:23 -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!;
|
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>(
|
export const queryFn = async <Parser extends z.ZodTypeAny>(
|
||||||
context: {
|
context: {
|
||||||
apiUrl?: string | null;
|
apiUrl?: string | null;
|
||||||
@ -54,17 +59,16 @@ export const queryFn = async <Parser extends z.ZodTypeAny>(
|
|||||||
lastUsedUrl = url!;
|
lastUsedUrl = url!;
|
||||||
|
|
||||||
const token = iToken === undefined && context.authenticated !== false ? await getToken() : iToken;
|
const token = iToken === undefined && context.authenticated !== false ? await getToken() : iToken;
|
||||||
const path = [url]
|
const path = [cleanSlash(url)]
|
||||||
.concat(
|
.concat(
|
||||||
"path" in context
|
"path" in context
|
||||||
? (context.path as string[])
|
? (context.path as string[])
|
||||||
: "pageParam" in context && context.pageParam
|
: "pageParam" in context && context.pageParam
|
||||||
? [context.pageParam as string]
|
? [cleanSlash(context.pageParam as string)]
|
||||||
: (context.queryKey as string[]),
|
: (context.queryKey as string[]),
|
||||||
)
|
)
|
||||||
.filter((x) => x)
|
.filter((x) => x)
|
||||||
.join("/")
|
.join("/")
|
||||||
.replace("//", "/")
|
|
||||||
.replace("/?", "?");
|
.replace("/?", "?");
|
||||||
let resp: Response;
|
let resp: Response;
|
||||||
try {
|
try {
|
||||||
|
@ -48,7 +48,7 @@ const query: QueryIdentifier<ServerInfo> = {
|
|||||||
export const ServerUrlPage: QueryPage = () => {
|
export const ServerUrlPage: QueryPage = () => {
|
||||||
const [_apiUrl, setApiUrl] = useState("");
|
const [_apiUrl, setApiUrl] = useState("");
|
||||||
const apiUrl = cleanApiUrl(_apiUrl);
|
const apiUrl = cleanApiUrl(_apiUrl);
|
||||||
const { data, error } = useFetch({ ...query, options: { apiUrl } });
|
const { data, error } = useFetch({ ...query, options: { apiUrl, authenticated: false } });
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { css } = useYoshiki();
|
const { css } = useYoshiki();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user