Skip to content

Commit

Permalink
fix(restoreStateFile): support 2.1.0 version of state file
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulHax committed Nov 29, 2023
1 parent 363207d commit ab466eb
Show file tree
Hide file tree
Showing 7 changed files with 468 additions and 35 deletions.
55 changes: 51 additions & 4 deletions src/io/import/processors/restoreStateFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,61 @@ import {
makeImageSelection,
useDatasetStore,
} from '@/src/store/datasets';
import { useSegmentGroupStore } from '@/src/store/segmentGroups';
import {
makeDefaultSegmentGroupName,
useSegmentGroupStore,
} from '@/src/store/segmentGroups';
import { useToolStore } from '@/src/store/tools';
import { useLayersStore } from '@/src/store/datasets-layers';
import { extractFilesFromZip } from '@/src/io/zip';
import downloadUrl from '@/src/io/import/processors/downloadUrl';
import updateFileMimeType from '@/src/io/import/processors/updateFileMimeType';
import extractArchiveTarget from '@/src/io/import/processors/extractArchiveTarget';

const migrateManifest = (manifestString: string) => {
const inputManifest = JSON.parse(manifestString);
if (inputManifest.version === '2.1.0') {
inputManifest.tools.paint.activeSegmentGroupID =
inputManifest.tools.paint.activeLabelmapID;
delete inputManifest.tools.paint.activeLabelmapID;

inputManifest.labelMaps = inputManifest.labelMaps.map(
(labelMap: any, index: number) => ({
id: labelMap.id,
path: labelMap.path,
metadata: {
parentImage: labelMap.parent,
name: makeDefaultSegmentGroupName('My Image', index),
segments: {
order: [1, 2, 3],
byValue: {
'1': {
value: 1,
name: 'Tissue',
color: [255, 0, 0, 255],
},
'2': {
value: 2,
name: 'Liver',
color: [0, 255, 0, 255],
},
'3': {
value: 3,
name: 'Heart',
color: [0, 0, 255, 255],
},
},
},
},
})
);

inputManifest.version = '3.0.0';
}

return inputManifest;
};

const resolveUriSource: ImportHandler = async (dataSource, { extra, done }) => {
const { uriSrc } = dataSource;

Expand Down Expand Up @@ -234,9 +281,9 @@ const restoreStateFile: ImportHandler = async (
throw new Error('State file does not have exactly 1 manifest');
}

const manifest = ManifestSchema.parse(
JSON.parse(await manifests[0].file.text())
);
const manifestString = await manifests[0].file.text();
const migrated = migrateManifest(manifestString);
const manifest = ManifestSchema.parse(migrated);

// We restore the view first, so that the appropriate watchers are triggered
// in the views as the data is loaded
Expand Down
Loading

0 comments on commit ab466eb

Please sign in to comment.