Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some failing validations of neuroglancer URLs #6722

Merged
merged 3 commits into from
Jan 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
);
Expand Down