38 lines
1.1 KiB
TypeScript
38 lines
1.1 KiB
TypeScript
/**
|
|
* Copyright (c) 2023-present Plane Software, Inc. and contributors
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
* See the LICENSE file for details.
|
|
*/
|
|
|
|
// plane imports
|
|
import { MAX_FILE_SIZE } from "@plane/constants";
|
|
// hooks
|
|
import { useInstance } from "@/hooks/store/use-instance";
|
|
import { useWorkspace } from "@/hooks/store/use-workspace";
|
|
|
|
type TReturnProps = {
|
|
maxFileSize: number;
|
|
fileSizeLimitEnabled: boolean;
|
|
};
|
|
|
|
export const useFileSize = (): TReturnProps => {
|
|
// store hooks
|
|
const { config } = useInstance();
|
|
const { currentWorkspace } = useWorkspace();
|
|
|
|
const workspaceLimitEnabled = currentWorkspace?.storage_file_size_limit_enabled ?? true;
|
|
const workspaceLimit = currentWorkspace?.storage_file_size_limit;
|
|
const fallbackLimit = config?.file_size_limit ?? MAX_FILE_SIZE;
|
|
const maxFileSize =
|
|
workspaceLimitEnabled && workspaceLimit && workspaceLimit > 0
|
|
? workspaceLimit
|
|
: workspaceLimitEnabled
|
|
? fallbackLimit
|
|
: Number.MAX_SAFE_INTEGER;
|
|
|
|
return {
|
|
maxFileSize,
|
|
fileSizeLimitEnabled: workspaceLimitEnabled,
|
|
};
|
|
};
|