fix: upload size too large tip

This commit is contained in:
Tristan Yang
2022-12-15 19:38:21 +08:00
parent 3df055a248
commit 160e9678fe
3 changed files with 18 additions and 3 deletions
+9 -2
View File
@@ -4,6 +4,7 @@ import dayjs from "dayjs";
import { updateToken, resetAuthData } from "../slices/auth.data"; import { updateToken, resetAuthData } from "../slices/auth.data";
import BASE_URL, { tokenHeader } from "../config"; import BASE_URL, { tokenHeader } from "../config";
import { RootState } from "../store"; import { RootState } from "../store";
import { getLocalAuthData } from "../../common/utils";
const whiteList = [ const whiteList = [
"guestLogin", "guestLogin",
@@ -43,8 +44,9 @@ const baseQueryWithTokenCheck = async (args, api, extraOptions) => {
if (waitingForRenew) { if (waitingForRenew) {
await waitingForRenew; await waitingForRenew;
} }
// 先检查token是否过期,过期则renew // 先检查token是否过期,过期则renew [从localstorage取]
const { token, refreshToken, expireTime = +new Date() } = api.getState().authData; const { token, refreshToken, expireTime } = getLocalAuthData();
let result = null; let result = null;
// console.log("base check", whiteList.includes(api.endpoint), api.endpoint); // console.log("base check", whiteList.includes(api.endpoint), api.endpoint);
if (!whiteList.includes(api.endpoint) && dayjs().isAfter(new Date(expireTime - 20 * 1000))) { if (!whiteList.includes(api.endpoint) && dayjs().isAfter(new Date(expireTime - 20 * 1000))) {
@@ -102,6 +104,11 @@ const baseQueryWithTokenCheck = async (args, api, extraOptions) => {
} }
} }
break; break;
case 413:
{
toast.error("File size too large");
}
break;
case 451: case 451:
{ {
// 证书错误 // 证书错误
+1
View File
@@ -90,6 +90,7 @@ const useUploadFile = (props?: IProps) => {
sliceUploadedCountRef.current++; sliceUploadedCountRef.current++;
} catch (error) { } catch (error) {
console.error("upload file error", error); console.error("upload file error", error);
canceledRef.current = true;
return; return;
} }
} }
+8 -1
View File
@@ -1,4 +1,4 @@
import BASE_URL, { FILE_IMAGE_SIZE, ContentTypes } from "../app/config"; import BASE_URL, { FILE_IMAGE_SIZE, ContentTypes, KEY_TOKEN, KEY_REFRESH_TOKEN, KEY_EXPIRE } from "../app/config";
import IconPdf from "../assets/icons/file.pdf.svg"; import IconPdf from "../assets/icons/file.pdf.svg";
import IconAudio from "../assets/icons/file.audio.svg"; import IconAudio from "../assets/icons/file.audio.svg";
import IconVideo from "../assets/icons/file.video.svg"; import IconVideo from "../assets/icons/file.video.svg";
@@ -8,6 +8,13 @@ import IconCode from "../assets/icons/file.code.svg";
import IconImage from "../assets/icons/file.image.svg"; import IconImage from "../assets/icons/file.image.svg";
import { Archive, ArchiveMessage } from "../types/resource"; import { Archive, ArchiveMessage } from "../types/resource";
export const getLocalAuthData = () => {
return {
token: localStorage.getItem(KEY_TOKEN) || "",
refreshToken: localStorage.getItem(KEY_REFRESH_TOKEN) || "",
expireTime: Number(localStorage.getItem(KEY_EXPIRE) || +new Date())
};
};
export const isImage = (file_type = "", size = 0) => { export const isImage = (file_type = "", size = 0) => {
return file_type.startsWith("image") && size <= FILE_IMAGE_SIZE; return file_type.startsWith("image") && size <= FILE_IMAGE_SIZE;
}; };