Refactor URL normalization to ensure valid wadouri: prefix for DICOM entries
Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
@@ -6,9 +6,28 @@ import Nifti from './Nifti.tsx'
|
||||
import './index.css'
|
||||
import { createImageIds, availableImageIds } from "./lib/createImageIds.ts"
|
||||
|
||||
// Helper to convert URLs to wadouri
|
||||
const toWadouri = (arr: string[]) =>
|
||||
arr.map(url => url.startsWith("wadouri:") ? url : `wadouri:${url}`);
|
||||
// Normalize incoming image ids/URLs and ensure DICOM entries use a valid wadouri: prefix.
|
||||
const normalizeImageId = (value: string) => {
|
||||
const trimmed = value.trim();
|
||||
if (!trimmed) return trimmed;
|
||||
|
||||
// Keep non-wadouri schemes untouched.
|
||||
if (trimmed.startsWith("external:") || trimmed.startsWith("wadors:")) {
|
||||
return trimmed;
|
||||
}
|
||||
|
||||
// Fix malformed values like "wadouri::https://..." by removing extra leading colons.
|
||||
if (trimmed.startsWith("wadouri:")) {
|
||||
const rest = trimmed.slice("wadouri:".length).replace(/^:+/, "");
|
||||
return `wadouri:${rest}`;
|
||||
}
|
||||
|
||||
// Also handle malformed absolute URLs such as ":https://...".
|
||||
const sanitized = trimmed.replace(/^:+/, "");
|
||||
return `wadouri:${sanitized}`;
|
||||
};
|
||||
|
||||
const toWadouri = (arr: string[]) => arr.map(normalizeImageId);
|
||||
|
||||
// Normalize a simple array -> descriptor object
|
||||
const toDescriptor = (arr: string[] | undefined) => {
|
||||
|
||||
Reference in New Issue
Block a user