Skip to content

Commit

Permalink
geosolutions-it#10770: Vector files import limits
Browse files Browse the repository at this point in the history
Description:
- add enhancements to the code including some helpful comments
  • Loading branch information
mahmoudadel54 committed Jan 27, 2025
1 parent 8b49759 commit 48268f1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
25 changes: 16 additions & 9 deletions web/client/components/import/dragZone/enhancers/processFiles.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,12 @@ const readFile = (onWarnings) => (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 isVectorFileSizeConfigurable = getConfigProp('importedVectorFileSizeInMB');
const configurableFileSizeLimitInMB = getConfigProp('importedVectorFileSizeInMB');
const isVectorFile = type !== 'application/json'; // skip json as json is for map file
if (isVectorFileSizeConfigurable && isVectorFile) {
const fileSizeLimitInMB = getConfigProp('importedVectorFileSizeInMB');
if (isFileSizeExceedMaxLimit(file, fileSizeLimitInMB)) {
if (configurableFileSizeLimitInMB && isVectorFile) {
if (isFileSizeExceedMaxLimit(file, configurableFileSizeLimitInMB)) {
// add 'exceedFileMaxSize' and fileSizeLimitInMB into layer object to be used in useFiles
return [[{ "type": "FeatureCollection", features: [], "fileName": file.name, exceedFileMaxSize: true, fileSizeLimitInMB }]];
return [[{ "type": "FeatureCollection", features: [{}], "fileName": file.name, name: file.name, exceedFileMaxSize: true, fileSizeLimitInMB: configurableFileSizeLimitInMB }]];
}
}

Expand Down Expand Up @@ -170,11 +169,19 @@ export default compose(
layers: (result.layers || [])
.concat(
jsonObjects.filter(json => isGeoJSON(json))
.map(json => (isAnnotation(json) ?
// annotation GeoJSON to layers
{ name: "Annotations", features: importJSONToAnnotations(json), filename: json.filename} :
.map(json => {
const isLayerExceedsMaxFileSize = json?.exceedFileMaxSize || false;
const isAnnotationLayer = isAnnotation(json);
if (isAnnotationLayer) {
// annotation GeoJSON to layers
return { name: "Annotations", features: importJSONToAnnotations(json), filename: json.filename};
} else if (isLayerExceedsMaxFileSize) {
// layers with size exceeds the max size limit
return { ...json, filename: json.filename};
}
// other GeoJSON to layers
{...geoJSONToLayer(json), filename: json.filename}))
return {...geoJSONToLayer(json), filename: json.filename};
})
),
maps: (result.maps || [])
.concat(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default compose(
layers.forEach((layer) => {
const isFileSizeNotValid = !!layer?.exceedFileMaxSize; // this check is for file size limit for vector layer
const valid = layer.type === "vector" ? (checkIfLayerFitsExtentForProjection(layer) && !isFileSizeNotValid) : true;
if (valid) {
if (valid && !isFileSizeNotValid) {
validLayers.push(layer);
} else if (isFileSizeNotValid) {
warning({
Expand Down

0 comments on commit 48268f1

Please sign in to comment.