From bb7721f8399e5f054ac96bf4f7095b01a6bd91d2 Mon Sep 17 00:00:00 2001 From: counterweight Date: Sat, 8 Feb 2025 01:14:01 +0100 Subject: [PATCH] npubbing works --- .gitignore | 3 +++ index.js | 31 ++++++++++++++++++++++++++++ models/SessionNpubbed.js | 26 ++++++++++++++++++++++++ views/index.ejs | 44 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 104 insertions(+) create mode 100644 models/SessionNpubbed.js diff --git a/.gitignore b/.gitignore index 1170717..9cced06 100644 --- a/.gitignore +++ b/.gitignore @@ -134,3 +134,6 @@ dist .yarn/build-state.yml .yarn/install-state.gz .pnp.* + + +container-data/ \ No newline at end of file diff --git a/index.js b/index.js index da38285..b448ea0 100644 --- a/index.js +++ b/index.js @@ -4,6 +4,7 @@ const cookieParser = require('cookie-parser'); const sequelize = require('./database'); const Session = require('./models/Session'); +const SessionNpubbed = require('./models/SessionNpubbed'); const app = express(); const port = 3000; @@ -18,6 +19,8 @@ sequelize.sync() app.use(cookieParser()); +app.use(express.json()); + app.set('view engine', 'ejs'); app.set('views', './views'); @@ -37,6 +40,34 @@ app.get('/', (req, res) => { res.render('index', { uuid: req.cookies.sessionUuid }); }); + +app.post('/api/session-npubbed', async (req, res) => { + console.log(req.body); + const sessionUuid = req.cookies.sessionUuid; + const npub = req.body.npub; + + if (!sessionUuid || !npub) { + return res.status(400).json({ error: 'Missing session_uuid or npub' }); + } + + console.log("This is the npub: ${npub}"); + + try { + await SessionNpubbed.create({ + sessionNpubbedUuid: uuid.v7(), + sessionUuid: sessionUuid, + npub: npub, + created_at: new Date().toISOString() + }); + + res.json({ message: 'SessionNpubbed record created successfully' }); + } catch (error) { + console.log(error); + console.error('Error creating sessionNpubbed record:', error); + res.status(500).json({ error: 'Failed to create sessionNpubbed record' }); + } +}); + app.listen(port, () => { console.log(`Server started on port ${port}`); }); diff --git a/models/SessionNpubbed.js b/models/SessionNpubbed.js new file mode 100644 index 0000000..39f3266 --- /dev/null +++ b/models/SessionNpubbed.js @@ -0,0 +1,26 @@ +const { DataTypes } = require('sequelize'); +const sequelize = require('../database'); + +const SessionNpubbed = sequelize.define('SessionNpubbed', { + sessionNpubbedUuid: { + type: DataTypes.UUID, + allowNull: false, + unique: true, + primaryKey: true + }, + sessionUuid: { + type: DataTypes.UUID, + allowNull: false, + unique: true, + }, + npub: { + type: DataTypes.STRING, + allowNull: false + }, + created_at: { + type: DataTypes.DATE, + allowNull: false + }, +}); + +module.exports = SessionNpubbed; \ No newline at end of file diff --git a/views/index.ejs b/views/index.ejs index 34b7190..cc34b4a 100644 --- a/views/index.ejs +++ b/views/index.ejs @@ -12,6 +12,50 @@

Now this is some production grade stuff, baby!

Your session's UUID: <%= uuid %>

+ + + \ No newline at end of file