fix: address code review comments
- vite.config.ts: fix __dirname for ESM, add 1MB payload limit + JSON validation - MapViewer.tsx: remove broken window.isTransforming checks, fix callback order - EditorPage.tsx: derive undoCount from historyManager in handleTransformEnd - package.json: support Node 20 or 22 in engines
This commit is contained in:
+1
-1
@@ -44,6 +44,6 @@
|
|||||||
"vite": "^8.0.4"
|
"vite": "^8.0.4"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=22.12.0"
|
"node": ">=20.19.0 || >=22.12.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -252,8 +252,6 @@ export function EditorPage(): React.JSX.Element {
|
|||||||
newMapNodes[nodeIndex] = updatedNode;
|
newMapNodes[nodeIndex] = updatedNode;
|
||||||
return { ...prev, mapNodes: newMapNodes };
|
return { ...prev, mapNodes: newMapNodes };
|
||||||
});
|
});
|
||||||
setUndoCount((prev) => prev + 1);
|
|
||||||
console.log("Node transformed:", nodeIndex);
|
|
||||||
},
|
},
|
||||||
[sceneData],
|
[sceneData],
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -40,7 +40,6 @@ export default function MapViewer({
|
|||||||
|
|
||||||
const handleTransformMouseUp = () => {
|
const handleTransformMouseUp = () => {
|
||||||
isTransforming.current = false;
|
isTransforming.current = false;
|
||||||
onTransformEnd?.();
|
|
||||||
|
|
||||||
if (selectedNodeIndex !== null) {
|
if (selectedNodeIndex !== null) {
|
||||||
const obj = objectsMapRef.current.get(selectedNodeIndex);
|
const obj = objectsMapRef.current.get(selectedNodeIndex);
|
||||||
@@ -53,9 +52,12 @@ export default function MapViewer({
|
|||||||
rotation: [obj.rotation.x, obj.rotation.y, obj.rotation.z],
|
rotation: [obj.rotation.x, obj.rotation.y, obj.rotation.z],
|
||||||
scale: [obj.scale.x, obj.scale.y, obj.scale.z],
|
scale: [obj.scale.x, obj.scale.y, obj.scale.z],
|
||||||
};
|
};
|
||||||
|
// Call onNodeTransform BEFORE onTransformEnd so history captures final state
|
||||||
onNodeTransform?.(selectedNodeIndex, updatedNode);
|
onNodeTransform?.(selectedNodeIndex, updatedNode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onTransformEnd?.();
|
||||||
};
|
};
|
||||||
|
|
||||||
const [selectedObject, setSelectedObject] = useState<THREE.Object3D | null>(
|
const [selectedObject, setSelectedObject] = useState<THREE.Object3D | null>(
|
||||||
@@ -91,11 +93,7 @@ export default function MapViewer({
|
|||||||
<group
|
<group
|
||||||
onClick={(e: unknown) => {
|
onClick={(e: unknown) => {
|
||||||
(e as { stopPropagation?: () => void }).stopPropagation?.();
|
(e as { stopPropagation?: () => void }).stopPropagation?.();
|
||||||
if (
|
|
||||||
!(window as unknown as { isTransforming?: boolean }).isTransforming
|
|
||||||
) {
|
|
||||||
onSelectNode(null);
|
onSelectNode(null);
|
||||||
}
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{sceneData.mapNodes.map((node, index) => {
|
{sceneData.mapNodes.map((node, index) => {
|
||||||
@@ -230,11 +228,7 @@ function ModelNodeWithRef({
|
|||||||
object={instance}
|
object={instance}
|
||||||
onClick={(e: unknown) => {
|
onClick={(e: unknown) => {
|
||||||
(e as { stopPropagation?: () => void }).stopPropagation?.();
|
(e as { stopPropagation?: () => void }).stopPropagation?.();
|
||||||
if (
|
|
||||||
!(window as unknown as { isTransforming?: boolean }).isTransforming
|
|
||||||
) {
|
|
||||||
onSelectNode(index);
|
onSelectNode(index);
|
||||||
}
|
|
||||||
}}
|
}}
|
||||||
onPointerEnter={(e: unknown) => {
|
onPointerEnter={(e: unknown) => {
|
||||||
(e as { stopPropagation?: () => void }).stopPropagation?.();
|
(e as { stopPropagation?: () => void }).stopPropagation?.();
|
||||||
@@ -292,11 +286,7 @@ function FallbackNodeWithRef({
|
|||||||
scale={node.scale}
|
scale={node.scale}
|
||||||
onClick={(e: unknown) => {
|
onClick={(e: unknown) => {
|
||||||
(e as { stopPropagation?: () => void }).stopPropagation?.();
|
(e as { stopPropagation?: () => void }).stopPropagation?.();
|
||||||
if (
|
|
||||||
!(window as unknown as { isTransforming?: boolean }).isTransforming
|
|
||||||
) {
|
|
||||||
onSelectNode(index);
|
onSelectNode(index);
|
||||||
}
|
|
||||||
}}
|
}}
|
||||||
onPointerEnter={(e: unknown) => {
|
onPointerEnter={(e: unknown) => {
|
||||||
(e as { stopPropagation?: () => void }).stopPropagation?.();
|
(e as { stopPropagation?: () => void }).stopPropagation?.();
|
||||||
|
|||||||
+42
-6
@@ -2,9 +2,14 @@ import { defineConfig } from "vite";
|
|||||||
import react from "@vitejs/plugin-react";
|
import react from "@vitejs/plugin-react";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import fs from "node:fs";
|
import fs from "node:fs";
|
||||||
|
import { fileURLToPath } from "node:url";
|
||||||
import type { ViteDevServer } from "vite";
|
import type { ViteDevServer } from "vite";
|
||||||
import type { IncomingMessage, ServerResponse } from "http";
|
import type { IncomingMessage, ServerResponse } from "http";
|
||||||
|
|
||||||
|
const __dirname = fileURLToPath(new URL(".", import.meta.url));
|
||||||
|
|
||||||
|
const MAX_MAP_PAYLOAD_BYTES = 1024 * 1024; // 1MB limit
|
||||||
|
|
||||||
const saveMapPlugin = () => ({
|
const saveMapPlugin = () => ({
|
||||||
name: "save-map-api",
|
name: "save-map-api",
|
||||||
configureServer(server: ViteDevServer) {
|
configureServer(server: ViteDevServer) {
|
||||||
@@ -12,20 +17,52 @@ const saveMapPlugin = () => ({
|
|||||||
"/api/save-map",
|
"/api/save-map",
|
||||||
async (req: IncomingMessage, res: ServerResponse) => {
|
async (req: IncomingMessage, res: ServerResponse) => {
|
||||||
if (req.method !== "POST") {
|
if (req.method !== "POST") {
|
||||||
res.writeHead(405).end();
|
res.writeHead(405, { "Content-Type": "application/json" });
|
||||||
|
res.end(JSON.stringify({ error: "Method not allowed" }));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = "";
|
let body = "";
|
||||||
req.on("data", (chunk: Buffer) => (body += chunk.toString()));
|
let bodySize = 0;
|
||||||
req.on("end", () => {
|
let requestAborted = false;
|
||||||
|
|
||||||
|
req.on("data", (chunk: Buffer) => {
|
||||||
|
if (requestAborted) return;
|
||||||
|
bodySize += chunk.length;
|
||||||
|
if (bodySize > MAX_MAP_PAYLOAD_BYTES) {
|
||||||
|
requestAborted = true;
|
||||||
|
res.writeHead(413, { "Content-Type": "application/json" });
|
||||||
|
res.end(JSON.stringify({ error: "Payload too large" }));
|
||||||
|
req.destroy();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
body += chunk.toString();
|
||||||
|
});
|
||||||
|
|
||||||
|
req.on("error", (err: Error) => {
|
||||||
|
if (!res.headersSent) {
|
||||||
|
res.writeHead(400, { "Content-Type": "application/json" });
|
||||||
|
res.end(JSON.stringify({ error: err.message }));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
req.on("end", async () => {
|
||||||
|
if (requestAborted) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
const parsedBody = JSON.parse(body);
|
||||||
const mapPath = path.resolve(__dirname, "public/map.json");
|
const mapPath = path.resolve(__dirname, "public/map.json");
|
||||||
fs.writeFileSync(mapPath, body);
|
await fs.promises.writeFile(
|
||||||
|
mapPath,
|
||||||
|
JSON.stringify(parsedBody, null, 2),
|
||||||
|
"utf8",
|
||||||
|
);
|
||||||
res.writeHead(200, { "Content-Type": "application/json" });
|
res.writeHead(200, { "Content-Type": "application/json" });
|
||||||
res.end(JSON.stringify({ success: true }));
|
res.end(JSON.stringify({ success: true }));
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
res.writeHead(500).end(
|
const statusCode = err instanceof SyntaxError ? 400 : 500;
|
||||||
|
res.writeHead(statusCode, { "Content-Type": "application/json" });
|
||||||
|
res.end(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
error: err instanceof Error ? err.message : "Unknown error",
|
error: err instanceof Error ? err.message : "Unknown error",
|
||||||
}),
|
}),
|
||||||
@@ -36,7 +73,6 @@ const saveMapPlugin = () => ({
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
import { fileURLToPath } from "node:url";
|
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [react(), saveMapPlugin()],
|
plugins: [react(), saveMapPlugin()],
|
||||||
|
|||||||
Reference in New Issue
Block a user