From 0049fe05559e255acd4b20be687d9cf3bebd557b Mon Sep 17 00:00:00 2001 From: mahmoudadel54 Date: Mon, 10 Feb 2025 11:58:31 +0200 Subject: [PATCH] #10770: Vector files import limits Description: - replace using 'getConfigProp' for 'importedVectorFileMaxSizeInMB' with direct cfg to map import - modify files based on this change - put default max file size with 2 mega byte --- web/client/components/import/ImportDragZone.jsx | 4 +++- .../import/dragZone/enhancers/processFiles.jsx | 10 +++++----- web/client/plugins/MapImport.jsx | 7 +++++-- web/client/utils/FileUtils.js | 4 ++++ 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/web/client/components/import/ImportDragZone.jsx b/web/client/components/import/ImportDragZone.jsx index 0a1581ce10..20040cf4ff 100644 --- a/web/client/components/import/ImportDragZone.jsx +++ b/web/client/components/import/ImportDragZone.jsx @@ -26,7 +26,9 @@ export default compose( ...props }) => { + return onDrop({ files, options: { importedVectorFileMaxSizeInMB: props.importedVectorFileMaxSizeInMB} }); + }} onRef={onRef} > diff --git a/web/client/components/import/dragZone/enhancers/processFiles.jsx b/web/client/components/import/dragZone/enhancers/processFiles.jsx index f3a48222eb..67740364cb 100644 --- a/web/client/components/import/dragZone/enhancers/processFiles.jsx +++ b/web/client/components/import/dragZone/enhancers/processFiles.jsx @@ -12,7 +12,7 @@ import { compose, createEventHandler, mapPropsStream } from 'recompose'; import Rx from 'rxjs'; import { isAnnotation, importJSONToAnnotations } from '../../../../plugins/Annotations/utils/AnnotationsUtils'; -import ConfigUtils, { getConfigProp } from '../../../../utils/ConfigUtils'; +import ConfigUtils from '../../../../utils/ConfigUtils'; import { MIME_LOOKUPS, checkShapePrj, @@ -64,11 +64,11 @@ const checkFileType = (file) => { * Create a function that return a Promise for reading file. The Promise resolves with an array of (json) * @param {function} onWarnings callback in case of warnings to report */ -const readFile = (onWarnings) => (file) => { +const readFile = ({onWarnings, options}) => (file) => { const ext = recognizeExt(file.name); const type = file.type || MIME_LOOKUPS[ext]; // Check the file size first before file conversion process to avoid this useless effort - const configurableFileSizeLimitInMB = getConfigProp('importedVectorFileMaxSizeInMB'); + const configurableFileSizeLimitInMB = options.importedVectorFileMaxSizeInMB; const isVectorFile = type !== 'application/json'; // skip json as json is for map file if (configurableFileSizeLimitInMB && isVectorFile) { if (isFileSizeExceedMaxLimit(file, configurableFileSizeLimitInMB)) { @@ -162,9 +162,9 @@ export default compose( const { handler: onWarnings, stream: warnings$} = createEventHandler(); return props$.combineLatest( drop$.switchMap( - files => Rx.Observable.from(files) + ({files, options}) => Rx.Observable.from(files) .flatMap(checkFileType) // check file types are allowed - .flatMap(readFile(onWarnings)) // read files to convert to json + .flatMap(readFile({onWarnings, options})) // read files to convert to json .reduce((result, jsonObjects) => ({ // divide files by type layers: (result.layers || []) .concat( diff --git a/web/client/plugins/MapImport.jsx b/web/client/plugins/MapImport.jsx index 0e16078c7e..72449ec979 100644 --- a/web/client/plugins/MapImport.jsx +++ b/web/client/plugins/MapImport.jsx @@ -31,6 +31,7 @@ import { toggleControl } from '../actions/controls'; import assign from 'object-assign'; import { Glyphicon } from 'react-bootstrap'; import { mapTypeSelector } from '../selectors/maptype'; +import { DEFAULT_VECTOR_FILE_MAX_SIZE_IN_MB } from '../utils/FileUtils'; /** * Allows the user to import a file into current map. @@ -46,13 +47,14 @@ import { mapTypeSelector } from '../selectors/maptype'; * @memberof plugins * @name MapImport * @class + * @prop {number} cfg.importedVectorFileMaxSizeInMB it is the max allowable file size for import vectir layers in mega bytes */ export default { MapImportPlugin: assign({loadPlugin: (resolve) => { import('./import/Import').then((importMod) => { const Import = importMod.default; - const ImportPlugin = connect((state) => ( + const ImportPlugin = connect((state, ownProps) =>( { enabled: state.controls && state.controls.mapimport && state.controls.mapimport.enabled, layers: state.mapimport && state.mapimport.layers || null, @@ -62,7 +64,8 @@ export default { errors: state.mapimport && state.mapimport.errors || null, shapeStyle: state.style || {}, mapType: mapTypeSelector(state), - annotationsLayer: annotationsLayerSelector(state) + annotationsLayer: annotationsLayerSelector(state), + importedVectorFileMaxSizeInMB: ownProps?.importedVectorFileMaxSizeInMB || DEFAULT_VECTOR_FILE_MAX_SIZE_IN_MB } ), { setLayers, diff --git a/web/client/utils/FileUtils.js b/web/client/utils/FileUtils.js index 5860c8254b..a2795dbf98 100644 --- a/web/client/utils/FileUtils.js +++ b/web/client/utils/FileUtils.js @@ -192,3 +192,7 @@ export const isFileSizeExceedMaxLimit = (file, fileSizeLimitInMb) => { } return true; }; +/** + * the max file size limit for import vector files + */ +export const DEFAULT_VECTOR_FILE_MAX_SIZE_IN_MB = 2;