From 329fb515e29e697934c8083a1469d10dc00a9af2 Mon Sep 17 00:00:00 2001 From: Philipp Otto Date: Thu, 5 Jan 2023 11:14:35 +0100 Subject: [PATCH 1/2] make neuroglancer import compatible with URLs that encode subsources and improve validation in general --- .../dataset/dataset_add_neuroglancer_view.tsx | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/frontend/javascripts/admin/dataset/dataset_add_neuroglancer_view.tsx b/frontend/javascripts/admin/dataset/dataset_add_neuroglancer_view.tsx index 6e37dc70cfc..8a4ca0ec2da 100644 --- a/frontend/javascripts/admin/dataset/dataset_add_neuroglancer_view.tsx +++ b/frontend/javascripts/admin/dataset/dataset_add_neuroglancer_view.tsx @@ -44,9 +44,20 @@ function DatasetAddNeuroglancerView({ datastores, onAdded, activeUser }: Props) const jsonConfig = url.slice(delimiterIndex + 2); // This will throw an error if the URL did not contain valid JSON. The error will be handled by the caller. const config = JSON.parse(decodeURIComponent(jsonConfig)); - // @ts-expect-error ts-migrate(7006) FIXME: Parameter 'layer' implicitly has an 'any' type. - config.layers.forEach((layer) => { - if (!layer.source.startsWith("precomputed://")) { + + if (!("layers" in config && Array.isArray(config.layers))) { + throw new Error("Invalid config in URL. No 'layers' array found."); + } + + config.layers.forEach((layer: any, index: number) => { + if (!("source" in layer)) { + throw new Error(`No source property found in a layer ${index + 1}.`); + } + const isIncompatibleString = + typeof layer.source === "string" && !layer.source.startsWith("precomputed://"); + const isIncompatibleObject = + typeof layer.source === "object" && !layer.source.url.startsWith("precomputed://"); + if (isIncompatibleString || isIncompatibleObject) { throw new Error( "This dataset contains layers that are not supported. wk-connect supports only 'precomputed://' neuroglancer layers.", ); From 6016160be208a50f8c689dbfd91db80516ad909c Mon Sep 17 00:00:00 2001 From: Philipp Otto Date: Thu, 5 Jan 2023 11:17:38 +0100 Subject: [PATCH 2/2] update changelog --- CHANGELOG.unreleased.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.unreleased.md b/CHANGELOG.unreleased.md index 670be7d60c5..0751e3394d2 100644 --- a/CHANGELOG.unreleased.md +++ b/CHANGELOG.unreleased.md @@ -16,6 +16,7 @@ For upgrade instructions, please check the [migration guide](MIGRATIONS.released - Improved performance of opening a dataset or annotation. [#6711](https://github.com/scalableminds/webknossos/pull/6711) ### Fixed +- Fixed the validation of some neuroglancer URLs during import. [#6722](https://github.com/scalableminds/webknossos/pull/6722) ### Removed