Skip to content

Commit

Permalink
#10770: Vector files import limits
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mahmoudadel54 committed Feb 10, 2025
1 parent 3479a25 commit 0049fe0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
4 changes: 3 additions & 1 deletion web/client/components/import/ImportDragZone.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ export default compose(
...props
}) => <DragZone
onClose={onClose}
onDrop={onDrop}
onDrop={(files) => {
return onDrop({ files, options: { importedVectorFileMaxSizeInMB: props.importedVectorFileMaxSizeInMB} });
}}
onRef={onRef}
>
<Content {...props} />
Expand Down
10 changes: 5 additions & 5 deletions web/client/components/import/dragZone/enhancers/processFiles.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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(
Expand Down
7 changes: 5 additions & 2 deletions web/client/plugins/MapImport.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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,
Expand All @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions web/client/utils/FileUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit 0049fe0

Please sign in to comment.