mirror of
https://github.com/logto-io/logto.git
synced 2025-01-06 20:40:08 -05:00
refactor(console): increase custom ui assets upload timeout to 5 mins (#6319)
refactor(console): increase custom ui assets upload timeout to 5mins
This commit is contained in:
parent
6477c6deef
commit
e76d4e6e53
3 changed files with 15 additions and 2 deletions
|
@ -13,6 +13,8 @@ import FileIcon from '../FileIcon';
|
||||||
|
|
||||||
import styles from './index.module.scss';
|
import styles from './index.module.scss';
|
||||||
|
|
||||||
|
const requestTimeout = 300_000; // 5 minutes
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
// eslint-disable-next-line react/boolean-prop-naming
|
// eslint-disable-next-line react/boolean-prop-naming
|
||||||
readonly disabled?: boolean;
|
readonly disabled?: boolean;
|
||||||
|
@ -51,6 +53,7 @@ function CustomUiAssetsUploader({ disabled, value, onChange }: Props) {
|
||||||
if (showUploader) {
|
if (showUploader) {
|
||||||
return (
|
return (
|
||||||
<FileUploader<{ customUiAssetId: string }>
|
<FileUploader<{ customUiAssetId: string }>
|
||||||
|
defaultApiInstanceTimeout={requestTimeout}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
allowedMimeTypes={allowedMimeTypes}
|
allowedMimeTypes={allowedMimeTypes}
|
||||||
maxSize={maxUploadFileSize}
|
maxSize={maxUploadFileSize}
|
||||||
|
|
|
@ -18,6 +18,11 @@ export type Props<T extends Record<string, unknown> = UserAssets> = {
|
||||||
// eslint-disable-next-line react/boolean-prop-naming
|
// eslint-disable-next-line react/boolean-prop-naming
|
||||||
readonly disabled?: boolean;
|
readonly disabled?: boolean;
|
||||||
readonly maxSize: number; // In bytes
|
readonly maxSize: number; // In bytes
|
||||||
|
/**
|
||||||
|
* The timeout for the default api instance, in milliseconds.
|
||||||
|
* Will not be applied if a custom API instance is provided.
|
||||||
|
*/
|
||||||
|
readonly defaultApiInstanceTimeout?: number;
|
||||||
readonly allowedMimeTypes: AllowedUploadMimeType[];
|
readonly allowedMimeTypes: AllowedUploadMimeType[];
|
||||||
readonly actionDescription?: string;
|
readonly actionDescription?: string;
|
||||||
readonly onCompleted: (response: T) => void;
|
readonly onCompleted: (response: T) => void;
|
||||||
|
@ -25,6 +30,7 @@ export type Props<T extends Record<string, unknown> = UserAssets> = {
|
||||||
readonly className?: string;
|
readonly className?: string;
|
||||||
/**
|
/**
|
||||||
* Specify which API instance to use for the upload request. For example, you can use admin tenant API instead.
|
* Specify which API instance to use for the upload request. For example, you can use admin tenant API instead.
|
||||||
|
* The `timeout` prop will not be applied to this instance.
|
||||||
* Defaults to the return value of `useApi()`.
|
* Defaults to the return value of `useApi()`.
|
||||||
*/
|
*/
|
||||||
readonly apiInstance?: KyInstance;
|
readonly apiInstance?: KyInstance;
|
||||||
|
@ -37,6 +43,7 @@ export type Props<T extends Record<string, unknown> = UserAssets> = {
|
||||||
function FileUploader<T extends Record<string, unknown> = UserAssets>({
|
function FileUploader<T extends Record<string, unknown> = UserAssets>({
|
||||||
disabled,
|
disabled,
|
||||||
maxSize,
|
maxSize,
|
||||||
|
defaultApiInstanceTimeout,
|
||||||
allowedMimeTypes,
|
allowedMimeTypes,
|
||||||
actionDescription,
|
actionDescription,
|
||||||
onCompleted,
|
onCompleted,
|
||||||
|
@ -57,7 +64,7 @@ function FileUploader<T extends Record<string, unknown> = UserAssets>({
|
||||||
};
|
};
|
||||||
}, [onUploadErrorChange, uploadError]);
|
}, [onUploadErrorChange, uploadError]);
|
||||||
|
|
||||||
const api = useApi();
|
const api = useApi({ timeout: defaultApiInstanceTimeout });
|
||||||
|
|
||||||
const onDrop = useCallback(
|
const onDrop = useCallback(
|
||||||
async (acceptedFiles: File[] = [], fileRejection: FileRejection[] = []) => {
|
async (acceptedFiles: File[] = [], fileRejection: FileRejection[] = []) => {
|
||||||
|
|
|
@ -40,6 +40,7 @@ export type StaticApiProps = {
|
||||||
prefixUrl?: URL;
|
prefixUrl?: URL;
|
||||||
hideErrorToast?: boolean | LogtoErrorCode[];
|
hideErrorToast?: boolean | LogtoErrorCode[];
|
||||||
resourceIndicator: string;
|
resourceIndicator: string;
|
||||||
|
timeout?: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
const useGlobalRequestErrorHandler = (toastDisabledErrorCodes?: LogtoErrorCode[]) => {
|
const useGlobalRequestErrorHandler = (toastDisabledErrorCodes?: LogtoErrorCode[]) => {
|
||||||
|
@ -110,6 +111,7 @@ export const useStaticApi = ({
|
||||||
prefixUrl,
|
prefixUrl,
|
||||||
hideErrorToast,
|
hideErrorToast,
|
||||||
resourceIndicator,
|
resourceIndicator,
|
||||||
|
timeout = requestTimeout,
|
||||||
}: StaticApiProps): KyInstance => {
|
}: StaticApiProps): KyInstance => {
|
||||||
const { isAuthenticated, getAccessToken, getOrganizationToken } = useLogto();
|
const { isAuthenticated, getAccessToken, getOrganizationToken } = useLogto();
|
||||||
const { i18n } = useTranslation(undefined, { keyPrefix: 'admin_console' });
|
const { i18n } = useTranslation(undefined, { keyPrefix: 'admin_console' });
|
||||||
|
@ -125,7 +127,7 @@ export const useStaticApi = ({
|
||||||
() =>
|
() =>
|
||||||
ky.create({
|
ky.create({
|
||||||
prefixUrl,
|
prefixUrl,
|
||||||
timeout: requestTimeout,
|
timeout,
|
||||||
hooks: {
|
hooks: {
|
||||||
beforeError: conditionalArray(
|
beforeError: conditionalArray(
|
||||||
!disableGlobalErrorHandling &&
|
!disableGlobalErrorHandling &&
|
||||||
|
@ -156,6 +158,7 @@ export const useStaticApi = ({
|
||||||
getOrganizationToken,
|
getOrganizationToken,
|
||||||
getAccessToken,
|
getAccessToken,
|
||||||
i18n.language,
|
i18n.language,
|
||||||
|
timeout,
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue