From 93aca73e55a17773ca0965e68583ce6880b07732 Mon Sep 17 00:00:00 2001 From: adrian Date: Thu, 4 Dec 2025 23:13:04 +0100 Subject: [PATCH] =?UTF-8?q?hinzuf=C3=BCgen=20von=20w=C3=B6rtern?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend.js | 32 ++++++++++++++++++++++++++++++++ game/game.html | 11 +++++++++++ game/game.js | 0 game/style.css | 0 imposter.db | Bin 12288 -> 20480 bytes index.html | 5 +++++ index.js | 17 +++++++++++++++++ 7 files changed, 65 insertions(+) create mode 100644 game/game.html create mode 100644 game/game.js create mode 100644 game/style.css diff --git a/backend.js b/backend.js index c561183..14b64a8 100644 --- a/backend.js +++ b/backend.js @@ -45,6 +45,12 @@ app.get('/:sessionId/:username', (req, res) => { }) +app.get('/:sessionId/:username/game', (req, res) => { + const {sessionId, username} = req.params; + + res.sendFile(join (__dirname, 'game', 'game.html')); +}) + //liste an user zurückgeben app.get('/api/user/:sessionId', (req,res) => { const {sessionId} = req.params; @@ -60,6 +66,32 @@ app.get('/api/user/:sessionId', (req,res) => { +app.put(`/api/words/add`, (req,res) => { + const payload = req.body; + + console.log(payload.word, payload.imposterWord) + + db.serialize(() => { + db.run(`CREATE TABLE IF NOT EXISTS words ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + word TEXT NOT NULL, + imposterWord TEXT NOT NULL + )`); + + db.run(`INSERT INTO words (word, imposterWord) VALUES (?, ?)`, + [payload.word, payload.imposterWord], + function (err){ + if (err) { + console.error('inserted words error:', err); + return res.status(500).json({error: err.message}); + } + res.status(201).json({id: this.lastID}) + } + ) + }) +}) + + //ready status updaten app.put('/api/ready/:sessionId', (req,res) => { diff --git a/game/game.html b/game/game.html new file mode 100644 index 0000000..9ec2dde --- /dev/null +++ b/game/game.html @@ -0,0 +1,11 @@ + + + + + + game + + + + + \ No newline at end of file diff --git a/game/game.js b/game/game.js new file mode 100644 index 0000000..e69de29 diff --git a/game/style.css b/game/style.css new file mode 100644 index 0000000..e69de29 diff --git a/imposter.db b/imposter.db index dd82e0609632ac4d33fb136a818b3cf38f84488c..785856b96df800799deda6d59af930e93aac98e8 100644 GIT binary patch delta 426 zcmZojXjs5FL0V9Vfq{V)h+%+fqK>hs5QARtPhS2X3@m(w4EzcF7x@nJ6>cp2%Ud77 z!X~b*%@|pdn3R)RT$qztk{Vx}T3DKzmyFJ3bq;cM3~^Nmadh%=RX|g#k(Zd8ssq%i z*(k-#E-o(4*dz=#vpl~jr5H@Gpy&q+Db#ClDS$y{ih`$Kh^xD6kU~I^r>|pBq=L6= zq=I8;h`*;FP@}J_Ux*G=El8_Eh-*ZMf}cMShx+)yWHNIL@{3DSi^4HfK(%V-GqQ^d z3o|ylf*qH%IiJ5%fRS_aPkD9$K3-s$G4j7-;D5(|ivQGRL4iH|4g$<945G4$r6u`k ri5W#zsio;aMM9_|0*vTtASQif;QzW=P~i^$!~g* +
+ + + +
\ No newline at end of file diff --git a/index.js b/index.js index 888fe0a..719ef8b 100644 --- a/index.js +++ b/index.js @@ -9,3 +9,20 @@ function re_direct () { window.location.href = `/${encodedSession}/${encodedUser}`; } + +async function addWord() { + const word = document.getElementById('word').value.trim(); + const imposterWord = document.getElementById('imposterWord').value.trim(); + + const data = { + word: word, + imposterWord: imposterWord, + } + const res = await fetch (`/api/words/add`, { + method: 'PUT', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify(data) + }); +}