diff --git a/app.js b/app.js index 7e428d6..aaecf90 100644 --- a/app.js +++ b/app.js @@ -14,6 +14,7 @@ const QRCode = require("qrcode"); const app = express(); const port = process.env.PORT; +const DATA_DIR = path.resolve('./data/layouts'); const TeleBot = require("telebot"); const bot = new TeleBot(process.env.TELEBOT); @@ -91,6 +92,43 @@ const pool = new Pool({ connectionString: process.env.DATABASE_URL, }); +// Api für Hallenplaner +app.get('/api/layouts', async (req, res) => { + try { + const files = await fs.readdir(DATA_DIR); + const names = files + .filter(f => f.endsWith('.json')) + .map(f => f.replace('.json', '')); + + res.json(names); + } catch (err) { + res.status(500).json({ error: 'Layouts konnten nicht geladen werden' }); + } +}); + +// GET Einzelnes +app.get('/api/layouts/:name', async (req, res) => { + try { + const file = path.join(DATA_DIR, `${req.params.name}.json`); + const data = await fs.readFile(file, 'utf8'); + res.json(JSON.parse(data)); + } catch { + res.status(404).json({ error: 'Layout nicht gefunden' }); + } +}); + +// ✅ Layout speichern / überschreiben +app.post('/api/layouts/:name', async (req, res) => { + try { + const safeName = req.params.name.replace(/[^a-zA-Z0-9-_]/g, ''); +const file = path.join(DATA_DIR, `${safeName}.json`); + await fs.writeFile(file, JSON.stringify(req.body, null, 2)); + res.json({ status: 'ok' }); + } catch (err) { + res.status(500).json({ error: 'Speichern fehlgeschlagen' }); + } +}); + // Registrierung app.post("/register", async (req, res) => { const { username, email, password } = req.body; diff --git a/data/layouts/heute.json b/data/layouts/heute.json new file mode 100644 index 0000000..ca6f2d7 --- /dev/null +++ b/data/layouts/heute.json @@ -0,0 +1,264 @@ +{ + "hall": { + "length": 27, + "width": 12, + "offset": 3 + }, + "groups": [ + { + "id": "ecdc1024-bf04-443e-aff2-d5a2c159dab6", + "label": "Anlauf", + "x": 5.173443080357143, + "y": -1.9154631696428575, + "rotation": 0 + }, + { + "id": "1d97bae8-6103-4461-ba48-b04742281e32", + "label": "Bank", + "x": -6.848186383928571, + "y": -5.437516741071429, + "rotation": 0 + }, + { + "id": "2e469c2f-6077-461d-9fd7-f1b17cf07ac2", + "label": "Stufenbarren", + "x": -4.053465401785714, + "y": 10.329157366071428, + "rotation": 0 + }, + { + "id": "37c0656a-7ab1-4449-86ad-9f93f641e573", + "label": "Bank", + "x": -1.4038895089285717, + "y": 10.525027901785714, + "rotation": 0 + }, + { + "id": "5211d862-afb3-46e3-8dff-1a1b363bc797", + "label": "Trampolin", + "x": 0, + "y": 0, + "rotation": 0 + }, + { + "id": "b90e6a88-eb72-4b09-80e5-f66f9049181b", + "label": "Sprung", + "x": 5.091729910714286, + "y": -8.800463169642857, + "rotation": 180 + }, + { + "id": "f48b904f-2fad-4320-b025-de56be33c179", + "label": "Reck", + "x": 3.648616071428571, + "y": 10.193404017857143, + "rotation": 0 + }, + { + "id": "8ad1f068-6d2e-40c4-9d41-5b140ba2cf7b", + "label": "Bank", + "x": 6.403208705357144, + "y": -8.287583705357143, + "rotation": 0 + }, + { + "id": "3fdef0fa-66c6-4892-a346-e4711634b3f5", + "label": "Bank", + "x": 6.371417410714286, + "y": 9.891010044642858, + "rotation": 15 + }, + { + "id": "9bbf6ca5-6eaa-4f66-ab72-575230a5d97d", + "label": "Boden", + "x": -5.0391462053571425, + "y": -4.858041294642857, + "rotation": 0 + }, + { + "id": "3aa59445-fb52-47ce-86ca-21b1805dacbd", + "label": "Ringe-1", + "x": -5, + "y": -5, + "rotation": 0 + } + ], + "devices": [ + { + "id": "480937c6-a2ba-41c4-ab88-80fc2e8dc6fd", + "defId": "anlauf", + "x": 0, + "y": 0, + "rotation": 0, + "groupId": "ecdc1024-bf04-443e-aff2-d5a2c159dab6" + }, + { + "id": "8ec4f2da-0f23-49ff-8554-4224aec90150", + "defId": "bank", + "x": 0, + "y": 0, + "rotation": 0, + "groupId": "1d97bae8-6103-4461-ba48-b04742281e32" + }, + { + "id": "05c6b73a-b54f-4cd7-8e1e-3b0e09b69570", + "defId": "matte", + "x": 1, + "y": 0, + "rotation": 0, + "groupId": "2e469c2f-6077-461d-9fd7-f1b17cf07ac2" + }, + { + "id": "81876d0f-cc5f-4a9e-bc02-3ddd5a6212db", + "defId": "matte", + "x": -1, + "y": 0, + "rotation": 0, + "groupId": "2e469c2f-6077-461d-9fd7-f1b17cf07ac2" + }, + { + "id": "0296077c-b15a-4bac-ad4f-c591f2a08c42", + "defId": "barren", + "x": 0, + "y": 0, + "rotation": 0, + "groupId": "2e469c2f-6077-461d-9fd7-f1b17cf07ac2" + }, + { + "id": "3e6d6da0-647e-4981-a2f3-9c9de69bec6e", + "defId": "bank", + "x": 0, + "y": 0, + "rotation": 0, + "groupId": "37c0656a-7ab1-4449-86ad-9f93f641e573" + }, + { + "id": "d704dde4-fff8-4009-904d-4f1bb31eb94f", + "defId": "trampolin", + "x": 0, + "y": 0, + "rotation": 0, + "groupId": "5211d862-afb3-46e3-8dff-1a1b363bc797" + }, + { + "id": "0a54a6e7-84a9-4cbb-b620-43535c521e16", + "defId": "weichboden", + "x": 2.5, + "y": 0, + "rotation": 0, + "groupId": "5211d862-afb3-46e3-8dff-1a1b363bc797" + }, + { + "id": "165b6e99-f8d0-4e1f-94d8-6f052ad06cd6", + "defId": "weichboden", + "x": -2.5, + "y": 0, + "rotation": 0, + "groupId": "5211d862-afb3-46e3-8dff-1a1b363bc797" + }, + { + "id": "4e14a63e-4959-40cc-ba9b-eba33d049bc7", + "defId": "grKasten", + "x": 3, + "y": 0, + "rotation": 90, + "groupId": "5211d862-afb3-46e3-8dff-1a1b363bc797" + }, + { + "id": "742113fa-ebac-4ee7-9e00-93a53e011045", + "defId": "grKasten", + "x": -3, + "y": 0, + "rotation": 90, + "groupId": "5211d862-afb3-46e3-8dff-1a1b363bc797" + }, + { + "id": "2955d6ad-c24c-4a30-b0da-0c2a268bda53", + "defId": "matte", + "x": 0, + "y": 3, + "rotation": 0, + "groupId": "b90e6a88-eb72-4b09-80e5-f66f9049181b" + }, + { + "id": "aa312c1b-a941-4185-be4b-28d6bcd4d5a2", + "defId": "matte", + "x": 0, + "y": 1, + "rotation": 0, + "groupId": "b90e6a88-eb72-4b09-80e5-f66f9049181b" + }, + { + "id": "5a9af8f6-c16e-4873-9cf9-75f46d381c04", + "defId": "bock", + "x": 0, + "y": 0, + "rotation": 0, + "groupId": "b90e6a88-eb72-4b09-80e5-f66f9049181b" + }, + { + "id": "ac9672ea-89fc-4528-b4ce-1ba4482708ad", + "defId": "sprungbrett", + "x": 0, + "y": -1, + "rotation": 0, + "groupId": "b90e6a88-eb72-4b09-80e5-f66f9049181b" + }, + { + "id": "e5fd6cf2-ab9c-49e4-910b-797da4028871", + "defId": "matte", + "x": -1, + "y": 0, + "rotation": 0, + "groupId": "f48b904f-2fad-4320-b025-de56be33c179" + }, + { + "id": "e393d346-b73b-43e1-a409-ebdc75f92d3f", + "defId": "matte", + "x": 1, + "y": 0, + "rotation": 0, + "groupId": "f48b904f-2fad-4320-b025-de56be33c179" + }, + { + "id": "1573dcaf-fb15-4ddc-92af-fa6aeb9d080f", + "defId": "barren", + "x": 0, + "y": 0, + "rotation": 0, + "groupId": "f48b904f-2fad-4320-b025-de56be33c179" + }, + { + "id": "e614dd81-2860-45fa-bc68-fd11290ec4db", + "defId": "bank", + "x": 0, + "y": 0, + "rotation": 0, + "groupId": "8ad1f068-6d2e-40c4-9d41-5b140ba2cf7b" + }, + { + "id": "f1f78983-c8d3-453b-9157-e00aa236578e", + "defId": "bank", + "x": 0, + "y": 0, + "rotation": 0, + "groupId": "3fdef0fa-66c6-4892-a346-e4711634b3f5" + }, + { + "id": "6782b536-5379-4836-9ff9-f65cff58cd87", + "defId": "laeufer", + "x": 0, + "y": 0, + "rotation": 0, + "groupId": "9bbf6ca5-6eaa-4f66-ab72-575230a5d97d" + }, + { + "id": "c3955209-782a-45c6-a8ff-298da3e0fec7", + "defId": "ringe1", + "x": 0, + "y": 0, + "rotation": 0, + "groupId": "3aa59445-fb52-47ce-86ca-21b1805dacbd" + } + ] +} \ No newline at end of file diff --git a/data/layouts/leer.json b/data/layouts/leer.json new file mode 100644 index 0000000..f56d121 --- /dev/null +++ b/data/layouts/leer.json @@ -0,0 +1,71 @@ +{ + "hall": { + "length": 27, + "width": 12, + "offset": 3 + }, + "groups": [ + { + "id": "43a30ac2-c54e-4764-9559-e1283a2f54e2", + "label": "Bank", + "x": 6.700931919642857, + "y": 7.182723214285714, + "rotation": 15 + }, + { + "id": "9e0033c7-f440-43c5-a64a-e7716f5bd15d", + "label": "Bank", + "x": 7.7357310267857144, + "y": 2.806824776785714, + "rotation": 15 + }, + { + "id": "f5834127-5a25-43ed-b34a-33060f40e3e0", + "label": "Bank", + "x": 6.751556919642857, + "y": -7.141891741071428, + "rotation": 165 + }, + { + "id": "77ce9809-b0e0-4826-a52f-f399fad86bd7", + "label": "Bank", + "x": 7.985691964285714, + "y": -2.4423549107142857, + "rotation": 165 + } + ], + "devices": [ + { + "id": "41e75ffc-24e2-448a-93d7-397dccabdc34", + "defId": "bank", + "x": 0, + "y": 0, + "rotation": 0, + "groupId": "43a30ac2-c54e-4764-9559-e1283a2f54e2" + }, + { + "id": "7ba79d81-9f05-4b23-bf11-6460b53ef8b0", + "defId": "bank", + "x": 0, + "y": 0, + "rotation": 0, + "groupId": "9e0033c7-f440-43c5-a64a-e7716f5bd15d" + }, + { + "id": "5dde21f8-2a8d-42d8-abf5-3f8a2dfd8994", + "defId": "bank", + "x": 0, + "y": 0, + "rotation": 0, + "groupId": "f5834127-5a25-43ed-b34a-33060f40e3e0" + }, + { + "id": "76cda43b-d5c1-4adf-9a40-0b7e7152cc40", + "defId": "bank", + "x": 0, + "y": 0, + "rotation": 0, + "groupId": "77ce9809-b0e0-4826-a52f-f399fad86bd7" + } + ] +} \ No newline at end of file diff --git a/data/layouts/test.json b/data/layouts/test.json new file mode 100644 index 0000000..7302136 --- /dev/null +++ b/data/layouts/test.json @@ -0,0 +1,102 @@ +{ + "hall": { + "length": 27, + "width": 12, + "offset": 3 + }, + "groups": [ + { + "id": "2b2904a6-71b5-499c-9f59-ca7060f18f6f", + "label": "Pferd-Aufbau", + "x": 4.451986607142857, + "y": -9.869313616071429, + "rotation": 0 + }, + { + "id": "7c16964f-aa81-4813-bb21-cef0b88abbf5", + "label": "Kasten (fest)", + "x": 3.225937499999999, + "y": 6.559252232142857, + "rotation": 0 + }, + { + "id": "2c4366b0-35a7-456f-b4ff-c54ed6ee1afe", + "label": "Matte", + "x": 0, + "y": 0, + "rotation": 0 + }, + { + "id": "765aaf47-fc9f-47c5-a7dc-853bea7d6057", + "label": "Matte", + "x": -0.0179296875, + "y": -2.1633147321428567, + "rotation": 0 + }, + { + "id": "9fe8695b-f0d6-40b1-bb6a-1cf175ea73fd", + "label": "Matte", + "x": 0.021997767857142855, + "y": -4.350435267857143, + "rotation": 0 + } + ], + "devices": [ + { + "id": "a7eb0eba-fd0e-4702-856c-723c53672b66", + "defId": "matte", + "x": 0, + "y": -0.75, + "rotation": 90, + "groupId": "2b2904a6-71b5-499c-9f59-ca7060f18f6f" + }, + { + "id": "a8cc2833-de95-4db4-b222-fee58b995585", + "defId": "matte", + "x": 0, + "y": 0.75, + "rotation": 90, + "groupId": "2b2904a6-71b5-499c-9f59-ca7060f18f6f" + }, + { + "id": "defaecdb-8b18-4a3b-b3a0-8233c9004bb8", + "defId": "pferd", + "x": 0, + "y": 0, + "rotation": 0, + "groupId": "2b2904a6-71b5-499c-9f59-ca7060f18f6f" + }, + { + "id": "50d126d7-9d36-4c98-8edb-1f6d7ac6f419", + "defId": "kasten", + "x": 0, + "y": 0, + "rotation": 0, + "groupId": "7c16964f-aa81-4813-bb21-cef0b88abbf5" + }, + { + "id": "f4d3cccf-5f26-4553-bbc0-ca3ff81ae169", + "defId": "matte", + "x": 0, + "y": 0, + "rotation": 0, + "groupId": "2c4366b0-35a7-456f-b4ff-c54ed6ee1afe" + }, + { + "id": "f4292036-5dac-4edc-aac9-5e60f9fc5e00", + "defId": "matte", + "x": 0, + "y": 0, + "rotation": 0, + "groupId": "765aaf47-fc9f-47c5-a7dc-853bea7d6057" + }, + { + "id": "6cb7a7f5-a89f-4aa2-9202-aed7bfd668af", + "defId": "matte", + "x": 0, + "y": 0, + "rotation": 0, + "groupId": "9fe8695b-f0d6-40b1-bb6a-1cf175ea73fd" + } + ] +} \ No newline at end of file