@geode/opengeodeweb-front 10.44.0-rc.6 → 10.44.0-rc.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.build/server/utils/scripts.js +34 -23
- package/app/components/BasemapAttribution.vue +28 -0
- package/app/components/MissingFilesSelector.vue +30 -17
- package/app/components/ObjectSelector.vue +34 -23
- package/app/components/Viewer/Basemap/CropOptions.vue +50 -0
- package/app/components/Viewer/Basemap/OpacityOptions.vue +52 -0
- package/app/components/Viewer/ContextMenu/ContextMenu.vue +5 -1
- package/app/components/Viewer/ContextMenu/ContextMenuItem.vue +6 -2
- package/app/components/Viewer/ObjectTree/Views/GlobalObjects.vue +49 -10
- package/app/components/Viewer/Ui.vue +6 -0
- package/app/composables/overlapping_picker_menu.ts +43 -0
- package/app/composables/project_manager_helpers/reset.ts +3 -0
- package/app/composables/project_manager_helpers/restore.ts +22 -10
- package/app/composables/project_manager_helpers/types.ts +2 -0
- package/app/composables/use_overlapping_picker.ts +23 -37
- package/app/composables/viewer_context_menu.ts +10 -0
- package/app/composables/virtual_tree_flatten.ts +66 -43
- package/app/stores/app_helpers/extension.ts +90 -51
- package/app/stores/basemap.ts +52 -0
- package/app/stores/basemap_detail.ts +51 -0
- package/app/stores/basemap_helpers/builds.ts +158 -0
- package/app/stores/basemap_helpers/detail_layers.ts +72 -0
- package/app/stores/basemap_helpers/detail_map.ts +62 -0
- package/app/stores/basemap_helpers/detail_refresh.ts +134 -0
- package/app/stores/basemap_helpers/detail_view.ts +94 -0
- package/app/stores/basemap_helpers/extent.ts +40 -0
- package/app/stores/basemap_helpers/georeferenced.ts +50 -0
- package/app/stores/basemap_helpers/layers.ts +66 -0
- package/app/stores/basemap_helpers/settings.ts +87 -0
- package/app/stores/basemap_helpers/viewer.ts +114 -0
- package/app/stores/infra.ts +26 -21
- package/app/stores/menu_helpers/basemap.ts +10 -0
- package/app/stores/menu_helpers/menus_data.ts +2 -0
- package/app/utils/basemap_tree.ts +76 -0
- package/app/utils/color_picker.ts +18 -15
- package/app/utils/treeview.ts +12 -1
- package/app/utils/visible_map_area.ts +129 -0
- package/internal/database/database.ts +47 -32
- package/internal/stores/data_style/mesh/base_style.ts +74 -0
- package/internal/stores/data_style/mesh/index.ts +2 -57
- package/internal/stores/data_style/model/blocks/color.ts +58 -57
- package/internal/stores/data_style/model/blocks/polyhedron.ts +88 -44
- package/internal/stores/data_style/model/blocks/vertex.ts +88 -44
- package/internal/stores/data_style/model/color.ts +25 -26
- package/internal/stores/data_style/model/corners/index.ts +85 -78
- package/internal/stores/data_style/model/corners/vertex.ts +83 -39
- package/internal/stores/data_style/model/lines/color.ts +53 -40
- package/internal/stores/data_style/model/lines/edge.ts +88 -44
- package/internal/stores/data_style/model/lines/vertex.ts +88 -44
- package/internal/stores/data_style/model/surfaces/color.ts +68 -56
- package/internal/stores/data_style/model/surfaces/polygon.ts +80 -36
- package/internal/stores/data_style/model/surfaces/vertex.ts +80 -36
- package/internal/stores/data_style/model/visibility_dispatch.ts +49 -99
- package/internal/stores/hybrid_viewer/highlight.ts +70 -54
- package/internal/stores/hybrid_viewer/scene.ts +31 -25
- package/internal/stores/hybrid_viewer/vtk_types.ts +2 -1
- package/package.json +1 -1
- package/server/api/local/extensions/upload.put.ts +47 -20
- package/server/utils/scripts.ts +35 -30
|
@@ -42,15 +42,29 @@ async function getModelComponentsMap(
|
|
|
42
42
|
),
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
const COMPONENT_TYPE_NAMES = ["Block", "Surface", "Line", "Corner"] as const;
|
|
46
|
+
type ComponentTypeName = (typeof COMPONENT_TYPE_NAMES)[number];
|
|
47
|
+
|
|
48
|
+
const DISPATCH_METHODS: Partial<Record<string, Record<ComponentTypeName, string>>> = {
|
|
49
|
+
Visibility: {
|
|
50
|
+
Block: "setModelBlocksVisibility",
|
|
51
|
+
Surface: "setModelSurfacesVisibility",
|
|
52
|
+
Line: "setModelLinesVisibility",
|
|
53
|
+
Corner: "setModelCornersVisibility",
|
|
54
|
+
},
|
|
55
|
+
Color: {
|
|
56
|
+
Block: "setModelBlocksColor",
|
|
57
|
+
Surface: "setModelSurfacesColor",
|
|
58
|
+
Line: "setModelLinesColor",
|
|
59
|
+
Corner: "setModelCornersColor",
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
function groupIdsByComponentType(
|
|
47
64
|
componentIds: string[],
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
): Promise<unknown[]> {
|
|
52
|
-
const { componentsMap } = await getModelComponentsMap(modelId);
|
|
53
|
-
const idsByComponent: { Block: string[]; Surface: string[]; Line: string[]; Corner: string[] } = {
|
|
65
|
+
componentsMap: Record<string, ModelComponent>,
|
|
66
|
+
): Record<ComponentTypeName, string[]> {
|
|
67
|
+
const idsByComponent: Record<ComponentTypeName, string[]> = {
|
|
54
68
|
Block: [],
|
|
55
69
|
Surface: [],
|
|
56
70
|
Line: [],
|
|
@@ -62,98 +76,34 @@ async function dispatchToComponentTypes(
|
|
|
62
76
|
(idsByComponent as Record<string, string[]>)[type]?.push(id);
|
|
63
77
|
}
|
|
64
78
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
callComponentStyleFunction(
|
|
81
|
-
componentStyleFunctions.Surface,
|
|
82
|
-
"setModelSurfacesVisibility",
|
|
83
|
-
modelId,
|
|
84
|
-
idsByComponent.Surface,
|
|
85
|
-
...args,
|
|
86
|
-
),
|
|
87
|
-
);
|
|
88
|
-
}
|
|
89
|
-
if (idsByComponent.Line.length > 0) {
|
|
90
|
-
promises.push(
|
|
91
|
-
callComponentStyleFunction(
|
|
92
|
-
componentStyleFunctions.Line,
|
|
93
|
-
"setModelLinesVisibility",
|
|
94
|
-
modelId,
|
|
95
|
-
idsByComponent.Line,
|
|
96
|
-
...args,
|
|
97
|
-
),
|
|
98
|
-
);
|
|
99
|
-
}
|
|
100
|
-
if (idsByComponent.Corner.length > 0) {
|
|
101
|
-
promises.push(
|
|
102
|
-
callComponentStyleFunction(
|
|
103
|
-
componentStyleFunctions.Corner,
|
|
104
|
-
"setModelCornersVisibility",
|
|
105
|
-
modelId,
|
|
106
|
-
idsByComponent.Corner,
|
|
107
|
-
...args,
|
|
108
|
-
),
|
|
109
|
-
);
|
|
110
|
-
}
|
|
111
|
-
} else if (action === "Color") {
|
|
112
|
-
if (idsByComponent.Block.length > 0) {
|
|
113
|
-
promises.push(
|
|
114
|
-
callComponentStyleFunction(
|
|
115
|
-
componentStyleFunctions.Block,
|
|
116
|
-
"setModelBlocksColor",
|
|
117
|
-
modelId,
|
|
118
|
-
idsByComponent.Block,
|
|
119
|
-
...args,
|
|
120
|
-
),
|
|
121
|
-
);
|
|
122
|
-
}
|
|
123
|
-
if (idsByComponent.Surface.length > 0) {
|
|
124
|
-
promises.push(
|
|
125
|
-
callComponentStyleFunction(
|
|
126
|
-
componentStyleFunctions.Surface,
|
|
127
|
-
"setModelSurfacesColor",
|
|
128
|
-
modelId,
|
|
129
|
-
idsByComponent.Surface,
|
|
130
|
-
...args,
|
|
131
|
-
),
|
|
132
|
-
);
|
|
133
|
-
}
|
|
134
|
-
if (idsByComponent.Line.length > 0) {
|
|
135
|
-
promises.push(
|
|
136
|
-
callComponentStyleFunction(
|
|
137
|
-
componentStyleFunctions.Line,
|
|
138
|
-
"setModelLinesColor",
|
|
139
|
-
modelId,
|
|
140
|
-
idsByComponent.Line,
|
|
141
|
-
...args,
|
|
142
|
-
),
|
|
143
|
-
);
|
|
144
|
-
}
|
|
145
|
-
if (idsByComponent.Corner.length > 0) {
|
|
146
|
-
promises.push(
|
|
147
|
-
callComponentStyleFunction(
|
|
148
|
-
componentStyleFunctions.Corner,
|
|
149
|
-
"setModelCornersColor",
|
|
150
|
-
modelId,
|
|
151
|
-
idsByComponent.Corner,
|
|
152
|
-
...args,
|
|
153
|
-
),
|
|
154
|
-
);
|
|
155
|
-
}
|
|
79
|
+
return idsByComponent;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async function dispatchToComponentTypes(
|
|
83
|
+
modelId: string,
|
|
84
|
+
componentIds: string[],
|
|
85
|
+
action: string,
|
|
86
|
+
{ componentStyleFunctions }: { componentStyleFunctions: ComponentStyleFunctions },
|
|
87
|
+
...args: unknown[]
|
|
88
|
+
): Promise<unknown[]> {
|
|
89
|
+
const { componentsMap } = await getModelComponentsMap(modelId);
|
|
90
|
+
const idsByComponent = groupIdsByComponentType(componentIds, componentsMap);
|
|
91
|
+
const methods = DISPATCH_METHODS[action];
|
|
92
|
+
if (methods === undefined) {
|
|
93
|
+
return [];
|
|
156
94
|
}
|
|
95
|
+
const promises = COMPONENT_TYPE_NAMES.filter((type) => idsByComponent[type].length > 0).map(
|
|
96
|
+
async (type) => {
|
|
97
|
+
const result = await callComponentStyleFunction(
|
|
98
|
+
componentStyleFunctions[type],
|
|
99
|
+
methods[type],
|
|
100
|
+
modelId,
|
|
101
|
+
idsByComponent[type],
|
|
102
|
+
...args,
|
|
103
|
+
);
|
|
104
|
+
return result;
|
|
105
|
+
},
|
|
106
|
+
);
|
|
157
107
|
return Promise.all(promises);
|
|
158
108
|
}
|
|
159
109
|
export { getModelComponentsMap, dispatchToComponentTypes };
|
|
@@ -10,6 +10,34 @@ import { useHybridViewerCore } from "./core";
|
|
|
10
10
|
import { useHybridViewerScene } from "./scene";
|
|
11
11
|
import { useViewerStore } from "@ogw_front/stores/viewer";
|
|
12
12
|
|
|
13
|
+
async function lookupModelName(modelId: string): Promise<string | undefined> {
|
|
14
|
+
const modelRecord = (await database.data?.get(modelId)) as { name?: string } | undefined;
|
|
15
|
+
return modelRecord?.name;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async function lookupComponentInfo(
|
|
19
|
+
modelId: string,
|
|
20
|
+
geodeId: string | undefined,
|
|
21
|
+
): Promise<HoverComponentInfo | undefined> {
|
|
22
|
+
const modelComponentsTable = database.model_components;
|
|
23
|
+
if (geodeId === undefined || !modelComponentsTable) {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
const components = modelComponentsTable.where("[id+geode_id]");
|
|
27
|
+
const query = components.equals([modelId, geodeId] as IndexableType);
|
|
28
|
+
const component = (await query.first()) as
|
|
29
|
+
| { name?: string; geode_id?: string; type?: string }
|
|
30
|
+
| undefined;
|
|
31
|
+
if (!component) {
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
return {
|
|
35
|
+
name: component.name ?? "",
|
|
36
|
+
id: component.geode_id ?? "",
|
|
37
|
+
type: component.type ?? "",
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
13
41
|
// Shared via createSharedComposable (rather than merged into the parent hybridViewer store) so sibling slices, e.g. ruler.ts and viewport.ts, can read hover state/clearHoverHighlight/hoverHighlight directly without importing the parent store and creating a cycle. A Pinia store would work too but its $id/$patch/... properties would leak into the composed store's spread and collapse its inferred type.
|
|
14
42
|
const useHybridViewerHighlight = createSharedComposable(() => {
|
|
15
43
|
const is_hover_highlight = ref(false);
|
|
@@ -67,6 +95,47 @@ const useHybridViewerHighlight = createSharedComposable(() => {
|
|
|
67
95
|
.catch(() => undefined);
|
|
68
96
|
}
|
|
69
97
|
|
|
98
|
+
async function handleHoverResponse(
|
|
99
|
+
response: ViewerHighlightResponse,
|
|
100
|
+
relativeMousePosition: { x: number; y: number },
|
|
101
|
+
): Promise<void> {
|
|
102
|
+
if (
|
|
103
|
+
!is_hover_highlight.value ||
|
|
104
|
+
response.id === undefined ||
|
|
105
|
+
response.picked_id === undefined ||
|
|
106
|
+
response.picked_id === -1
|
|
107
|
+
) {
|
|
108
|
+
clearHoverData();
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const hoverKey = `${response.id}_${response.field_type}_${response.picked_id}`;
|
|
112
|
+
if (currentHoverId.value === hoverKey) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
if (hoverTimeoutRef.value) {
|
|
116
|
+
clearTimeout(hoverTimeoutRef.value);
|
|
117
|
+
hoverTimeoutRef.value = undefined;
|
|
118
|
+
}
|
|
119
|
+
hoverData.value = undefined;
|
|
120
|
+
currentHoverId.value = hoverKey;
|
|
121
|
+
const modelName = await lookupModelName(response.id);
|
|
122
|
+
const componentInfo = await lookupComponentInfo(response.id, response.geode_id);
|
|
123
|
+
const newHoverData: HoverData = {
|
|
124
|
+
modelId: response.id,
|
|
125
|
+
modelName,
|
|
126
|
+
blockName: response.geode_id,
|
|
127
|
+
pickedId: response.picked_id,
|
|
128
|
+
fieldType: response.field_type,
|
|
129
|
+
component: componentInfo,
|
|
130
|
+
attributes: response.attributes ?? {},
|
|
131
|
+
};
|
|
132
|
+
hoverTimeoutRef.value = setTimeout(() => {
|
|
133
|
+
hoverPosition.value = relativeMousePosition;
|
|
134
|
+
hoverData.value = newHoverData;
|
|
135
|
+
hoverTimeoutRef.value = undefined;
|
|
136
|
+
}, HOVER_TIMEOUT_MS);
|
|
137
|
+
}
|
|
138
|
+
|
|
70
139
|
const hoverHighlight = useDebounceFn((event: MouseEvent) => {
|
|
71
140
|
const { genericRenderWindow } = useHybridViewerCore();
|
|
72
141
|
const containerElement = genericRenderWindow.value?.getContainer();
|
|
@@ -81,60 +150,7 @@ const useHybridViewerHighlight = createSharedComposable(() => {
|
|
|
81
150
|
};
|
|
82
151
|
}
|
|
83
152
|
requestHoverHighlight(event, async (response) => {
|
|
84
|
-
|
|
85
|
-
!is_hover_highlight.value ||
|
|
86
|
-
response.id === undefined ||
|
|
87
|
-
response.picked_id === undefined ||
|
|
88
|
-
response.picked_id === -1
|
|
89
|
-
) {
|
|
90
|
-
clearHoverData();
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
const hoverKey = `${response.id}_${response.field_type}_${response.picked_id}`;
|
|
94
|
-
if (currentHoverId.value === hoverKey) {
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
if (hoverTimeoutRef.value) {
|
|
98
|
-
clearTimeout(hoverTimeoutRef.value);
|
|
99
|
-
hoverTimeoutRef.value = undefined;
|
|
100
|
-
}
|
|
101
|
-
hoverData.value = undefined;
|
|
102
|
-
currentHoverId.value = hoverKey;
|
|
103
|
-
let componentInfo: HoverComponentInfo | undefined = undefined;
|
|
104
|
-
let modelName: string | undefined = undefined;
|
|
105
|
-
const modelRecord = (await database.data?.get(response.id)) as { name?: string } | undefined;
|
|
106
|
-
if (modelRecord) {
|
|
107
|
-
modelName = modelRecord.name;
|
|
108
|
-
}
|
|
109
|
-
const modelComponentsTable = database.model_components;
|
|
110
|
-
if (response.geode_id !== undefined && modelComponentsTable) {
|
|
111
|
-
const components = modelComponentsTable.where("[id+geode_id]");
|
|
112
|
-
const query = components.equals([response.id, response.geode_id] as IndexableType);
|
|
113
|
-
const component = (await query.first()) as
|
|
114
|
-
| { name?: string; geode_id?: string; type?: string }
|
|
115
|
-
| undefined;
|
|
116
|
-
if (component) {
|
|
117
|
-
componentInfo = {
|
|
118
|
-
name: component.name ?? "",
|
|
119
|
-
id: component.geode_id ?? "",
|
|
120
|
-
type: component.type ?? "",
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
const newHoverData: HoverData = {
|
|
125
|
-
modelId: response.id,
|
|
126
|
-
modelName,
|
|
127
|
-
blockName: response.geode_id,
|
|
128
|
-
pickedId: response.picked_id,
|
|
129
|
-
fieldType: response.field_type,
|
|
130
|
-
component: componentInfo,
|
|
131
|
-
attributes: response.attributes ?? {},
|
|
132
|
-
};
|
|
133
|
-
hoverTimeoutRef.value = setTimeout(() => {
|
|
134
|
-
hoverPosition.value = relativeMousePosition;
|
|
135
|
-
hoverData.value = newHoverData;
|
|
136
|
-
hoverTimeoutRef.value = undefined;
|
|
137
|
-
}, HOVER_TIMEOUT_MS);
|
|
153
|
+
await handleHoverResponse(response, relativeMousePosition);
|
|
138
154
|
});
|
|
139
155
|
}, HOVER_DEBOUNCE_MS);
|
|
140
156
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ACTOR_COLOR, RGB_MAX } from "./constants";
|
|
2
|
-
import type { HybridDb, vtkActor as VtkActorInstance, vtkCamera } from "./vtk_types";
|
|
2
|
+
import type { HybridDb, HybridDbEntry, vtkActor as VtkActorInstance, vtkCamera } from "./vtk_types";
|
|
3
3
|
import { requireRenderWindow, useHybridViewerCore } from "./core";
|
|
4
4
|
import viewer_schemas, {
|
|
5
5
|
type ViewerSetBackgroundColorParams,
|
|
@@ -40,6 +40,31 @@ function followZScaling(camera: vtkCamera, ratio: number): void {
|
|
|
40
40
|
camera.setPosition(positionX, positionY, positionZ + offset);
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
+
async function fetchBinaryLightViewable(id: string): Promise<string | undefined> {
|
|
44
|
+
const dataStore = useDataStore();
|
|
45
|
+
const isViewable = await dataStore.isItemViewable(id);
|
|
46
|
+
if (!isViewable) {
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
const value = await dataStore.item(id);
|
|
50
|
+
return value.binary_light_viewable;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function createHybridDbEntry(binaryLightViewable: string, zScale: number): HybridDbEntry {
|
|
54
|
+
const reader = vtkXMLPolyDataReader();
|
|
55
|
+
reader.parseAsArrayBuffer(base64ToArrayBuffer(binaryLightViewable));
|
|
56
|
+
const actor = vtkActor();
|
|
57
|
+
const mapper = vtkMapper();
|
|
58
|
+
// oxlint-disable-next-line no-unsafe-type-assertion -- vtk.js's algorithm interface types getOutputData as `any`; this reader always produces polydata.
|
|
59
|
+
const polydata = reader.getOutputData(0) as unknown as vtkPolyData;
|
|
60
|
+
mapper.setInputData(polydata);
|
|
61
|
+
const property = actor.getProperty();
|
|
62
|
+
property.setColor(ACTOR_COLOR);
|
|
63
|
+
actor.setMapper(mapper);
|
|
64
|
+
actor.setScale(1, 1, zScale);
|
|
65
|
+
return { actor, polydata, mapper };
|
|
66
|
+
}
|
|
67
|
+
|
|
43
68
|
// Shared via createSharedComposable (rather than merged into the parent hybridViewer store) so sibling slices, e.g. camera.ts and ruler.ts, can read hybridDb/setZScaling directly without importing the parent store and creating a cycle. A Pinia store would work too but its $id/$patch/... properties would leak into the composed store's spread and collapse its inferred type.
|
|
44
69
|
const useHybridViewerScene = createSharedComposable(() => {
|
|
45
70
|
const hybridDb = reactive<HybridDb>({});
|
|
@@ -50,42 +75,23 @@ const useHybridViewerScene = createSharedComposable(() => {
|
|
|
50
75
|
if (!genericRenderWindow.value) {
|
|
51
76
|
return;
|
|
52
77
|
}
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
if (!isViewable) {
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
const value = await dataStore.item(id);
|
|
59
|
-
if (value.binary_light_viewable === undefined) {
|
|
78
|
+
const binaryLightViewable = await fetchBinaryLightViewable(id);
|
|
79
|
+
if (binaryLightViewable === undefined) {
|
|
60
80
|
return;
|
|
61
81
|
}
|
|
62
|
-
const reader = vtkXMLPolyDataReader();
|
|
63
|
-
reader.parseAsArrayBuffer(base64ToArrayBuffer(value.binary_light_viewable));
|
|
64
|
-
const actor = vtkActor();
|
|
65
|
-
const mapper = vtkMapper();
|
|
66
|
-
// oxlint-disable-next-line no-unsafe-type-assertion -- vtk.js's algorithm interface types getOutputData as `any`; this reader always produces polydata.
|
|
67
|
-
const polydata = reader.getOutputData(0) as unknown as vtkPolyData;
|
|
68
|
-
mapper.setInputData(polydata);
|
|
69
|
-
const property = actor.getProperty();
|
|
70
|
-
property.setColor(ACTOR_COLOR);
|
|
71
|
-
actor.setMapper(mapper);
|
|
72
82
|
// The scene z-scaling also applies to actors added after it was set
|
|
73
|
-
|
|
83
|
+
const entry = createHybridDbEntry(binaryLightViewable, zScale.value);
|
|
74
84
|
const renderer = genericRenderWindow.value.getRenderer();
|
|
75
85
|
// Replacing an actor keeps the camera where the user left it
|
|
76
86
|
const isFirst = !hybridDb[id] && renderer.getActors().length === 0;
|
|
77
87
|
if (hybridDb[id]) {
|
|
78
88
|
renderer.removeActor(hybridDb[id].actor);
|
|
79
89
|
}
|
|
80
|
-
renderer.addActor(actor);
|
|
90
|
+
renderer.addActor(entry.actor);
|
|
81
91
|
if (isFirst) {
|
|
82
92
|
renderer.resetCamera();
|
|
83
93
|
}
|
|
84
|
-
hybridDb[id] =
|
|
85
|
-
actor,
|
|
86
|
-
polydata,
|
|
87
|
-
mapper,
|
|
88
|
-
};
|
|
94
|
+
hybridDb[id] = entry;
|
|
89
95
|
}
|
|
90
96
|
|
|
91
97
|
function removeItem(id: string): void {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Vector3 } from "@kitware/vtk.js/types";
|
|
2
2
|
import type vtkActor from "@kitware/vtk.js/Rendering/Core/Actor";
|
|
3
|
+
import type vtkPolyData from "@kitware/vtk.js/Common/DataModel/PolyData";
|
|
3
4
|
|
|
4
5
|
// The camera state as exchanged with the viewer microservice (snake_case field names, plain arrays) - distinct from vtk.js's own vtkCamera object.
|
|
5
6
|
interface CameraOptions {
|
|
@@ -13,7 +14,7 @@ interface CameraOptions {
|
|
|
13
14
|
|
|
14
15
|
interface HybridDbEntry {
|
|
15
16
|
actor: vtkActor;
|
|
16
|
-
polydata:
|
|
17
|
+
polydata: vtkPolyData;
|
|
17
18
|
mapper: unknown;
|
|
18
19
|
}
|
|
19
20
|
|
package/package.json
CHANGED
|
@@ -40,33 +40,60 @@ function requiredQueryInt(event: H3Event, key: string): number {
|
|
|
40
40
|
return parsed;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
+
interface UploadQuery {
|
|
44
|
+
projectName: string;
|
|
45
|
+
filename: string;
|
|
46
|
+
totalChunks: number;
|
|
47
|
+
chunkIndex: number;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function parseUploadQuery(event: H3Event): UploadQuery {
|
|
51
|
+
const projectName = requiredQueryString(event, "projectName");
|
|
52
|
+
const filename = requiredQueryString(event, "filename");
|
|
53
|
+
const totalChunks = requiredQueryInt(event, "total_chunks");
|
|
54
|
+
const chunkIndex = requiredQueryInt(event, "chunk_index");
|
|
55
|
+
if (chunkIndex >= totalChunks) {
|
|
56
|
+
throw createError({ statusCode: 400, message: "chunk_index must be less than total_chunks" });
|
|
57
|
+
}
|
|
58
|
+
return { projectName, filename, totalChunks, chunkIndex };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function requiredBodyStream(event: H3Event): ReadableStream<unknown> {
|
|
62
|
+
const webStream = getRequestWebStream(event);
|
|
63
|
+
if (!webStream) {
|
|
64
|
+
throw createError({ statusCode: 400, message: "No request body received" });
|
|
65
|
+
}
|
|
66
|
+
return webStream;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async function writeChunk(
|
|
70
|
+
webStream: ReadableStream<unknown>,
|
|
71
|
+
partPath: string,
|
|
72
|
+
chunkIndex: number,
|
|
73
|
+
): Promise<void> {
|
|
74
|
+
const writeStream = fs.createWriteStream(partPath, { flags: chunkIndex === 0 ? "w" : "a" });
|
|
75
|
+
await pipeline(Readable.fromWeb(toNodeWebStream(webStream)), writeStream);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async function enforceSizeLimit(partPath: string): Promise<void> {
|
|
79
|
+
const { size } = await fs.promises.stat(partPath);
|
|
80
|
+
if (size > FILE_SIZE_LIMIT) {
|
|
81
|
+
await fs.promises.unlink(partPath);
|
|
82
|
+
throw createError({ statusCode: 400, message: "File too large" });
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
43
86
|
// The file is sent as a raw (non-multipart) body, split into sequential chunks the client uploads in order (see OpenGeodeWeb-Front's upload_file.ts and OpenGeodeWeb-Back's upload_file route, which use the same protocol). Each chunk is appended to a `.part` file; the last one triggers the existing zip-metadata registration.
|
|
44
87
|
export default defineRawEventHandler(
|
|
45
88
|
schemas.api.local.extensions.upload,
|
|
46
89
|
async (event: H3Event): Promise<LocalExtensionsUploadResponse> => {
|
|
47
|
-
const projectName =
|
|
48
|
-
const
|
|
49
|
-
const totalChunks = requiredQueryInt(event, "total_chunks");
|
|
50
|
-
const chunkIndex = requiredQueryInt(event, "chunk_index");
|
|
51
|
-
if (chunkIndex >= totalChunks) {
|
|
52
|
-
throw createError({ statusCode: 400, message: "chunk_index must be less than total_chunks" });
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const webStream = getRequestWebStream(event);
|
|
56
|
-
if (!webStream) {
|
|
57
|
-
throw createError({ statusCode: 400, message: "No request body received" });
|
|
58
|
-
}
|
|
90
|
+
const { projectName, filename, totalChunks, chunkIndex } = parseUploadQuery(event);
|
|
91
|
+
const webStream = requiredBodyStream(event);
|
|
59
92
|
|
|
60
93
|
const targetPath = targetExtensionFilePath(projectName, filename);
|
|
61
94
|
const partPath = `${targetPath}.part`;
|
|
62
|
-
|
|
63
|
-
await
|
|
64
|
-
|
|
65
|
-
const { size } = await fs.promises.stat(partPath);
|
|
66
|
-
if (size > FILE_SIZE_LIMIT) {
|
|
67
|
-
await fs.promises.unlink(partPath);
|
|
68
|
-
throw createError({ statusCode: 400, message: "File too large" });
|
|
69
|
-
}
|
|
95
|
+
await writeChunk(webStream, partPath, chunkIndex);
|
|
96
|
+
await enforceSizeLimit(partPath);
|
|
70
97
|
|
|
71
98
|
if (chunkIndex < totalChunks - 1) {
|
|
72
99
|
return { statusCode: CODE_200 };
|
package/server/utils/scripts.ts
CHANGED
|
@@ -43,6 +43,36 @@ interface NamedChildProcess extends child_process.ChildProcessByStdio<null, Read
|
|
|
43
43
|
name?: string;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
+
function truncateLine(lineOutput: string): string {
|
|
47
|
+
const halfBuffer = MAX_ERROR_BUFFER_BYTES / 2;
|
|
48
|
+
return byteLength(lineOutput) > halfBuffer
|
|
49
|
+
? `${lineOutput.slice(0, halfBuffer)}…[truncated]`
|
|
50
|
+
: lineOutput;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function trimOutputBuffer(output: string): string {
|
|
54
|
+
let trimmed = output;
|
|
55
|
+
while (byteLength(trimmed) > MAX_ERROR_BUFFER_BYTES) {
|
|
56
|
+
const newline = trimmed.indexOf("\n");
|
|
57
|
+
if (newline === -1) {
|
|
58
|
+
return "";
|
|
59
|
+
}
|
|
60
|
+
trimmed = trimmed.slice(newline + 1);
|
|
61
|
+
}
|
|
62
|
+
return trimmed;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function createOutputRecorder(): { record: (lineOutput: string) => void; read: () => string } {
|
|
66
|
+
let recentOutput = "";
|
|
67
|
+
function record(lineOutput: string): void {
|
|
68
|
+
recentOutput = trimOutputBuffer(`${recentOutput} ${truncateLine(lineOutput)}\n`);
|
|
69
|
+
}
|
|
70
|
+
function read(): string {
|
|
71
|
+
return recentOutput;
|
|
72
|
+
}
|
|
73
|
+
return { record, read };
|
|
74
|
+
}
|
|
75
|
+
|
|
46
76
|
// oxlint-disable-next-line max-lines-per-function typescript/prefer-readonly-parameter-types eslint/require-await
|
|
47
77
|
async function waitForReady(
|
|
48
78
|
child: NamedChildProcess,
|
|
@@ -57,24 +87,8 @@ async function waitForReady(
|
|
|
57
87
|
const readlineStderr = readline.createInterface({
|
|
58
88
|
input: child.stderr,
|
|
59
89
|
});
|
|
60
|
-
|
|
61
|
-
function recordOutput(lineOutput: string): void {
|
|
62
|
-
const safeLine =
|
|
63
|
-
byteLength(lineOutput) > MAX_ERROR_BUFFER_BYTES / 2
|
|
64
|
-
? `${lineOutput.slice(0, MAX_ERROR_BUFFER_BYTES / 2)}…[truncated]`
|
|
65
|
-
: lineOutput;
|
|
66
|
-
recentOutput = `${recentOutput} ${safeLine}\n`;
|
|
67
|
-
while (byteLength(recentOutput) > MAX_ERROR_BUFFER_BYTES) {
|
|
68
|
-
const newline = recentOutput.indexOf("\n");
|
|
69
|
-
if (newline === -1) {
|
|
70
|
-
recentOutput = "";
|
|
71
|
-
break;
|
|
72
|
-
}
|
|
73
|
-
recentOutput = recentOutput.slice(newline + 1);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
90
|
+
const recorder = createOutputRecorder();
|
|
76
91
|
let onLine: ((line: string) => void) | undefined = undefined;
|
|
77
|
-
let onErrLine: ((line: string) => void) | undefined = undefined;
|
|
78
92
|
let onError: ((err: Error) => void) | undefined = undefined;
|
|
79
93
|
let onClose: ((code: number | null) => void) | undefined = undefined;
|
|
80
94
|
let onAbort: (() => void) | undefined = undefined;
|
|
@@ -82,9 +96,7 @@ async function waitForReady(
|
|
|
82
96
|
function cleanup(): void {
|
|
83
97
|
if (onLine) {
|
|
84
98
|
readlineStdout.removeListener("line", onLine);
|
|
85
|
-
|
|
86
|
-
if (onErrLine) {
|
|
87
|
-
readlineStderr.removeListener("line", onErrLine);
|
|
99
|
+
readlineStderr.removeListener("line", onLine);
|
|
88
100
|
}
|
|
89
101
|
if (onError) {
|
|
90
102
|
child.removeListener("error", onError);
|
|
@@ -113,20 +125,12 @@ async function waitForReady(
|
|
|
113
125
|
|
|
114
126
|
onLine = (lineOutput): void => {
|
|
115
127
|
consola.info(`[${child.name}] ${lineOutput}`);
|
|
116
|
-
|
|
128
|
+
recorder.record(lineOutput);
|
|
117
129
|
if (lineOutput.includes(expectedResponse)) {
|
|
118
130
|
becomeReady();
|
|
119
131
|
}
|
|
120
132
|
};
|
|
121
133
|
|
|
122
|
-
onErrLine = (line): void => {
|
|
123
|
-
consola.info(`[${child.name}] ${line}`);
|
|
124
|
-
recordOutput(line);
|
|
125
|
-
if (line.includes(expectedResponse)) {
|
|
126
|
-
becomeReady();
|
|
127
|
-
}
|
|
128
|
-
};
|
|
129
|
-
|
|
130
134
|
onError = (err): void => {
|
|
131
135
|
cleanup();
|
|
132
136
|
reject(err);
|
|
@@ -135,6 +139,7 @@ async function waitForReady(
|
|
|
135
139
|
onClose = (code): void => {
|
|
136
140
|
consola.info(`[${child.name}] exited with code ${code}`);
|
|
137
141
|
cleanup();
|
|
142
|
+
const recentOutput = recorder.read();
|
|
138
143
|
reject(
|
|
139
144
|
new Error(
|
|
140
145
|
`[${child.name}] exited with code ${code} before becoming ready.${recentOutput ? `\nRecent output:\n${recentOutput}` : ""}`,
|
|
@@ -147,7 +152,7 @@ async function waitForReady(
|
|
|
147
152
|
reject(new Error(`[${child.name}] timed out waiting for "${expectedResponse}"`));
|
|
148
153
|
};
|
|
149
154
|
readlineStdout.on("line", onLine);
|
|
150
|
-
readlineStderr.on("line",
|
|
155
|
+
readlineStderr.on("line", onLine);
|
|
151
156
|
child.once("error", onError);
|
|
152
157
|
child.once("close", onClose);
|
|
153
158
|
if (signal) {
|