From 0c91bb6c4442ea13acf31e9a3ef60b3ee9abad40 Mon Sep 17 00:00:00 2001 From: Sean Thompson <80723794+iSCJT@users.noreply.github.com> Date: Tue, 29 Oct 2024 16:04:18 +0000 Subject: [PATCH] feat: add 300mb file upload limit for admins --- src/common/Form/FileInput.field.tsx | 5 ++- src/common/Form/FileInput/FileInput.tsx | 9 ++++- src/common/Form/FileInput/UppyConfigAdmin.ts | 26 +++++++++++++ .../Content/Common/HowtoFieldFileUpload.tsx | 37 ++++++++++++++++--- .../CreateResearch/Form/FilesFields.tsx | 33 +++++++++++++++-- 5 files changed, 98 insertions(+), 12 deletions(-) create mode 100644 src/common/Form/FileInput/UppyConfigAdmin.ts diff --git a/src/common/Form/FileInput.field.tsx b/src/common/Form/FileInput.field.tsx index cefbf6a12e..8304cc7f24 100644 --- a/src/common/Form/FileInput.field.tsx +++ b/src/common/Form/FileInput.field.tsx @@ -2,7 +2,10 @@ import { FileInput } from './FileInput/FileInput' import type { FieldProps } from './types' -export const FileInputField = ({ input, ...rest }: FieldProps) => ( +export const FileInputField = ({ + input, + ...rest +}: FieldProps & { admin: boolean }) => ( { diff --git a/src/common/Form/FileInput/FileInput.tsx b/src/common/Form/FileInput/FileInput.tsx index c05da4cac8..592b3d4be9 100644 --- a/src/common/Form/FileInput/FileInput.tsx +++ b/src/common/Form/FileInput/FileInput.tsx @@ -6,6 +6,7 @@ import { Button, DownloadStaticFile } from 'oa-components' import { Flex } from 'theme-ui' import { UPPY_CONFIG } from './UppyConfig' +import { UPPY_CONFIG_ADMIN } from './UppyConfigAdmin' import type { UppyFile } from '@uppy/core' @@ -18,14 +19,20 @@ interface IUppyFiles { interface IProps { onFilesChange?: (files: (Blob | File)[]) => void 'data-cy'?: string + admin: boolean } interface IState { open: boolean } export const FileInput = (props: IProps) => { const [state, setState] = useState({ open: false }) + const uploadConfig = props.admin ? UPPY_CONFIG_ADMIN : UPPY_CONFIG const [uppy] = useState( - () => new Uppy({ ...UPPY_CONFIG, onBeforeUpload: () => uploadTriggered() }), + () => + new Uppy({ + ...uploadConfig, + onBeforeUpload: () => uploadTriggered(), + }), ) useEffect(() => { diff --git a/src/common/Form/FileInput/UppyConfigAdmin.ts b/src/common/Form/FileInput/UppyConfigAdmin.ts new file mode 100644 index 0000000000..bab248008f --- /dev/null +++ b/src/common/Form/FileInput/UppyConfigAdmin.ts @@ -0,0 +1,26 @@ +import type { UppyOptions } from '@uppy/core' + +export const UPPY_CONFIG_ADMIN: Partial = { + restrictions: { + // max upload file size in bytes (i.e. 300 x 1048576 => 300 MB) + maxFileSize: 300 * 1048576, + maxNumberOfFiles: 5, + minNumberOfFiles: null, + allowedFileTypes: null, + }, + locale: { + strings: { + youCanOnlyUploadX: { + 0: 'You can only upload %{smart_count} file', + 1: 'You can only upload %{smart_count} files', + }, + youHaveToAtLeastSelectX: { + 0: 'You have to select at least %{smart_count} file', + 1: 'You have to select at least %{smart_count} files', + }, + exceedsSize: 'This file exceeds maximum allowed size of %{size}', + youCanOnlyUploadFileTypes: 'You can only upload: %{types}', + companionError: 'Connection with Companion failed', + }, + }, +} diff --git a/src/pages/Howto/Content/Common/HowtoFieldFileUpload.tsx b/src/pages/Howto/Content/Common/HowtoFieldFileUpload.tsx index 30c8457d13..e124bce60b 100644 --- a/src/pages/Howto/Content/Common/HowtoFieldFileUpload.tsx +++ b/src/pages/Howto/Content/Common/HowtoFieldFileUpload.tsx @@ -1,4 +1,6 @@ import { Field } from 'react-final-form' +import { UserRole } from 'oa-shared' +import { AuthWrapper } from 'src/common/AuthWrapper' import { FileInputField } from 'src/common/Form/FileInput.field' import { FormFieldWrapper } from 'src/pages/Howto/Content/Common/FormFieldWrapper' import { Text } from 'theme-ui' @@ -10,11 +12,34 @@ export const HowtoFieldFileUpload = () => { const name = 'files' return ( - - - - {description} - - + + + + {description} + + + } + > + + + + {'Maximum file size 300MB'} + + + ) } diff --git a/src/pages/Research/Content/CreateResearch/Form/FilesFields.tsx b/src/pages/Research/Content/CreateResearch/Form/FilesFields.tsx index a76737fbcc..97cb414f47 100644 --- a/src/pages/Research/Content/CreateResearch/Form/FilesFields.tsx +++ b/src/pages/Research/Content/CreateResearch/Form/FilesFields.tsx @@ -1,6 +1,8 @@ import * as React from 'react' import { Field } from 'react-final-form' import { Button, DownloadStaticFile, FieldInput } from 'oa-components' +import { UserRole } from 'oa-shared' +import { AuthWrapper } from 'src/common/AuthWrapper' import { FileInputField } from 'src/common/Form/FileInput.field' import { MAX_LINK_LENGTH } from 'src/pages/constants' import { buttons, update as updateLabels } from 'src/pages/Research/labels' @@ -77,10 +79,33 @@ const UploadNewFiles = () => { - - - {files.description} - + + + + {files.description} + + + } + > + <> + + + {'Maximum file size 300MB'} + + + )