feat: pre check file with HEAD method

This commit is contained in:
Tristan Yang
2023-05-04 07:01:34 +08:00
parent 3826aed3c9
commit 55d851541f
3 changed files with 52 additions and 15 deletions
+6 -3
View File
@@ -27,9 +27,11 @@ const whiteList = [
"createAdmin",
"getBotRelatedChannels",
"sendMessageByBot",
"getAgoraVoicingList"
"getAgoraVoicingList",
"preCheckFileFromUrl"
];
const whiteList401 = ["getAgoraVoicingList"];
const errorWhiteList = ["preCheckFileFromUrl"];
const baseQuery = fetchBaseQuery({
baseUrl: BASE_URL,
prepareHeaders: (headers, { getState, endpoint }) => {
@@ -78,6 +80,7 @@ const baseQueryWithTokenCheck = async (args: any, api: any, extraOptions: any) =
}
if (result?.error) {
console.error("api error", result.error, api.endpoint);
if (errorWhiteList.includes(api.endpoint)) return result;
switch (result.error.originalStatus || result.error.status) {
case "FETCH_ERROR":
{
@@ -95,7 +98,7 @@ const baseQueryWithTokenCheck = async (args: any, api: any, extraOptions: any) =
if (api.endpoint !== "login") {
api.dispatch(resetAuthData());
location.href = "/#/login";
toast.error("API Not Authenticated");
// toast.error("API Not Authenticated");
}
}
break;
@@ -104,7 +107,7 @@ const baseQueryWithTokenCheck = async (args: any, api: any, extraOptions: any) =
break;
case 404:
{
const whiteList404 = ["login", "getArchiveMessage"];
const whiteList404 = ["login", "getArchiveMessage", "preCheckFileFromUrl"];
if (!whiteList404.includes(api.endpoint)) {
toast.error("Request Not Found");
}
+9 -1
View File
@@ -237,11 +237,19 @@ export const messageApi = createApi({
// todo
}
}
})
}),
preCheckFileFromUrl: builder.query<void, string>({
query: (url) => ({
url,
method: "HEAD",
responseHandler: "text"
})
}),
})
});
export const {
useLazyPreCheckFileFromUrlQuery,
useLazyRemoveFavoriteQuery,
useUnpinMessageMutation,
useLazyGetFavoritesQuery,