From 4fcf268789a52a1c6be6d6c80cd054ad2c106ea8 Mon Sep 17 00:00:00 2001 From: svoboda200786 Date: Sat, 16 Aug 2025 09:09:46 +0000 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=B8=D1=82?= =?UTF-8?q?=D1=8C=20furniture.js?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- furniture.js | 144 +++++++++++++++++++++++++-------------------------- 1 file changed, 72 insertions(+), 72 deletions(-) diff --git a/furniture.js b/furniture.js index a9eab03..0e3573a 100644 --- a/furniture.js +++ b/furniture.js @@ -1,73 +1,73 @@ -// server.js - -const express = require('express'); -const path = require('path'); - -const app = express(); -// --- ИЗМЕНЕНИЕ: Используйте порт 3201, как в вашем конфиге прокси --- -const PORT = 3201; - -app.use(express.json()); - -// Раздаем ТОЛЬКО нашу папку 'public' -app.use(express.static(path.join(__dirname, 'public'))); - -// --- УДАЛЕНО: Раздача папок build и jsm больше не нужна --- -// app.use('/build', express.static(path.join(__dirname, 'node_modules/three/build'))); -// app.use('/jsm', express.static(path.join(__dirname, 'node_modules/three/examples/jsm'))); - - -// API эндпоинт для расчета цены (без изменений) -const PRICE_CONFIG = { - edgeBandingPerMeter: 50, - baseWorkCost: 3000, -}; -const MATERIALS_PRICES = { - 'Белый': 1500, - 'Серый': 1650, - 'Черный': 1800, - 'Образец1': 2200, - 'Образец2': 2500, -}; -const PANEL_THICKNESS = 16; - -app.post('/api/calculate-price', (req, res) => { - const params = req.body; - const pricePerM2 = MATERIALS_PRICES[params.materialName]; - if (!pricePerM2) { - return res.status(400).json({ error: 'Invalid material name' }); - } - const { width, height, depth, columns, rows } = params; - const M_IN_MM = 1000; - let totalAreaM2 = 0; - let totalEdgeLengthM = 0; - const innerWidth = width - 2 * PANEL_THICKNESS; - const innerHeight = height - 2 * PANEL_THICKNESS; - const shelfDepth = depth - PANEL_THICKNESS; - totalAreaM2 += (2 * height * depth) / (M_IN_MM * M_IN_MM); - totalAreaM2 += (2 * width * depth) / (M_IN_MM * M_IN_MM); - totalEdgeLengthM += (2 * height + 2 * width) / M_IN_MM; - totalAreaM2 += (innerWidth * innerHeight) / (M_IN_MM * M_IN_MM); - const numDividers = columns - 1; - if (numDividers > 0) { - totalAreaM2 += (numDividers * innerHeight * shelfDepth) / (M_IN_MM * M_IN_MM); - totalEdgeLengthM += (numDividers * innerHeight) / M_IN_MM; - } - const numShelves = rows - 1; - if (numShelves > 0) { - const sectionWidth = (innerWidth - (numDividers * PANEL_THICKNESS)) / columns; - const totalShelfArea = (columns * numShelves * sectionWidth * shelfDepth) / (M_IN_MM * M_IN_MM); - totalAreaM2 += totalShelfArea; - const totalShelfEdgeLength = (columns * numShelves * sectionWidth) / M_IN_MM; - totalEdgeLengthM += totalShelfEdgeLength; - } - const materialCost = totalAreaM2 * pricePerM2; - const edgeBandingCost = totalEdgeLengthM * PRICE_CONFIG.edgeBandingPerMeter; - const finalPrice = PRICE_CONFIG.baseWorkCost + materialCost + edgeBandingCost; - res.json({ price: Math.round(finalPrice) }); -}); - - -app.listen(PORT, () => { - console.log(`Сервер конструктора мебели запущен на порту: ${PORT}`); +// server.js 2 + +const express = require('express'); +const path = require('path'); + +const app = express(); +// --- ИЗМЕНЕНИЕ: Используйте порт 3201, как в вашем конфиге прокси --- +const PORT = 3201; + +app.use(express.json()); + +// Раздаем ТОЛЬКО нашу папку 'public' +app.use(express.static(path.join(__dirname, 'public'))); + +// --- УДАЛЕНО: Раздача папок build и jsm больше не нужна --- +// app.use('/build', express.static(path.join(__dirname, 'node_modules/three/build'))); +// app.use('/jsm', express.static(path.join(__dirname, 'node_modules/three/examples/jsm'))); + + +// API эндпоинт для расчета цены (без изменений) +const PRICE_CONFIG = { + edgeBandingPerMeter: 50, + baseWorkCost: 3000, +}; +const MATERIALS_PRICES = { + 'Белый': 1500, + 'Серый': 1650, + 'Черный': 1800, + 'Образец1': 2200, + 'Образец2': 2500, +}; +const PANEL_THICKNESS = 16; + +app.post('/api/calculate-price', (req, res) => { + const params = req.body; + const pricePerM2 = MATERIALS_PRICES[params.materialName]; + if (!pricePerM2) { + return res.status(400).json({ error: 'Invalid material name' }); + } + const { width, height, depth, columns, rows } = params; + const M_IN_MM = 1000; + let totalAreaM2 = 0; + let totalEdgeLengthM = 0; + const innerWidth = width - 2 * PANEL_THICKNESS; + const innerHeight = height - 2 * PANEL_THICKNESS; + const shelfDepth = depth - PANEL_THICKNESS; + totalAreaM2 += (2 * height * depth) / (M_IN_MM * M_IN_MM); + totalAreaM2 += (2 * width * depth) / (M_IN_MM * M_IN_MM); + totalEdgeLengthM += (2 * height + 2 * width) / M_IN_MM; + totalAreaM2 += (innerWidth * innerHeight) / (M_IN_MM * M_IN_MM); + const numDividers = columns - 1; + if (numDividers > 0) { + totalAreaM2 += (numDividers * innerHeight * shelfDepth) / (M_IN_MM * M_IN_MM); + totalEdgeLengthM += (numDividers * innerHeight) / M_IN_MM; + } + const numShelves = rows - 1; + if (numShelves > 0) { + const sectionWidth = (innerWidth - (numDividers * PANEL_THICKNESS)) / columns; + const totalShelfArea = (columns * numShelves * sectionWidth * shelfDepth) / (M_IN_MM * M_IN_MM); + totalAreaM2 += totalShelfArea; + const totalShelfEdgeLength = (columns * numShelves * sectionWidth) / M_IN_MM; + totalEdgeLengthM += totalShelfEdgeLength; + } + const materialCost = totalAreaM2 * pricePerM2; + const edgeBandingCost = totalEdgeLengthM * PRICE_CONFIG.edgeBandingPerMeter; + const finalPrice = PRICE_CONFIG.baseWorkCost + materialCost + edgeBandingCost; + res.json({ price: Math.round(finalPrice) }); +}); + + +app.listen(PORT, () => { + console.log(`Сервер конструктора мебели запущен на порту: ${PORT}`); }); \ No newline at end of file