From fa928fa38075b8142e226f03b0a5349ea4ead704 Mon Sep 17 00:00:00 2001 From: CodeByStella Date: Wed, 28 Jan 2026 17:26:20 +0900 Subject: [PATCH] feat: Add real-time chat functionality with Socket.io and role-based features - Add Socket.io server integration with role-based authentication - Implement chat container UI with message display and input - Add role-based features: moderators, VIPs, administrators, broadcaster, bot - Implement moderator actions: timeout, ban, delete messages - Add role hierarchy system for permission management - Update User model to support all chat roles - Add chat styling with dark mode support - Update CSP to allow Socket.io connections Chat supports real-time messaging, role-based permissions, and moderator controls for managing chat interactions. --- index.html | 417 ++++++------ package-lock.json | 985 ++++++++++++++++++++++++++++- package.json | 9 +- public/service-worker.js | 193 +++--- server.js | 350 +++++++++- src/controllers/AuthControllers.js | 207 +++--- src/css/style.css | 306 ++++++++- src/js/main.js | 343 ++++++++++ src/middleware/auth.js | 65 +- src/models/User.js | 84 +-- 10 files changed, 2463 insertions(+), 496 deletions(-) diff --git a/index.html b/index.html index b747868..a361df8 100644 --- a/index.html +++ b/index.html @@ -1,196 +1,261 @@ - + - - - - - - - - + + + + + - - - DevStream | Live Coding & Game Development - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- -

DevStream

-
- - -
-
- - - - - -
- - -
- - -
-

Live Streams

- - -
- + /> + + + DevStream | Live Coding & Game Development + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

DevStream

+
+ + +
+
+ + + + + +
+ + +
+ +
+

Live Streams

+ + +
+ +
-
-
- - -
-

Popular Tags

-
- JavaScript - Python - Rust - English - Linux -
-
-
+ +
+
+
+

Loading live streams...

+
+
+ - - + +
+

Popular Tags

+
+ JavaScript + Python + Rust + English + Linux +
+
+ + +
+

Live Chat

+
+
+
+ + +
+
+
+ - - + + - + + - + + + diff --git a/package-lock.json b/package-lock.json index 6c6e8e1..f7105c1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,9 +10,14 @@ "license": "ISC", "dependencies": { "@fortawesome/fontawesome-free": "^6.5.2", + "bcrypt": "^6.0.0", "bootstrap": "^5.3.3", "cors": "^2.8.5", - "express": "^5.2.1" + "dotenv": "^17.2.3", + "express": "^5.2.1", + "jsonwebtoken": "^9.0.3", + "mongoose": "^9.1.5", + "socket.io": "^4.8.3" }, "devDependencies": { "eslint": "^8.57.0", @@ -491,6 +496,15 @@ "deprecated": "Use @eslint/object-schema instead", "dev": true }, + "node_modules/@mongodb-js/saslprep": { + "version": "1.4.5", + "resolved": "https://registry.npmjs.org/@mongodb-js/saslprep/-/saslprep-1.4.5.tgz", + "integrity": "sha512-k64Lbyb7ycCSXHSLzxVdb2xsKGPMvYZfCICXvDsI8Z65CeWQzTEKS4YmGbnqw+U9RBvLPTsB6UCmwkgsDTGWIw==", + "license": "MIT", + "dependencies": { + "sparse-bitfield": "^3.0.3" + } + }, "node_modules/@nodelib/fs.scandir": { "version": "2.1.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", @@ -822,12 +836,51 @@ "win32" ] }, + "node_modules/@socket.io/component-emitter": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/@socket.io/component-emitter/-/component-emitter-3.1.2.tgz", + "integrity": "sha512-9BCxFwvbGg/RsZK9tjXd8s4UcwR0MWeFQ1XEKIQVVvAGJyINdrqKMcTRyLoK8Rse1GjzLV9cwjWV1olXRWEXVA==", + "license": "MIT" + }, + "node_modules/@types/cors": { + "version": "2.8.19", + "resolved": "https://registry.npmjs.org/@types/cors/-/cors-2.8.19.tgz", + "integrity": "sha512-mFNylyeyqN93lfe/9CSxOGREz8cpzAhH+E93xJ4xWQf62V8sQ/24reV2nyzUWM6H6Xji+GGHpkbLe7pVoUEskg==", + "license": "MIT", + "dependencies": { + "@types/node": "*" + } + }, "node_modules/@types/estree": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.8.tgz", "integrity": "sha512-dWHzHa2WqEXI/O1E9OjrocMTKJl2mSrEolh1Iomrv6U+JuNwaHXsXx9bLu5gG7BUWFIN0skIQJQ/L1rIex4X6w==", "dev": true }, + "node_modules/@types/node": { + "version": "25.0.10", + "resolved": "https://registry.npmjs.org/@types/node/-/node-25.0.10.tgz", + "integrity": "sha512-zWW5KPngR/yvakJgGOmZ5vTBemDoSqF3AcV/LrO5u5wTWyEAVVh+IT39G4gtyAkh3CtTZs8aX/yRM82OfzHJRg==", + "license": "MIT", + "dependencies": { + "undici-types": "~7.16.0" + } + }, + "node_modules/@types/webidl-conversions": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/@types/webidl-conversions/-/webidl-conversions-7.0.3.tgz", + "integrity": "sha512-CiJJvcRtIgzadHCYXw7dqEnMNRjhGZlYK05Mj9OyktqV8uVT8fD2BFOB7S1uwBE3Kj2Z+4UyPmFw/Ixgw/LAlA==", + "license": "MIT" + }, + "node_modules/@types/whatwg-url": { + "version": "13.0.0", + "resolved": "https://registry.npmjs.org/@types/whatwg-url/-/whatwg-url-13.0.0.tgz", + "integrity": "sha512-N8WXpbE6Wgri7KUSvrmQcqrMllKZ9uxkYWMt+mCSGwNc0Hsw9VQTW7ApqI4XNrx6/SaM2QQJCzMPDEXE058s+Q==", + "license": "MIT", + "dependencies": { + "@types/webidl-conversions": "*" + } + }, "node_modules/@ungap/structured-clone": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/@ungap/structured-clone/-/structured-clone-1.3.0.tgz", @@ -852,7 +905,6 @@ "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.15.0.tgz", "integrity": "sha512-NZyJarBfL7nWwIq+FDL6Zp/yHEhePMNnnJ0y3qfieCrmNvYct8uvtiV41UvlSe6apAfk0fY1FbWx+NwfmpvtTg==", "dev": true, - "peer": true, "bin": { "acorn": "bin/acorn" }, @@ -921,6 +973,29 @@ "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", "dev": true }, + "node_modules/base64id": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/base64id/-/base64id-2.0.0.tgz", + "integrity": "sha512-lGe34o6EHj9y3Kts9R4ZYs/Gr+6N7MCaMlIFA3F1R2O5/m7K06AxfSeO5530PEERE6/WyEg3lsuyw4GHlPZHog==", + "license": "MIT", + "engines": { + "node": "^4.5.0 || >= 5.9" + } + }, + "node_modules/bcrypt": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/bcrypt/-/bcrypt-6.0.0.tgz", + "integrity": "sha512-cU8v/EGSrnH+HnxV2z0J7/blxH8gq7Xh2JFT6Aroax7UohdmiJJlxApMxtKfuI7z68NvvVcmR78k2LbT6efhRg==", + "hasInstallScript": true, + "license": "MIT", + "dependencies": { + "node-addon-api": "^8.3.0", + "node-gyp-build": "^4.8.4" + }, + "engines": { + "node": ">= 18" + } + }, "node_modules/body-parser": { "version": "2.2.1", "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-2.2.1.tgz", @@ -973,6 +1048,21 @@ "concat-map": "0.0.1" } }, + "node_modules/bson": { + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/bson/-/bson-7.1.1.tgz", + "integrity": "sha512-TtJgBB+QyOlWjrbM+8bRgH84VM/xrDjyBFgSgGrfZF4xvt6gbEDtcswm27Tn9F9TWsjQybxT8b8VpCP/oJK4Dw==", + "license": "Apache-2.0", + "engines": { + "node": ">=20.19.0" + } + }, + "node_modules/buffer-equal-constant-time": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz", + "integrity": "sha512-zRpUiDwd/xk6ADqPMATG8vc9VPrkck7T07OIx0gnjmJAnHnTVXNQG3vfvWNuiZIkwu9KrKdA1iJKfsfTVxE6NA==", + "license": "BSD-3-Clause" + }, "node_modules/bytes": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", @@ -1170,6 +1260,18 @@ "node": ">=6.0.0" } }, + "node_modules/dotenv": { + "version": "17.2.3", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-17.2.3.tgz", + "integrity": "sha512-JVUnt+DUIzu87TABbhPmNfVdBDt18BLOWjMUFJMSi/Qqg7NTYtabbvSNJGOJ7afbRuv9D/lngizHtP7QyLQ+9w==", + "license": "BSD-2-Clause", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://dotenvx.com" + } + }, "node_modules/dunder-proto": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", @@ -1184,6 +1286,15 @@ "node": ">= 0.4" } }, + "node_modules/ecdsa-sig-formatter": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.11.tgz", + "integrity": "sha512-nagl3RYrbNv6kQkeJIpt6NJZy8twLB/2vtz6yN9Z4vRKHN4/QZJIEbqohALSgwKdnksuY3k5Addp5lg8sVoVcQ==", + "license": "Apache-2.0", + "dependencies": { + "safe-buffer": "^5.0.1" + } + }, "node_modules/ee-first": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", @@ -1199,6 +1310,78 @@ "node": ">= 0.8" } }, + "node_modules/engine.io": { + "version": "6.6.5", + "resolved": "https://registry.npmjs.org/engine.io/-/engine.io-6.6.5.tgz", + "integrity": "sha512-2RZdgEbXmp5+dVbRm0P7HQUImZpICccJy7rN7Tv+SFa55pH+lxnuw6/K1ZxxBfHoYpSkHLAO92oa8O4SwFXA2A==", + "license": "MIT", + "dependencies": { + "@types/cors": "^2.8.12", + "@types/node": ">=10.0.0", + "accepts": "~1.3.4", + "base64id": "2.0.0", + "cookie": "~0.7.2", + "cors": "~2.8.5", + "debug": "~4.4.1", + "engine.io-parser": "~5.2.1", + "ws": "~8.18.3" + }, + "engines": { + "node": ">=10.2.0" + } + }, + "node_modules/engine.io-parser": { + "version": "5.2.3", + "resolved": "https://registry.npmjs.org/engine.io-parser/-/engine.io-parser-5.2.3.tgz", + "integrity": "sha512-HqD3yTBfnBxIrbnM1DoD6Pcq8NECnh8d4As1Qgh0z5Gg3jRRIqijury0CL3ghu/edArpUYiYqQiDUQBIs4np3Q==", + "license": "MIT", + "engines": { + "node": ">=10.0.0" + } + }, + "node_modules/engine.io/node_modules/accepts": { + "version": "1.3.8", + "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz", + "integrity": "sha512-PYAthTa2m2VKxuvSD3DPC/Gy+U+sOA1LAuT8mkmRuvw+NACSaeXEQ+NHcVF7rONl6qcaxV3Uuemwawk+7+SJLw==", + "license": "MIT", + "dependencies": { + "mime-types": "~2.1.34", + "negotiator": "0.6.3" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/engine.io/node_modules/mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/engine.io/node_modules/mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "license": "MIT", + "dependencies": { + "mime-db": "1.52.0" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/engine.io/node_modules/negotiator": { + "version": "0.6.3", + "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz", + "integrity": "sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, "node_modules/es-define-property": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz", @@ -1291,7 +1474,6 @@ "integrity": "sha512-ypowyDxpVSYpkXr9WPv2PAZCtNip1Mv5KTW0SCurXv/9iOpcrH9PaqUElksqEB6pChqHGDRCFTyrZlGhnLNGiA==", "deprecated": "This version is no longer supported. Please see https://eslint.org/version-support for other options.", "dev": true, - "peer": true, "dependencies": { "@eslint-community/eslint-utils": "^4.2.0", "@eslint-community/regexpp": "^4.6.1", @@ -1939,6 +2121,58 @@ "integrity": "sha512-Bdboy+l7tA3OGW6FjyFHWkP5LuByj1Tk33Ljyq0axyzdk9//JSi2u3fP1QSmd1KNwq6VOKYGlAu87CisVir6Pw==", "dev": true }, + "node_modules/jsonwebtoken": { + "version": "9.0.3", + "resolved": "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-9.0.3.tgz", + "integrity": "sha512-MT/xP0CrubFRNLNKvxJ2BYfy53Zkm++5bX9dtuPbqAeQpTVe0MQTFhao8+Cp//EmJp244xt6Drw/GVEGCUj40g==", + "license": "MIT", + "dependencies": { + "jws": "^4.0.1", + "lodash.includes": "^4.3.0", + "lodash.isboolean": "^3.0.3", + "lodash.isinteger": "^4.0.4", + "lodash.isnumber": "^3.0.3", + "lodash.isplainobject": "^4.0.6", + "lodash.isstring": "^4.0.1", + "lodash.once": "^4.0.0", + "ms": "^2.1.1", + "semver": "^7.5.4" + }, + "engines": { + "node": ">=12", + "npm": ">=6" + } + }, + "node_modules/jwa": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/jwa/-/jwa-2.0.1.tgz", + "integrity": "sha512-hRF04fqJIP8Abbkq5NKGN0Bbr3JxlQ+qhZufXVr0DvujKy93ZCbXZMHDL4EOtodSbCWxOqR8MS1tXA5hwqCXDg==", + "license": "MIT", + "dependencies": { + "buffer-equal-constant-time": "^1.0.1", + "ecdsa-sig-formatter": "1.0.11", + "safe-buffer": "^5.0.1" + } + }, + "node_modules/jws": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/jws/-/jws-4.0.1.tgz", + "integrity": "sha512-EKI/M/yqPncGUUh44xz0PxSidXFr/+r0pA70+gIYhjv+et7yxM+s29Y+VGDkovRofQem0fs7Uvf4+YmAdyRduA==", + "license": "MIT", + "dependencies": { + "jwa": "^2.0.1", + "safe-buffer": "^5.0.1" + } + }, + "node_modules/kareem": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/kareem/-/kareem-3.0.0.tgz", + "integrity": "sha512-RKhaOBSPN8L7y4yAgNhDT2602G5FD6QbOIISbjN9D6mjHPeqeg7K+EB5IGSU5o81/X2Gzm3ICnAvQW3x3OP8HA==", + "license": "Apache-2.0", + "engines": { + "node": ">=18.0.0" + } + }, "node_modules/keyv": { "version": "4.5.4", "resolved": "https://registry.npmjs.org/keyv/-/keyv-4.5.4.tgz", @@ -1976,12 +2210,54 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/lodash.includes": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/lodash.includes/-/lodash.includes-4.3.0.tgz", + "integrity": "sha512-W3Bx6mdkRTGtlJISOvVD/lbqjTlPPUDTMnlXZFnVwi9NKJ6tiAk6LVdlhZMm17VZisqhKcgzpO5Wz91PCt5b0w==", + "license": "MIT" + }, + "node_modules/lodash.isboolean": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/lodash.isboolean/-/lodash.isboolean-3.0.3.tgz", + "integrity": "sha512-Bz5mupy2SVbPHURB98VAcw+aHh4vRV5IPNhILUCsOzRmsTmSQ17jIuqopAentWoehktxGd9e/hbIXq980/1QJg==", + "license": "MIT" + }, + "node_modules/lodash.isinteger": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/lodash.isinteger/-/lodash.isinteger-4.0.4.tgz", + "integrity": "sha512-DBwtEWN2caHQ9/imiNeEA5ys1JoRtRfY3d7V9wkqtbycnAmTvRRmbHKDV4a0EYc678/dia0jrte4tjYwVBaZUA==", + "license": "MIT" + }, + "node_modules/lodash.isnumber": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/lodash.isnumber/-/lodash.isnumber-3.0.3.tgz", + "integrity": "sha512-QYqzpfwO3/CWf3XP+Z+tkQsfaLL/EnUlXWVkIk5FUPc4sBdTehEqZONuyRt2P67PXAk+NXmTBcc97zw9t1FQrw==", + "license": "MIT" + }, + "node_modules/lodash.isplainobject": { + "version": "4.0.6", + "resolved": "https://registry.npmjs.org/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz", + "integrity": "sha512-oSXzaWypCMHkPC3NvBEaPHf0KsA5mvPrOPgQWDsbg8n7orZ290M0BmC/jgRZ4vcJ6DTAhjrsSYgdsW/F+MFOBA==", + "license": "MIT" + }, + "node_modules/lodash.isstring": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/lodash.isstring/-/lodash.isstring-4.0.1.tgz", + "integrity": "sha512-0wJxfxH1wgO3GrbuP+dTTk7op+6L41QCXbGINEmD+ny/G/eCqGzxyCsh7159S+mgDDcoarnBw6PC1PS5+wUGgw==", + "license": "MIT" + }, "node_modules/lodash.merge": { "version": "4.6.2", "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz", "integrity": "sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==", "dev": true }, + "node_modules/lodash.once": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/lodash.once/-/lodash.once-4.1.1.tgz", + "integrity": "sha512-Sb487aTOCr9drQVL8pIxOzVhafOjZN9UU54hiN8PU3uAiSV7lx1yYNpbNmex2PK6dSJoNTSJUUswT651yww3Mg==", + "license": "MIT" + }, "node_modules/math-intrinsics": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz", @@ -2000,6 +2276,12 @@ "node": ">= 0.8" } }, + "node_modules/memory-pager": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/memory-pager/-/memory-pager-1.5.0.tgz", + "integrity": "sha512-ZS4Bp4r/Zoeq6+NLJpP+0Zzm0pR8whtGPf1XExKLJBAczGMnSi3It14OiNCStjQjM6NU1okjQGSxgEZN8eBYKg==", + "license": "MIT" + }, "node_modules/merge-descriptors": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-2.0.0.tgz", @@ -2049,6 +2331,104 @@ "node": "*" } }, + "node_modules/mongodb": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-7.0.0.tgz", + "integrity": "sha512-vG/A5cQrvGGvZm2mTnCSz1LUcbOPl83hfB6bxULKQ8oFZauyox/2xbZOoGNl+64m8VBrETkdGCDBdOsCr3F3jg==", + "license": "Apache-2.0", + "dependencies": { + "@mongodb-js/saslprep": "^1.3.0", + "bson": "^7.0.0", + "mongodb-connection-string-url": "^7.0.0" + }, + "engines": { + "node": ">=20.19.0" + }, + "peerDependencies": { + "@aws-sdk/credential-providers": "^3.806.0", + "@mongodb-js/zstd": "^7.0.0", + "gcp-metadata": "^7.0.1", + "kerberos": "^7.0.0", + "mongodb-client-encryption": ">=7.0.0 <7.1.0", + "snappy": "^7.3.2", + "socks": "^2.8.6" + }, + "peerDependenciesMeta": { + "@aws-sdk/credential-providers": { + "optional": true + }, + "@mongodb-js/zstd": { + "optional": true + }, + "gcp-metadata": { + "optional": true + }, + "kerberos": { + "optional": true + }, + "mongodb-client-encryption": { + "optional": true + }, + "snappy": { + "optional": true + }, + "socks": { + "optional": true + } + } + }, + "node_modules/mongodb-connection-string-url": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/mongodb-connection-string-url/-/mongodb-connection-string-url-7.0.1.tgz", + "integrity": "sha512-h0AZ9A7IDVwwHyMxmdMXKy+9oNlF0zFoahHiX3vQ8e3KFcSP3VmsmfvtRSuLPxmyv2vjIDxqty8smTgie/SNRQ==", + "license": "Apache-2.0", + "dependencies": { + "@types/whatwg-url": "^13.0.0", + "whatwg-url": "^14.1.0" + }, + "engines": { + "node": ">=20.19.0" + } + }, + "node_modules/mongoose": { + "version": "9.1.5", + "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-9.1.5.tgz", + "integrity": "sha512-N6gypEO+wLmZp8kCYNQmrEWxVMT0KhyHvVttBZoKA/1ngY7aUsBjqHzCPtDgz+i8JAnqMOiEKmuJIDEQu1b9Dw==", + "license": "MIT", + "dependencies": { + "kareem": "3.0.0", + "mongodb": "~7.0", + "mpath": "0.9.0", + "mquery": "6.0.0", + "ms": "2.1.3", + "sift": "17.1.3" + }, + "engines": { + "node": ">=20.19.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/mongoose" + } + }, + "node_modules/mpath": { + "version": "0.9.0", + "resolved": "https://registry.npmjs.org/mpath/-/mpath-0.9.0.tgz", + "integrity": "sha512-ikJRQTk8hw5DEoFVxHG1Gn9T/xcjtdnOKIU1JTmGjZZlg9LST2mBLmcX3/ICIbgJydT2GOc15RnNy5mHmzfSew==", + "license": "MIT", + "engines": { + "node": ">=4.0.0" + } + }, + "node_modules/mquery": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/mquery/-/mquery-6.0.0.tgz", + "integrity": "sha512-b2KQNsmgtkscfeDgkYMcWGn9vZI9YoXh802VDEwE6qc50zxBFQ0Oo8ROkawbPAsXCY1/Z1yp0MagqsZStPWJjw==", + "license": "MIT", + "engines": { + "node": ">=20.19.0" + } + }, "node_modules/ms": { "version": "2.1.3", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", @@ -2087,6 +2467,26 @@ "node": ">= 0.6" } }, + "node_modules/node-addon-api": { + "version": "8.5.0", + "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-8.5.0.tgz", + "integrity": "sha512-/bRZty2mXUIFY/xU5HLvveNHlswNJej+RnxBjOMkidWfwZzgTbPG1E3K5TOxRLOR+5hX7bSofy8yf1hZevMS8A==", + "license": "MIT", + "engines": { + "node": "^18 || ^20 || >= 21" + } + }, + "node_modules/node-gyp-build": { + "version": "4.8.4", + "resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.8.4.tgz", + "integrity": "sha512-LA4ZjwlnUblHVgq0oBF3Jl/6h/Nvs5fzBLwdEF4nuxnFdsfajde4WfxtJr3CaiH+F6ewcIB/q4jQ4UzPyid+CQ==", + "license": "MIT", + "bin": { + "node-gyp-build": "bin.js", + "node-gyp-build-optional": "optional.js", + "node-gyp-build-test": "build-test.js" + } + }, "node_modules/object-assign": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", @@ -2308,7 +2708,6 @@ "version": "2.3.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", "integrity": "sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==", - "dev": true, "engines": { "node": ">=6" } @@ -2487,12 +2886,44 @@ "queue-microtask": "^1.2.2" } }, + "node_modules/safe-buffer": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", + "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "MIT" + }, "node_modules/safer-buffer": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", "license": "MIT" }, + "node_modules/semver": { + "version": "7.7.3", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.3.tgz", + "integrity": "sha512-SdsKMrI9TdgjdweUSR9MweHA4EJ8YxHn8DFaDisvhVlUOe4BF1tLD7GAj0lIqWVl+dPb/rExr0Btby5loQm20Q==", + "license": "ISC", + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/send": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/send/-/send-1.2.1.tgz", @@ -2637,6 +3068,96 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/sift": { + "version": "17.1.3", + "resolved": "https://registry.npmjs.org/sift/-/sift-17.1.3.tgz", + "integrity": "sha512-Rtlj66/b0ICeFzYTuNvX/EF1igRbbnGSvEyT79McoZa/DeGhMyC5pWKOEsZKnpkqtSeovd5FL/bjHWC3CIIvCQ==", + "license": "MIT" + }, + "node_modules/socket.io": { + "version": "4.8.3", + "resolved": "https://registry.npmjs.org/socket.io/-/socket.io-4.8.3.tgz", + "integrity": "sha512-2Dd78bqzzjE6KPkD5fHZmDAKRNe3J15q+YHDrIsy9WEkqttc7GY+kT9OBLSMaPbQaEd0x1BjcmtMtXkfpc+T5A==", + "license": "MIT", + "dependencies": { + "accepts": "~1.3.4", + "base64id": "~2.0.0", + "cors": "~2.8.5", + "debug": "~4.4.1", + "engine.io": "~6.6.0", + "socket.io-adapter": "~2.5.2", + "socket.io-parser": "~4.2.4" + }, + "engines": { + "node": ">=10.2.0" + } + }, + "node_modules/socket.io-adapter": { + "version": "2.5.6", + "resolved": "https://registry.npmjs.org/socket.io-adapter/-/socket.io-adapter-2.5.6.tgz", + "integrity": "sha512-DkkO/dz7MGln0dHn5bmN3pPy+JmywNICWrJqVWiVOyvXjWQFIv9c2h24JrQLLFJ2aQVQf/Cvl1vblnd4r2apLQ==", + "license": "MIT", + "dependencies": { + "debug": "~4.4.1", + "ws": "~8.18.3" + } + }, + "node_modules/socket.io-parser": { + "version": "4.2.5", + "resolved": "https://registry.npmjs.org/socket.io-parser/-/socket.io-parser-4.2.5.tgz", + "integrity": "sha512-bPMmpy/5WWKHea5Y/jYAP6k74A+hvmRCQaJuJB6I/ML5JZq/KfNieUVo/3Mh7SAqn7TyFdIo6wqYHInG1MU1bQ==", + "license": "MIT", + "dependencies": { + "@socket.io/component-emitter": "~3.1.0", + "debug": "~4.4.1" + }, + "engines": { + "node": ">=10.0.0" + } + }, + "node_modules/socket.io/node_modules/accepts": { + "version": "1.3.8", + "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz", + "integrity": "sha512-PYAthTa2m2VKxuvSD3DPC/Gy+U+sOA1LAuT8mkmRuvw+NACSaeXEQ+NHcVF7rONl6qcaxV3Uuemwawk+7+SJLw==", + "license": "MIT", + "dependencies": { + "mime-types": "~2.1.34", + "negotiator": "0.6.3" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/socket.io/node_modules/mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/socket.io/node_modules/mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "license": "MIT", + "dependencies": { + "mime-db": "1.52.0" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/socket.io/node_modules/negotiator": { + "version": "0.6.3", + "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz", + "integrity": "sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, "node_modules/source-map-js": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.1.tgz", @@ -2646,6 +3167,15 @@ "node": ">=0.10.0" } }, + "node_modules/sparse-bitfield": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/sparse-bitfield/-/sparse-bitfield-3.0.3.tgz", + "integrity": "sha512-kvzhi7vqKTfkh0PZU+2D2PIllw2ymqJKujUcyPMd9Y75Nv4nPbGJZXNhxsgdQab2BmlDct1YnfQCguEvHr7VsQ==", + "license": "MIT", + "dependencies": { + "memory-pager": "^1.0.2" + } + }, "node_modules/statuses": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.2.tgz", @@ -2706,6 +3236,18 @@ "node": ">=0.6" } }, + "node_modules/tr46": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-5.1.1.tgz", + "integrity": "sha512-hdF5ZgjTqgAntKkklYw0R03MG2x/bSzTtkxmIRw/sTNV8YXsCJ1tfLAX23lhxhHJlEf3CRCOCGGWw3vI3GaSPw==", + "license": "MIT", + "dependencies": { + "punycode": "^2.3.1" + }, + "engines": { + "node": ">=18" + } + }, "node_modules/type-check": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", @@ -2744,6 +3286,12 @@ "node": ">= 0.6" } }, + "node_modules/undici-types": { + "version": "7.16.0", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.16.0.tgz", + "integrity": "sha512-Zz+aZWSj8LE6zoxD+xrjh4VfkIG8Ya6LvYkZqtUQGJPZjYl53ypCaUwWqo7eI0x66KBGeRo+mlBEkMSeSZ38Nw==", + "license": "MIT" + }, "node_modules/unpipe": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", @@ -2830,6 +3378,28 @@ } } }, + "node_modules/webidl-conversions": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-7.0.0.tgz", + "integrity": "sha512-VwddBukDzu71offAQR975unBIGqfKZpM+8ZX6ySk8nYhVoo5CYaZyzt3YBvYtRtO+aoGlqxPg/B87NGVZ/fu6g==", + "license": "BSD-2-Clause", + "engines": { + "node": ">=12" + } + }, + "node_modules/whatwg-url": { + "version": "14.2.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-14.2.0.tgz", + "integrity": "sha512-De72GdQZzNTUBBChsXueQUnPKDkg/5A5zp7pFDuQAj5UFoENpiACU0wlCvzpAGnTkj++ihpKwKyYewn/XNUbKw==", + "license": "MIT", + "dependencies": { + "tr46": "^5.1.0", + "webidl-conversions": "^7.0.0" + }, + "engines": { + "node": ">=18" + } + }, "node_modules/which": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", @@ -2859,6 +3429,27 @@ "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==" }, + "node_modules/ws": { + "version": "8.18.3", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.18.3.tgz", + "integrity": "sha512-PEIGCY5tSlUt50cqyMXfCzX+oOPqN0vuGqWzbcJ2xvnkzkq46oOpz7dQaTDBdfICb4N14+GARUDw2XV2N4tvzg==", + "license": "MIT", + "engines": { + "node": ">=10.0.0" + }, + "peerDependencies": { + "bufferutil": "^4.0.1", + "utf-8-validate": ">=5.0.2" + }, + "peerDependenciesMeta": { + "bufferutil": { + "optional": true + }, + "utf-8-validate": { + "optional": true + } + } + }, "node_modules/yocto-queue": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", @@ -3100,6 +3691,14 @@ "integrity": "sha512-93zYdMES/c1D69yZiKDBj0V24vqNzB/koF26KPaagAfd3P/4gUlh3Dys5ogAK+Exi9QyzlD8x/08Zt7wIKcDcA==", "dev": true }, + "@mongodb-js/saslprep": { + "version": "1.4.5", + "resolved": "https://registry.npmjs.org/@mongodb-js/saslprep/-/saslprep-1.4.5.tgz", + "integrity": "sha512-k64Lbyb7ycCSXHSLzxVdb2xsKGPMvYZfCICXvDsI8Z65CeWQzTEKS4YmGbnqw+U9RBvLPTsB6UCmwkgsDTGWIw==", + "requires": { + "sparse-bitfield": "^3.0.3" + } + }, "@nodelib/fs.scandir": { "version": "2.1.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", @@ -3286,12 +3885,46 @@ "dev": true, "optional": true }, + "@socket.io/component-emitter": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/@socket.io/component-emitter/-/component-emitter-3.1.2.tgz", + "integrity": "sha512-9BCxFwvbGg/RsZK9tjXd8s4UcwR0MWeFQ1XEKIQVVvAGJyINdrqKMcTRyLoK8Rse1GjzLV9cwjWV1olXRWEXVA==" + }, + "@types/cors": { + "version": "2.8.19", + "resolved": "https://registry.npmjs.org/@types/cors/-/cors-2.8.19.tgz", + "integrity": "sha512-mFNylyeyqN93lfe/9CSxOGREz8cpzAhH+E93xJ4xWQf62V8sQ/24reV2nyzUWM6H6Xji+GGHpkbLe7pVoUEskg==", + "requires": { + "@types/node": "*" + } + }, "@types/estree": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.8.tgz", "integrity": "sha512-dWHzHa2WqEXI/O1E9OjrocMTKJl2mSrEolh1Iomrv6U+JuNwaHXsXx9bLu5gG7BUWFIN0skIQJQ/L1rIex4X6w==", "dev": true }, + "@types/node": { + "version": "25.0.10", + "resolved": "https://registry.npmjs.org/@types/node/-/node-25.0.10.tgz", + "integrity": "sha512-zWW5KPngR/yvakJgGOmZ5vTBemDoSqF3AcV/LrO5u5wTWyEAVVh+IT39G4gtyAkh3CtTZs8aX/yRM82OfzHJRg==", + "requires": { + "undici-types": "~7.16.0" + } + }, + "@types/webidl-conversions": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/@types/webidl-conversions/-/webidl-conversions-7.0.3.tgz", + "integrity": "sha512-CiJJvcRtIgzadHCYXw7dqEnMNRjhGZlYK05Mj9OyktqV8uVT8fD2BFOB7S1uwBE3Kj2Z+4UyPmFw/Ixgw/LAlA==" + }, + "@types/whatwg-url": { + "version": "13.0.0", + "resolved": "https://registry.npmjs.org/@types/whatwg-url/-/whatwg-url-13.0.0.tgz", + "integrity": "sha512-N8WXpbE6Wgri7KUSvrmQcqrMllKZ9uxkYWMt+mCSGwNc0Hsw9VQTW7ApqI4XNrx6/SaM2QQJCzMPDEXE058s+Q==", + "requires": { + "@types/webidl-conversions": "*" + } + }, "@ungap/structured-clone": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/@ungap/structured-clone/-/structured-clone-1.3.0.tgz", @@ -3311,8 +3944,7 @@ "version": "8.15.0", "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.15.0.tgz", "integrity": "sha512-NZyJarBfL7nWwIq+FDL6Zp/yHEhePMNnnJ0y3qfieCrmNvYct8uvtiV41UvlSe6apAfk0fY1FbWx+NwfmpvtTg==", - "dev": true, - "peer": true + "dev": true }, "acorn-jsx": { "version": "5.3.2", @@ -3360,6 +3992,20 @@ "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", "dev": true }, + "base64id": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/base64id/-/base64id-2.0.0.tgz", + "integrity": "sha512-lGe34o6EHj9y3Kts9R4ZYs/Gr+6N7MCaMlIFA3F1R2O5/m7K06AxfSeO5530PEERE6/WyEg3lsuyw4GHlPZHog==" + }, + "bcrypt": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/bcrypt/-/bcrypt-6.0.0.tgz", + "integrity": "sha512-cU8v/EGSrnH+HnxV2z0J7/blxH8gq7Xh2JFT6Aroax7UohdmiJJlxApMxtKfuI7z68NvvVcmR78k2LbT6efhRg==", + "requires": { + "node-addon-api": "^8.3.0", + "node-gyp-build": "^4.8.4" + } + }, "body-parser": { "version": "2.2.1", "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-2.2.1.tgz", @@ -3392,6 +4038,16 @@ "concat-map": "0.0.1" } }, + "bson": { + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/bson/-/bson-7.1.1.tgz", + "integrity": "sha512-TtJgBB+QyOlWjrbM+8bRgH84VM/xrDjyBFgSgGrfZF4xvt6gbEDtcswm27Tn9F9TWsjQybxT8b8VpCP/oJK4Dw==" + }, + "buffer-equal-constant-time": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz", + "integrity": "sha512-zRpUiDwd/xk6ADqPMATG8vc9VPrkck7T07OIx0gnjmJAnHnTVXNQG3vfvWNuiZIkwu9KrKdA1iJKfsfTVxE6NA==" + }, "bytes": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", @@ -3520,6 +4176,11 @@ "esutils": "^2.0.2" } }, + "dotenv": { + "version": "17.2.3", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-17.2.3.tgz", + "integrity": "sha512-JVUnt+DUIzu87TABbhPmNfVdBDt18BLOWjMUFJMSi/Qqg7NTYtabbvSNJGOJ7afbRuv9D/lngizHtP7QyLQ+9w==" + }, "dunder-proto": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", @@ -3530,6 +4191,14 @@ "gopd": "^1.2.0" } }, + "ecdsa-sig-formatter": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.11.tgz", + "integrity": "sha512-nagl3RYrbNv6kQkeJIpt6NJZy8twLB/2vtz6yN9Z4vRKHN4/QZJIEbqohALSgwKdnksuY3k5Addp5lg8sVoVcQ==", + "requires": { + "safe-buffer": "^5.0.1" + } + }, "ee-first": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", @@ -3540,6 +4209,56 @@ "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-2.0.0.tgz", "integrity": "sha512-Q0n9HRi4m6JuGIV1eFlmvJB7ZEVxu93IrMyiMsGC0lrMJMWzRgx6WGquyfQgZVb31vhGgXnfmPNNXmxnOkRBrg==" }, + "engine.io": { + "version": "6.6.5", + "resolved": "https://registry.npmjs.org/engine.io/-/engine.io-6.6.5.tgz", + "integrity": "sha512-2RZdgEbXmp5+dVbRm0P7HQUImZpICccJy7rN7Tv+SFa55pH+lxnuw6/K1ZxxBfHoYpSkHLAO92oa8O4SwFXA2A==", + "requires": { + "@types/cors": "^2.8.12", + "@types/node": ">=10.0.0", + "accepts": "~1.3.4", + "base64id": "2.0.0", + "cookie": "~0.7.2", + "cors": "~2.8.5", + "debug": "~4.4.1", + "engine.io-parser": "~5.2.1", + "ws": "~8.18.3" + }, + "dependencies": { + "accepts": { + "version": "1.3.8", + "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz", + "integrity": "sha512-PYAthTa2m2VKxuvSD3DPC/Gy+U+sOA1LAuT8mkmRuvw+NACSaeXEQ+NHcVF7rONl6qcaxV3Uuemwawk+7+SJLw==", + "requires": { + "mime-types": "~2.1.34", + "negotiator": "0.6.3" + } + }, + "mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==" + }, + "mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "requires": { + "mime-db": "1.52.0" + } + }, + "negotiator": { + "version": "0.6.3", + "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz", + "integrity": "sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==" + } + } + }, + "engine.io-parser": { + "version": "5.2.3", + "resolved": "https://registry.npmjs.org/engine.io-parser/-/engine.io-parser-5.2.3.tgz", + "integrity": "sha512-HqD3yTBfnBxIrbnM1DoD6Pcq8NECnh8d4As1Qgh0z5Gg3jRRIqijury0CL3ghu/edArpUYiYqQiDUQBIs4np3Q==" + }, "es-define-property": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz", @@ -3605,7 +4324,6 @@ "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.57.1.tgz", "integrity": "sha512-ypowyDxpVSYpkXr9WPv2PAZCtNip1Mv5KTW0SCurXv/9iOpcrH9PaqUElksqEB6pChqHGDRCFTyrZlGhnLNGiA==", "dev": true, - "peer": true, "requires": { "@eslint-community/eslint-utils": "^4.2.0", "@eslint-community/regexpp": "^4.6.1", @@ -4064,6 +4782,47 @@ "integrity": "sha512-Bdboy+l7tA3OGW6FjyFHWkP5LuByj1Tk33Ljyq0axyzdk9//JSi2u3fP1QSmd1KNwq6VOKYGlAu87CisVir6Pw==", "dev": true }, + "jsonwebtoken": { + "version": "9.0.3", + "resolved": "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-9.0.3.tgz", + "integrity": "sha512-MT/xP0CrubFRNLNKvxJ2BYfy53Zkm++5bX9dtuPbqAeQpTVe0MQTFhao8+Cp//EmJp244xt6Drw/GVEGCUj40g==", + "requires": { + "jws": "^4.0.1", + "lodash.includes": "^4.3.0", + "lodash.isboolean": "^3.0.3", + "lodash.isinteger": "^4.0.4", + "lodash.isnumber": "^3.0.3", + "lodash.isplainobject": "^4.0.6", + "lodash.isstring": "^4.0.1", + "lodash.once": "^4.0.0", + "ms": "^2.1.1", + "semver": "^7.5.4" + } + }, + "jwa": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/jwa/-/jwa-2.0.1.tgz", + "integrity": "sha512-hRF04fqJIP8Abbkq5NKGN0Bbr3JxlQ+qhZufXVr0DvujKy93ZCbXZMHDL4EOtodSbCWxOqR8MS1tXA5hwqCXDg==", + "requires": { + "buffer-equal-constant-time": "^1.0.1", + "ecdsa-sig-formatter": "1.0.11", + "safe-buffer": "^5.0.1" + } + }, + "jws": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/jws/-/jws-4.0.1.tgz", + "integrity": "sha512-EKI/M/yqPncGUUh44xz0PxSidXFr/+r0pA70+gIYhjv+et7yxM+s29Y+VGDkovRofQem0fs7Uvf4+YmAdyRduA==", + "requires": { + "jwa": "^2.0.1", + "safe-buffer": "^5.0.1" + } + }, + "kareem": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/kareem/-/kareem-3.0.0.tgz", + "integrity": "sha512-RKhaOBSPN8L7y4yAgNhDT2602G5FD6QbOIISbjN9D6mjHPeqeg7K+EB5IGSU5o81/X2Gzm3ICnAvQW3x3OP8HA==" + }, "keyv": { "version": "4.5.4", "resolved": "https://registry.npmjs.org/keyv/-/keyv-4.5.4.tgz", @@ -4092,12 +4851,47 @@ "p-locate": "^5.0.0" } }, + "lodash.includes": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/lodash.includes/-/lodash.includes-4.3.0.tgz", + "integrity": "sha512-W3Bx6mdkRTGtlJISOvVD/lbqjTlPPUDTMnlXZFnVwi9NKJ6tiAk6LVdlhZMm17VZisqhKcgzpO5Wz91PCt5b0w==" + }, + "lodash.isboolean": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/lodash.isboolean/-/lodash.isboolean-3.0.3.tgz", + "integrity": "sha512-Bz5mupy2SVbPHURB98VAcw+aHh4vRV5IPNhILUCsOzRmsTmSQ17jIuqopAentWoehktxGd9e/hbIXq980/1QJg==" + }, + "lodash.isinteger": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/lodash.isinteger/-/lodash.isinteger-4.0.4.tgz", + "integrity": "sha512-DBwtEWN2caHQ9/imiNeEA5ys1JoRtRfY3d7V9wkqtbycnAmTvRRmbHKDV4a0EYc678/dia0jrte4tjYwVBaZUA==" + }, + "lodash.isnumber": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/lodash.isnumber/-/lodash.isnumber-3.0.3.tgz", + "integrity": "sha512-QYqzpfwO3/CWf3XP+Z+tkQsfaLL/EnUlXWVkIk5FUPc4sBdTehEqZONuyRt2P67PXAk+NXmTBcc97zw9t1FQrw==" + }, + "lodash.isplainobject": { + "version": "4.0.6", + "resolved": "https://registry.npmjs.org/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz", + "integrity": "sha512-oSXzaWypCMHkPC3NvBEaPHf0KsA5mvPrOPgQWDsbg8n7orZ290M0BmC/jgRZ4vcJ6DTAhjrsSYgdsW/F+MFOBA==" + }, + "lodash.isstring": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/lodash.isstring/-/lodash.isstring-4.0.1.tgz", + "integrity": "sha512-0wJxfxH1wgO3GrbuP+dTTk7op+6L41QCXbGINEmD+ny/G/eCqGzxyCsh7159S+mgDDcoarnBw6PC1PS5+wUGgw==" + }, "lodash.merge": { "version": "4.6.2", "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz", "integrity": "sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==", "dev": true }, + "lodash.once": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/lodash.once/-/lodash.once-4.1.1.tgz", + "integrity": "sha512-Sb487aTOCr9drQVL8pIxOzVhafOjZN9UU54hiN8PU3uAiSV7lx1yYNpbNmex2PK6dSJoNTSJUUswT651yww3Mg==" + }, "math-intrinsics": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz", @@ -4108,6 +4902,11 @@ "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-1.1.0.tgz", "integrity": "sha512-aisnrDP4GNe06UcKFnV5bfMNPBUw4jsLGaWwWfnH3v02GnBuXX2MCVn5RbrWo0j3pczUilYblq7fQ7Nw2t5XKw==" }, + "memory-pager": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/memory-pager/-/memory-pager-1.5.0.tgz", + "integrity": "sha512-ZS4Bp4r/Zoeq6+NLJpP+0Zzm0pR8whtGPf1XExKLJBAczGMnSi3It14OiNCStjQjM6NU1okjQGSxgEZN8eBYKg==" + }, "merge-descriptors": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-2.0.0.tgz", @@ -4135,6 +4934,48 @@ "brace-expansion": "^1.1.7" } }, + "mongodb": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-7.0.0.tgz", + "integrity": "sha512-vG/A5cQrvGGvZm2mTnCSz1LUcbOPl83hfB6bxULKQ8oFZauyox/2xbZOoGNl+64m8VBrETkdGCDBdOsCr3F3jg==", + "requires": { + "@mongodb-js/saslprep": "^1.3.0", + "bson": "^7.0.0", + "mongodb-connection-string-url": "^7.0.0" + } + }, + "mongodb-connection-string-url": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/mongodb-connection-string-url/-/mongodb-connection-string-url-7.0.1.tgz", + "integrity": "sha512-h0AZ9A7IDVwwHyMxmdMXKy+9oNlF0zFoahHiX3vQ8e3KFcSP3VmsmfvtRSuLPxmyv2vjIDxqty8smTgie/SNRQ==", + "requires": { + "@types/whatwg-url": "^13.0.0", + "whatwg-url": "^14.1.0" + } + }, + "mongoose": { + "version": "9.1.5", + "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-9.1.5.tgz", + "integrity": "sha512-N6gypEO+wLmZp8kCYNQmrEWxVMT0KhyHvVttBZoKA/1ngY7aUsBjqHzCPtDgz+i8JAnqMOiEKmuJIDEQu1b9Dw==", + "requires": { + "kareem": "3.0.0", + "mongodb": "~7.0", + "mpath": "0.9.0", + "mquery": "6.0.0", + "ms": "2.1.3", + "sift": "17.1.3" + } + }, + "mpath": { + "version": "0.9.0", + "resolved": "https://registry.npmjs.org/mpath/-/mpath-0.9.0.tgz", + "integrity": "sha512-ikJRQTk8hw5DEoFVxHG1Gn9T/xcjtdnOKIU1JTmGjZZlg9LST2mBLmcX3/ICIbgJydT2GOc15RnNy5mHmzfSew==" + }, + "mquery": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/mquery/-/mquery-6.0.0.tgz", + "integrity": "sha512-b2KQNsmgtkscfeDgkYMcWGn9vZI9YoXh802VDEwE6qc50zxBFQ0Oo8ROkawbPAsXCY1/Z1yp0MagqsZStPWJjw==" + }, "ms": { "version": "2.1.3", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", @@ -4157,6 +4998,16 @@ "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-1.0.0.tgz", "integrity": "sha512-8Ofs/AUQh8MaEcrlq5xOX0CQ9ypTF5dl78mjlMNfOK08fzpgTHQRQPBxcPlEtIw0yRpws+Zo/3r+5WRby7u3Gg==" }, + "node-addon-api": { + "version": "8.5.0", + "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-8.5.0.tgz", + "integrity": "sha512-/bRZty2mXUIFY/xU5HLvveNHlswNJej+RnxBjOMkidWfwZzgTbPG1E3K5TOxRLOR+5hX7bSofy8yf1hZevMS8A==" + }, + "node-gyp-build": { + "version": "4.8.4", + "resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.8.4.tgz", + "integrity": "sha512-LA4ZjwlnUblHVgq0oBF3Jl/6h/Nvs5fzBLwdEF4nuxnFdsfajde4WfxtJr3CaiH+F6ewcIB/q4jQ4UzPyid+CQ==" + }, "object-assign": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", @@ -4293,8 +5144,7 @@ "punycode": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", - "integrity": "sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==", - "dev": true + "integrity": "sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==" }, "qs": { "version": "6.14.0", @@ -4400,11 +5250,21 @@ "queue-microtask": "^1.2.2" } }, + "safe-buffer": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", + "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==" + }, "safer-buffer": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" }, + "semver": { + "version": "7.7.3", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.3.tgz", + "integrity": "sha512-SdsKMrI9TdgjdweUSR9MweHA4EJ8YxHn8DFaDisvhVlUOe4BF1tLD7GAj0lIqWVl+dPb/rExr0Btby5loQm20Q==" + }, "send": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/send/-/send-1.2.1.tgz", @@ -4498,12 +5358,86 @@ "side-channel-map": "^1.0.1" } }, + "sift": { + "version": "17.1.3", + "resolved": "https://registry.npmjs.org/sift/-/sift-17.1.3.tgz", + "integrity": "sha512-Rtlj66/b0ICeFzYTuNvX/EF1igRbbnGSvEyT79McoZa/DeGhMyC5pWKOEsZKnpkqtSeovd5FL/bjHWC3CIIvCQ==" + }, + "socket.io": { + "version": "4.8.3", + "resolved": "https://registry.npmjs.org/socket.io/-/socket.io-4.8.3.tgz", + "integrity": "sha512-2Dd78bqzzjE6KPkD5fHZmDAKRNe3J15q+YHDrIsy9WEkqttc7GY+kT9OBLSMaPbQaEd0x1BjcmtMtXkfpc+T5A==", + "requires": { + "accepts": "~1.3.4", + "base64id": "~2.0.0", + "cors": "~2.8.5", + "debug": "~4.4.1", + "engine.io": "~6.6.0", + "socket.io-adapter": "~2.5.2", + "socket.io-parser": "~4.2.4" + }, + "dependencies": { + "accepts": { + "version": "1.3.8", + "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz", + "integrity": "sha512-PYAthTa2m2VKxuvSD3DPC/Gy+U+sOA1LAuT8mkmRuvw+NACSaeXEQ+NHcVF7rONl6qcaxV3Uuemwawk+7+SJLw==", + "requires": { + "mime-types": "~2.1.34", + "negotiator": "0.6.3" + } + }, + "mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==" + }, + "mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "requires": { + "mime-db": "1.52.0" + } + }, + "negotiator": { + "version": "0.6.3", + "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz", + "integrity": "sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==" + } + } + }, + "socket.io-adapter": { + "version": "2.5.6", + "resolved": "https://registry.npmjs.org/socket.io-adapter/-/socket.io-adapter-2.5.6.tgz", + "integrity": "sha512-DkkO/dz7MGln0dHn5bmN3pPy+JmywNICWrJqVWiVOyvXjWQFIv9c2h24JrQLLFJ2aQVQf/Cvl1vblnd4r2apLQ==", + "requires": { + "debug": "~4.4.1", + "ws": "~8.18.3" + } + }, + "socket.io-parser": { + "version": "4.2.5", + "resolved": "https://registry.npmjs.org/socket.io-parser/-/socket.io-parser-4.2.5.tgz", + "integrity": "sha512-bPMmpy/5WWKHea5Y/jYAP6k74A+hvmRCQaJuJB6I/ML5JZq/KfNieUVo/3Mh7SAqn7TyFdIo6wqYHInG1MU1bQ==", + "requires": { + "@socket.io/component-emitter": "~3.1.0", + "debug": "~4.4.1" + } + }, "source-map-js": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.1.tgz", "integrity": "sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==", "dev": true }, + "sparse-bitfield": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/sparse-bitfield/-/sparse-bitfield-3.0.3.tgz", + "integrity": "sha512-kvzhi7vqKTfkh0PZU+2D2PIllw2ymqJKujUcyPMd9Y75Nv4nPbGJZXNhxsgdQab2BmlDct1YnfQCguEvHr7VsQ==", + "requires": { + "memory-pager": "^1.0.2" + } + }, "statuses": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.2.tgz", @@ -4544,6 +5478,14 @@ "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz", "integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==" }, + "tr46": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-5.1.1.tgz", + "integrity": "sha512-hdF5ZgjTqgAntKkklYw0R03MG2x/bSzTtkxmIRw/sTNV8YXsCJ1tfLAX23lhxhHJlEf3CRCOCGGWw3vI3GaSPw==", + "requires": { + "punycode": "^2.3.1" + } + }, "type-check": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", @@ -4569,6 +5511,11 @@ "mime-types": "^3.0.0" } }, + "undici-types": { + "version": "7.16.0", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.16.0.tgz", + "integrity": "sha512-Zz+aZWSj8LE6zoxD+xrjh4VfkIG8Ya6LvYkZqtUQGJPZjYl53ypCaUwWqo7eI0x66KBGeRo+mlBEkMSeSZ38Nw==" + }, "unpipe": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", @@ -4600,6 +5547,20 @@ "rollup": "^4.20.0" } }, + "webidl-conversions": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-7.0.0.tgz", + "integrity": "sha512-VwddBukDzu71offAQR975unBIGqfKZpM+8ZX6ySk8nYhVoo5CYaZyzt3YBvYtRtO+aoGlqxPg/B87NGVZ/fu6g==" + }, + "whatwg-url": { + "version": "14.2.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-14.2.0.tgz", + "integrity": "sha512-De72GdQZzNTUBBChsXueQUnPKDkg/5A5zp7pFDuQAj5UFoENpiACU0wlCvzpAGnTkj++ihpKwKyYewn/XNUbKw==", + "requires": { + "tr46": "^5.1.0", + "webidl-conversions": "^7.0.0" + } + }, "which": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", @@ -4620,6 +5581,12 @@ "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==" }, + "ws": { + "version": "8.18.3", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.18.3.tgz", + "integrity": "sha512-PEIGCY5tSlUt50cqyMXfCzX+oOPqN0vuGqWzbcJ2xvnkzkq46oOpz7dQaTDBdfICb4N14+GARUDw2XV2N4tvzg==", + "requires": {} + }, "yocto-queue": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", diff --git a/package.json b/package.json index 995be66..942337b 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "A live streaming platform for developers.", "main": "src/js/main.js", "scripts": { - "dev": "vite", + "dev": "vite --host", "build": "vite build", "preview": "vite preview", "lint": "eslint .", @@ -23,9 +23,14 @@ "type": "module", "dependencies": { "@fortawesome/fontawesome-free": "^6.5.2", + "bcrypt": "^6.0.0", "bootstrap": "^5.3.3", "cors": "^2.8.5", - "express": "^5.2.1" + "dotenv": "^17.2.3", + "express": "^5.2.1", + "jsonwebtoken": "^9.0.3", + "mongoose": "^9.1.5", + "socket.io": "^4.8.3" }, "devDependencies": { "eslint": "^8.57.0", diff --git a/public/service-worker.js b/public/service-worker.js index a17b805..263f5d8 100644 --- a/public/service-worker.js +++ b/public/service-worker.js @@ -1,125 +1,126 @@ // service-worker.js -const CACHE_NAME = "devstream-v1"; +const CACHE_NAME = 'devstream-v1'; // List of resources to cache const CACHE_RESOURCES = [ - "/", - "/index.html", - "/src/css/style.css", - "/src/js/main.js", - "/manifest.json", - "/src/assets/images/preview-placeholder.jpg", - "/src/assets/icons/icon-192x192.png", - "/src/assets/icons/icon-512x512.png", - "/src/assets/icons/maskable-icon-192x192.png", - "/src/assets/icons/maskable-icon-512x512.png", - "https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css", - "https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css", - "https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js", - "https://fonts.googleapis.com/css2?family=Roboto:wght@400&display=swap", - "https://fonts.gstatic.com/s/roboto/v27/KFOmCnqEu92Fr1Mu4mxK.woff2" + '/', + '/index.html', + '/src/css/style.css', + '/src/js/main.js', + '/manifest.json', + '/src/assets/images/preview-placeholder.jpg', + '/src/assets/icons/icon-192x192.png', + '/src/assets/icons/icon-512x512.png', + '/src/assets/icons/maskable-icon-192x192.png', + '/src/assets/icons/maskable-icon-512x512.png', + 'https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css', + 'https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css', + 'https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js', + 'https://fonts.googleapis.com/css2?family=Roboto:wght@400&display=swap', + 'https://fonts.gstatic.com/s/roboto/v27/KFOmCnqEu92Fr1Mu4mxK.woff2', ]; // Install event handler -self.addEventListener("install", (event) => { - event.waitUntil( - caches.open(CACHE_NAME).then((cache) => { - console.log("Installing service worker..."); - return cache.addAll(CACHE_RESOURCES); - }).catch(error => { - console.error("Error during cache installation:", error); - }) - ); +self.addEventListener('install', (event) => { + event.waitUntil( + caches + .open(CACHE_NAME) + .then((cache) => { + console.log('Installing service worker...'); + return cache.addAll(CACHE_RESOURCES); + }) + .catch((error) => { + console.error('Error during cache installation:', error); + }) + ); }); // Activate event handler -self.addEventListener("activate", (event) => { - event.waitUntil( - caches.keys().then((cacheNames) => { - return Promise.all( - cacheNames.map((cacheName) => { - if (cacheName !== CACHE_NAME) { - console.log("Removing outdated cache:", cacheName); - return caches.delete(cacheName); - } - }) - ); +self.addEventListener('activate', (event) => { + event.waitUntil( + caches.keys().then((cacheNames) => { + return Promise.all( + cacheNames.map((cacheName) => { + if (cacheName !== CACHE_NAME) { + console.log('Removing outdated cache:', cacheName); + return caches.delete(cacheName); + } }) - ); + ); + }) + ); }); // Fetch event handler with cache-first strategy -self.addEventListener("fetch", (event) => { - event.respondWith( - caches.match(event.request).then((response) => { - if (response) { - // Update cache in background while serving cached response - event.waitUntil( - fetch(event.request).then((newResponse) => { - if (newResponse.ok) { - caches.open(CACHE_NAME).then((cache) => { - cache.put(event.request, newResponse.clone()); - }); - } - }).catch(error => { - console.error("Failed to update cache:", error); - }) - ); - return response; - } - - // Handle non-cached requests - return fetch(event.request).catch(error => { - console.error("Network request failed:", error); - - // Serve offline fallback for navigation requests - if (event.request.mode === 'navigate') { - return caches.match('/offline.html'); - } - }); - }) - ); +self.addEventListener('fetch', (event) => { + event.respondWith( + caches.match(event.request).then((response) => { + if (response) { + // Update cache in background while serving cached response + event.waitUntil( + fetch(event.request) + .then((newResponse) => { + if (newResponse.ok) { + caches.open(CACHE_NAME).then((cache) => { + cache.put(event.request, newResponse.clone()); + }); + } + }) + .catch((error) => { + console.error('Failed to update cache:', error); + }) + ); + return response; + } + + // Handle non-cached requests + return fetch(event.request).catch((error) => { + console.error('Network request failed:', error); + + // Serve offline fallback for navigation requests + if (event.request.mode === 'navigate') { + return caches.match('/offline.html'); + } + }); + }) + ); }); // Message event handler for debugging -self.addEventListener("message", (event) => { - if (event.data === "skipWaiting") { - self.skipWaiting(); - } +self.addEventListener('message', (event) => { + if (event.data === 'skipWaiting') { + self.skipWaiting(); + } }); // Push notification handler -self.addEventListener("push", (event) => { - let data = {}; +self.addEventListener('push', (event) => { + let data = {}; - if (event.data) { - try { - data = event.data.json(); - } catch (e) { - data = { body: event.data.text() }; - } + if (event.data) { + try { + data = event.data.json(); + } catch (e) { + data = { body: event.data.text() }; } + } - const title = data.title || "DevStreamer is Live!"; - const options = { - body: data.body || "Your favorite DevStreamer just went live.", - icon: "/favicon.ico", - badge: "/favicon.ico", - data: { - url: data.url || "/" - } - }; + const title = data.title || 'DevStreamer is Live!'; + const options = { + body: data.body || 'Your favorite DevStreamer just went live.', + icon: '/favicon.ico', + badge: '/favicon.ico', + data: { + url: data.url || '/', + }, + }; - event.waitUntil( - self.registration.showNotification(title, options) - ); + event.waitUntil(self.registration.showNotification(title, options)); }); // Notification click handler -self.addEventListener("notificationclick", (event) => { - event.notification.close(); +self.addEventListener('notificationclick', (event) => { + event.notification.close(); - event.waitUntil( - clients.openWindow(event.notification.data.url) - ); + event.waitUntil(clients.openWindow(event.notification.data.url)); }); diff --git a/server.js b/server.js index 79b3bb9..a64386e 100644 --- a/server.js +++ b/server.js @@ -5,12 +5,31 @@ import mongoose from 'mongoose'; import fs from 'fs'; import { fileURLToPath } from 'url'; import { dirname, join } from 'path'; -import * as AuthControllers from './src/controllers/AuthControllers.js'; +import { createServer } from 'http'; +import { Server } from 'socket.io'; +import jwt from 'jsonwebtoken'; +import * as AuthControllers from './src/controllers/AuthControllers.js'; import { auth, authorizeRole } from './src/middleware/auth.js'; const app = express(); +const httpServer = createServer(app); +const io = new Server(httpServer, { + cors: { + origin: [ + 'http://localhost:3000', + 'http://localhost:5173', + 'http://127.0.0.1:5173', + ], + methods: ['GET', 'POST'], + credentials: true, + allowedHeaders: ['Authorization'], + }, + transports: ['websocket', 'polling'], + allowEIO3: true, +}); const PORT = process.env.PORT || 3000; const MONGODB_URI = process.env.MONGODB_URI; +const JWT_SECRET = process.env.JWT_SECRET; // Recreate __dirname since it is not available in ES Modules by default const __filename = fileURLToPath(import.meta.url); @@ -18,27 +37,25 @@ const __dirname = dirname(__filename); // Enable CORS so your frontend can communicate with this API // Middleware setup (must be before routes) -app.use(cors({ origin: 'http://localhost:3000' })); // SECURE CORS +app.use(cors({ origin: 'http://localhost:3000' })); // SECURE CORS app.use(express.json()); // DATABASE CONNECTION -mongoose.connect(MONGODB_URI) - .then(() => console.log('🟢 MongoDB connected successfully.')) - .catch(err => console.error('šŸ”“ MongoDB connection error:', err)); - - -// AUTH ROUTES -app.post('/api/auth/register', AuthControllers.register); -app.post('/api/auth/login', AuthControllers.login); +mongoose + .connect(MONGODB_URI) + .then(() => console.log('🟢 MongoDB connected successfully.')) + .catch((err) => console.error('šŸ”“ MongoDB connection error:', err)); +// AUTH ROUTES +app.post('/api/auth/register', AuthControllers.register); +app.post('/api/auth/login', AuthControllers.login); /** * @route GET /api/auth/me * @desc Gets the currently logged-in user's details (eg: username, role). * This endpoint demonstrates basic 'auth' middleware protection. */ -app.get('/api/auth/me', auth, AuthControllers.getUserDetails); - +app.get('/api/auth/me', auth, AuthControllers.getUserDetails); /** * @route GET /api/admin/dashboard @@ -46,8 +63,8 @@ app.get('/api/auth/me', auth, AuthControllers.getUserDetails); * This demonstrates Role-Based Access Control. */ app.get('/api/admin/dashboard', auth, authorizeRole(['admin']), (req, res) => { - // req.user is available here due to the 'auth' middleware - res.json({ message: `Access granted, Admin ID: ${req.user.id}.` }); + // req.user is available here due to the 'auth' middleware + res.json({ message: `Access granted, Admin ID: ${req.user.id}.` }); }); /** @@ -55,7 +72,7 @@ app.get('/api/admin/dashboard', auth, authorizeRole(['admin']), (req, res) => { * This fixes the "Cannot GET /" error by providing a landing page. */ app.get('/', (req, res) => { - res.send(` + res.send(`

šŸš€ DevStream API is Online

The server is running correctly.

@@ -69,23 +86,294 @@ app.get('/', (req, res) => { * Reads the mock data from streams.json and returns it as JSON. */ app.get('/api/streams', (req, res) => { - const dataPath = join(__dirname, 'streams.json'); - - fs.readFile(dataPath, 'utf8', (err, data) => { - if (err) { - console.error("Error reading streams.json:", err); - return res.status(500).json({ error: "Internal Server Error: Could not read data file." }); + const dataPath = join(__dirname, 'streams.json'); + + fs.readFile(dataPath, 'utf8', (err, data) => { + if (err) { + console.error('Error reading streams.json:', err); + return res + .status(500) + .json({ error: 'Internal Server Error: Could not read data file.' }); + } + try { + res.json(JSON.parse(data)); + } catch (parseErr) { + console.error('Error parsing JSON:', parseErr); + res + .status(500) + .json({ error: 'Internal Server Error: Invalid JSON format.' }); + } + }); +}); + +// ================= SOCKET.IO CHAT ================= + +// Store connected users with their roles +const connectedUsers = new Map(); + +// Store chat message history (in-memory, max 100 messages) +const chatHistory = []; +const MAX_HISTORY = 100; + +// Role hierarchy for permissions (higher number = more permissions) +const roleHierarchy = { + user: 1, + vip: 2, + moderator: 3, + broadcaster: 4, + administrator: 5, + admin: 5, + bot: 6, +}; + +// Helper function to verify socket token +const verifySocketToken = (token) => { + try { + return jwt.verify(token, JWT_SECRET); + } catch (err) { + return null; + } +}; + +// Helper function to check if user has permission +const hasPermission = (userRole, requiredRole) => { + return (roleHierarchy[userRole] || 0) >= (roleHierarchy[requiredRole] || 0); +}; + +io.use((socket, next) => { + const token = socket.handshake.auth.token; + const persistentUserId = socket.handshake.auth.persistentUserId; + + if (!token) { + // Use persistent user ID if provided, otherwise generate guest ID + const username = persistentUserId || `Guest_${socket.id.substring(0, 6)}`; + socket.user = { + id: persistentUserId || socket.id, + username: username, + role: 'user', + persistentId: persistentUserId, + }; + return next(); + } + + const decoded = verifySocketToken(token); + if (decoded) { + // If authenticated, use token data but preserve persistent ID for message matching + socket.user = { + ...decoded, + persistentId: persistentUserId || decoded.id, + }; + next(); + } else { + // Allow connection but with limited user role, use persistent ID + const username = persistentUserId || `Guest_${socket.id.substring(0, 6)}`; + socket.user = { + id: persistentUserId || socket.id, + username: username, + role: 'user', + persistentId: persistentUserId, + }; + next(); + } +}); + +io.on('connection', (socket) => { + const user = socket.user; + // Use persistent ID if available, otherwise use socket ID + const userId = user.persistentId || user.id || socket.id; + const username = user.username || `Guest_${socket.id.substring(0, 6)}`; + const role = user.role || 'user'; + + // Store user info with persistent ID + connectedUsers.set(socket.id, { + id: userId, + persistentId: user.persistentId || userId, + username, + role, + socketId: socket.id, + }); + + // Send user info to client so they can identify their own messages + socket.emit('userInfo', { + username, + role, + id: userId, + persistentId: user.persistentId || userId, + }); + + // Send chat history to newly connected user + if (chatHistory.length > 0) { + socket.emit('chatHistory', chatHistory); + } + + console.log( + `šŸ‘¤ User connected: ${username} (${role}) [ID: ${userId}] [Socket: ${socket.id}]` + ); + + // Broadcast user joined (only for non-bot users) + if (role !== 'bot') { + const joinMessage = { + id: Date.now(), + username: 'System', + message: `${username} joined the chat`, + role: 'bot', + timestamp: new Date().toISOString(), + type: 'system', + }; + + // Add system messages to history (but don't count toward MAX_HISTORY limit) + chatHistory.push(joinMessage); + if (chatHistory.length > MAX_HISTORY * 2) { + // Only trim if it gets really large + chatHistory.splice(0, chatHistory.length - MAX_HISTORY); + } + + io.emit('chatMessage', joinMessage); + } + + // Handle chat messages + socket.on('chatMessage', (data) => { + const userInfo = connectedUsers.get(socket.id); + if (!userInfo) return; + + const { message } = data; + + // Validate message + if ( + !message || + typeof message !== 'string' || + message.trim().length === 0 + ) { + socket.emit('error', { message: 'Message cannot be empty' }); + return; + } + + if (message.length > 500) { + socket.emit('error', { + message: 'Message is too long (max 500 characters)', + }); + return; + } + + // Create message object with persistent ID for client matching + const chatMessage = { + id: Date.now(), + username: userInfo.username, + message: message.trim(), + role: userInfo.role, + timestamp: new Date().toISOString(), + type: 'user', + userId: userInfo.id, + persistentId: userInfo.persistentId || userInfo.id, + }; + + // Add to chat history + chatHistory.push(chatMessage); + + // Keep only the last MAX_HISTORY messages + if (chatHistory.length > MAX_HISTORY) { + chatHistory.shift(); // Remove oldest message + } + + // Broadcast message to all clients + io.emit('chatMessage', chatMessage); + console.log(`šŸ’¬ [${userInfo.role}] ${userInfo.username}: ${message}`); + }); + + // Moderator/Broadcaster/Admin actions + socket.on('modAction', (data) => { + const userInfo = connectedUsers.get(socket.id); + if (!userInfo) return; + + const { action, targetUsername, reason } = data; + + // Check if user has moderator permissions + if (!hasPermission(userInfo.role, 'moderator')) { + socket.emit('error', { + message: 'Insufficient permissions for this action', + }); + return; + } + + switch (action) { + case 'timeout': + // Find target user and timeout them + const targetSocket = Array.from(connectedUsers.values()).find( + (u) => u.username === targetUsername + )?.socketId; + + if (targetSocket) { + io.to(targetSocket).emit('timeout', { + duration: data.duration || 60, + reason, + }); + io.emit('chatMessage', { + id: Date.now(), + username: 'System', + message: `${targetUsername} has been timed out${reason ? `: ${reason}` : ''}`, + role: 'bot', + timestamp: new Date().toISOString(), + type: 'system', + }); } - try { - res.json(JSON.parse(data)); - } catch (parseErr) { - console.error("Error parsing JSON:", parseErr); - res.status(500).json({ error: "Internal Server Error: Invalid JSON format." }); + break; + + case 'ban': + const banTarget = Array.from(connectedUsers.values()).find( + (u) => u.username === targetUsername + )?.socketId; + + if (banTarget) { + io.to(banTarget).emit('banned', { reason }); + io.to(banTarget).disconnectSockets(); + io.emit('chatMessage', { + id: Date.now(), + username: 'System', + message: `${targetUsername} has been banned${reason ? `: ${reason}` : ''}`, + role: 'bot', + timestamp: new Date().toISOString(), + type: 'system', + }); } - }); + break; + + case 'delete': + // Delete a message by ID (broadcast to all) + io.emit('deleteMessage', { messageId: data.messageId }); + break; + } + }); + + // Handle disconnection + socket.on('disconnect', () => { + const userInfo = connectedUsers.get(socket.id); + if (userInfo && userInfo.role !== 'bot') { + const leaveMessage = { + id: Date.now(), + username: 'System', + message: `${userInfo.username} left the chat`, + role: 'bot', + timestamp: new Date().toISOString(), + type: 'system', + }; + + // Add to history + chatHistory.push(leaveMessage); + if (chatHistory.length > MAX_HISTORY * 2) { + chatHistory.splice(0, chatHistory.length - MAX_HISTORY); + } + + io.emit('chatMessage', leaveMessage); + } + connectedUsers.delete(socket.id); + console.log(`šŸ‘‹ User disconnected: ${socket.id}`); + }); }); -app.listen(PORT, () => { - console.log(`\nāœ… Server successfully started!`); - console.log(`šŸ  Home: http://localhost:${PORT}`); -}); \ No newline at end of file +// ================= SERVER START ================= + +httpServer.listen(PORT, () => { + console.log(`\nāœ… Server successfully started!`); + console.log(`šŸ  Home: http://localhost:${PORT}`); + console.log(`šŸ’¬ Socket.IO server running on port ${PORT}`); +}); diff --git a/src/controllers/AuthControllers.js b/src/controllers/AuthControllers.js index b8bbb5c..e354f26 100644 --- a/src/controllers/AuthControllers.js +++ b/src/controllers/AuthControllers.js @@ -3,7 +3,7 @@ import bcrypt from 'bcrypt'; import jwt from 'jsonwebtoken'; const JWT_SECRET = process.env.JWT_SECRET; -const SALT_ROUNDS = 10; +const SALT_ROUNDS = 10; /** * @route POST /api/auth/register @@ -11,60 +11,63 @@ const SALT_ROUNDS = 10; */ export const register = async (req, res) => { - const { username, email, password } = req.body; - - if (!username || !email || !password) { - return res.status(400).json({ message: 'Please enter all fields.' }); + const { username, email, password } = req.body; + + if (!username || !email || !password) { + return res.status(400).json({ message: 'Please enter all fields.' }); + } + + try { + // 1. Check if user already exists + let user = await User.findOne({ email }); + if (user) { + return res + .status(400) + .json({ message: 'User with that email already exists.' }); } - try { - // 1. Check if user already exists - let user = await User.findOne({ email }); - if (user) { - return res.status(400).json({ message: 'User with that email already exists.' }); - } - - // 2. Hash Password - const salt = await bcrypt.genSalt(SALT_ROUNDS); - const passwordHashed = await bcrypt.hash(password, salt); - - // 3. Create new user instance - user = new User({ - username, - email, - password: passwordHashed, - role: 'user' - }); - - // 4. Save to DB - await user.save(); - - // 5. Create JWT - const payload = { - id: user.id, - role: user.role - }; - const token = jwt.sign(payload, JWT_SECRET, { expiresIn: '1d' }); - - // 6. Respond with token and user info - res.status(201).json({ - token, - user: { - id: user.id, - username: user.username, - email: user.email, - role: user.role - } - }); - - } catch (err) { - // Handle validation errors - if (err.code === 11000) { - return res.status(400).json({ message: 'Username or email already taken.' }); - } - console.error(err.message); - res.status(500).send('Server error during registration.'); + // 2. Hash Password + const salt = await bcrypt.genSalt(SALT_ROUNDS); + const passwordHashed = await bcrypt.hash(password, salt); + + // 3. Create new user instance + user = new User({ + username, + email, + password: passwordHashed, + role: 'user', + }); + + // 4. Save to DB + await user.save(); + + // 5. Create JWT + const payload = { + id: user.id, + role: user.role, + }; + const token = jwt.sign(payload, JWT_SECRET, { expiresIn: '1d' }); + + // 6. Respond with token and user info + res.status(201).json({ + token, + user: { + id: user.id, + username: user.username, + email: user.email, + role: user.role, + }, + }); + } catch (err) { + // Handle validation errors + if (err.code === 11000) { + return res + .status(400) + .json({ message: 'Username or email already taken.' }); } + console.error(err.message); + res.status(500).send('Server error during registration.'); + } }; /** @@ -72,47 +75,48 @@ export const register = async (req, res) => { * @desc Authenticate user and get token */ export const login = async (req, res) => { - const { email, password } = req.body; - - if (!email || !password) { - return res.status(400).json({ message: 'Please enter email and password.' }); + const { email, password } = req.body; + + if (!email || !password) { + return res + .status(400) + .json({ message: 'Please enter email and password.' }); + } + + try { + // 1. Find user by email + const user = await User.findOne({ email }); + if (!user) { + return res.status(400).json({ message: 'Invalid Credentials.' }); } - try { - // 1. Find user by email - const user = await User.findOne({ email }); - if (!user) { - return res.status(400).json({ message: 'Invalid Credentials.' }); - } - - // 2. Compare Password - const isMatch = await bcrypt.compare(password, user.password); - if (!isMatch) { - return res.status(444).json({ message: 'Invalid Credentials.' }); - } - - // 3. Create JWT - const payload = { - id: user.id, - role: user.role - }; - const token = jwt.sign(payload, JWT_SECRET, { expiresIn: '1d' }); - - // 4. Respond with token and user info - res.json({ - token, - user: { - id: user.id, - username: user.username, - email: user.email, - role: user.role - } - }); - - } catch (err) { - console.error(err.message); - res.status(500).send('Server error during login.'); + // 2. Compare Password + const isMatch = await bcrypt.compare(password, user.password); + if (!isMatch) { + return res.status(444).json({ message: 'Invalid Credentials.' }); } + + // 3. Create JWT + const payload = { + id: user.id, + role: user.role, + }; + const token = jwt.sign(payload, JWT_SECRET, { expiresIn: '1d' }); + + // 4. Respond with token and user info + res.json({ + token, + user: { + id: user.id, + username: user.username, + email: user.email, + role: user.role, + }, + }); + } catch (err) { + console.error(err.message); + res.status(500).send('Server error during login.'); + } }; /** @@ -120,16 +124,15 @@ export const login = async (req, res) => { * @desc Get user data (protected route) */ export const getUserDetails = async (req, res) => { - try { - const user = await User.findById(req.user.id).select('-password'); - if (!user) { - return res.status(404).json({ message: 'User not found.' }); - } - // Return the user data (without the password) - res.json(user); - - } catch (err) { - console.error(err.message); - res.status(500).send('Server error retrieving user data.'); + try { + const user = await User.findById(req.user.id).select('-password'); + if (!user) { + return res.status(404).json({ message: 'User not found.' }); } -}; \ No newline at end of file + // Return the user data (without the password) + res.json(user); + } catch (err) { + console.error(err.message); + res.status(500).send('Server error retrieving user data.'); + } +}; diff --git a/src/css/style.css b/src/css/style.css index 1db2bc2..81dd2e5 100644 --- a/src/css/style.css +++ b/src/css/style.css @@ -1,14 +1,18 @@ @import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400&display=swap'); /* Reset and base */ -*, *::before, *::after { +*, +*::before, +*::after { margin: 0; padding: 0; box-sizing: border-box; } :root { - --font-base: 'Roboto', 'OpenSans', 'Lato', 'Montserrat', 'Noto Sans', 'Oswald', 'Poppins', 'Raleway', system-ui, -apple-system, sans-serif; + --font-base: + 'Roboto', 'OpenSans', 'Lato', 'Montserrat', 'Noto Sans', 'Oswald', + 'Poppins', 'Raleway', system-ui, -apple-system, sans-serif; --primary: #4fc3f7; @@ -51,7 +55,9 @@ header { /* Navigation links within the header */ header .nav-link { - color: var(--color-header-text); /* Ensure nav links get the header text color */ + color: var( + --color-header-text + ); /* Ensure nav links get the header text color */ } /* Footer */ @@ -60,7 +66,6 @@ footer { color: var(--color-footer-text); } - /* Card Styles */ .card { background-color: var(--color-card-bg); @@ -72,11 +77,14 @@ footer { } /* Card texts and viewer counts */ -.card-text, .viewer-count, .card-title { +.card-text, +.viewer-count, +.card-title { color: var(--color-card-text); } -.card-text, .viewer-count { +.card-text, +.viewer-count { /* Use card text color to override bootstrap defaults */ color: var(--color-card-text); } @@ -94,13 +102,15 @@ body.dark .badge.bg-primary { #categoryDrawer { width: 280px; transform: translateX(-100%); - transition: transform 0.3s ease-in-out, visibility 0.3s ease-in-out, opacity 0.3s ease-in-out; + transition: + transform 0.3s ease-in-out, + visibility 0.3s ease-in-out, + opacity 0.3s ease-in-out; visibility: hidden; opacity: 0; z-index: 1050; } - #categoryDrawer.open { transform: translateX(0); visibility: visible; @@ -109,12 +119,12 @@ body.dark .badge.bg-primary { /* Dark mode for drawer when body is dark */ body.dark #categoryDrawer { - background-color: #222; /* Dark background for drawer */ - color: #eee; /* Light text for drawer */ + background-color: #222; /* Dark background for drawer */ + color: #eee; /* Light text for drawer */ } body.dark #categoryDrawer a { - color: #eee; /* Light text for drawer links */ + color: #eee; /* Light text for drawer links */ } /* Drawer Overlay */ @@ -157,7 +167,6 @@ body.dark #categoryDrawer a { transform: scale(0.98); } - .column-gap { -moz-column-gap: 1rem; /* For older versions of Firefox */ column-gap: 1rem; /* Adjust the value as needed */ @@ -270,3 +279,276 @@ body.dark .badge { .close-modal:hover { opacity: 0.8; } + +/* ================================ + Chat Container Styles + ================================ */ + +/* Default: Light theme */ +.chat-container { + background-color: #fff; + color: #111; + border: 1px solid #dee2e6; + border-radius: 0.375rem; +} + +/* Chat messages area - light background by default */ +#chatMessages { + background-color: #fff; + color: #111; + border-bottom: 1px solid #dee2e6; + min-height: 300px; + max-height: 300px; + display: flex; + flex-direction: column; +} + +.chat-message { + padding: 0.5rem 0.75rem; + border-radius: var(--radius); + transition: background-color 0.2s ease; + margin-bottom: 0.5rem; + width: 100%; + box-sizing: border-box; +} + +.chat-message:hover { + background-color: rgba(0, 0, 0, 0.03); +} + +.chat-message strong { + color: #111; +} + +.chat-message .text-muted { + color: #6c757d; +} + +/* Input group styling - light theme by default */ +.chat-container .input-group { + background-color: transparent; +} + +.chat-container .input-group .form-control { + background-color: #fff; + color: #212529; + border: 1px solid #ced4da; + border-radius: 0.375rem; +} + +.chat-container .input-group .form-control:focus { + background-color: #fff; + color: #212529; + border-color: #86b7fe; + outline: 0; + box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25); +} + +.chat-container .input-group .form-control::placeholder { + color: #6c757d; +} + +.chat-container .input-group .btn-primary { + background-color: var(--primary); + border-color: var(--primary); + border-radius: 0 0.375rem 0.375rem 0; +} + +.chat-container .input-group .btn-primary:hover { + background-color: #29b6f6; + border-color: #29b6f6; +} + +/* Chat message role badges - consistent with existing badge styles */ +.chat-message .badge { + font-size: 0.7rem; + font-weight: 600; + text-transform: uppercase; + padding: 0.25rem 0.5rem; +} + +/* System messages styling */ +.chat-message.text-muted { + font-style: italic; + padding: 0.25rem 0; + color: #6c757d; +} + +/* Own message styling - right-aligned with distinct background */ +.chat-message.own-message { + padding: 0.5rem 0; + width: 100% !important; + display: flex !important; + justify-content: flex-end !important; + align-items: flex-start !important; + flex-direction: row !important; +} + +.chat-message.own-message > div { + display: flex !important; + justify-content: flex-end !important; + width: 100% !important; + max-width: 100% !important; + flex-direction: row !important; +} + +.chat-message.own-message > div.d-flex { + justify-content: flex-end !important; + width: 100% !important; +} + +.chat-message.own-message > div > div.d-flex { + justify-content: flex-end !important; +} + +.own-message-content { + max-width: 70% !important; + min-width: 200px; + text-align: right; + margin-left: auto !important; + margin-right: 0 !important; + flex-shrink: 0; + flex-grow: 0; +} + +.own-message-bubble { + background-color: var(--primary); + color: #fff; + padding: 0.5rem 0.75rem; + border-radius: 1rem 1rem 0.25rem 1rem; + display: inline-block; + word-wrap: break-word; + text-align: left; + max-width: 100%; +} + +body.dark .own-message-bubble { + background-color: var(--primary); + color: #222; +} + +/* Other users' messages - left-aligned */ +.other-message-bubble { + background-color: #f1f3f5; + color: #111; + padding: 0.5rem 0.75rem; + border-radius: 1rem 1rem 1rem 0.25rem; + display: inline-block; + word-wrap: break-word; + max-width: 100%; +} + +body.dark .other-message-bubble { + background-color: rgba(255, 255, 255, 0.1); + color: var(--color-card-text); +} + +/* Dark mode styles - apply when body.dark is active */ +body.dark .chat-container { + background-color: var(--color-card-bg); + color: var(--color-card-text); + border-color: rgba(255, 255, 255, 0.1); +} + +body.dark #chatMessages { + background-color: var(--color-card-bg); + color: var(--color-card-text); + border-bottom-color: rgba(255, 255, 255, 0.1); +} + +body.dark .chat-message:hover { + background-color: rgba(255, 255, 255, 0.05); +} + +body.dark .chat-message strong { + color: var(--color-card-text); +} + +body.dark .chat-message .text-muted { + color: var(--color-card-text); + opacity: 0.6; +} + +body.dark .chat-container .input-group .form-control { + background-color: var(--color-card-bg); + color: var(--color-card-text); + border-color: rgba(255, 255, 255, 0.1); +} + +body.dark .chat-container .input-group .form-control:focus { + background-color: var(--color-card-bg); + color: var(--color-card-text); + border-color: var(--primary); + box-shadow: 0 0 0 0.2rem rgba(79, 195, 247, 0.25); +} + +body.dark .chat-container .input-group .form-control::placeholder { + color: rgba(255, 255, 255, 0.5); +} + +body.dark .chat-container .border-top { + border-top-color: rgba(255, 255, 255, 0.1) !important; +} + +/* Ensure own messages stay right-aligned on all screen sizes */ +@media (min-width: 1360px) { + .chat-message.own-message { + display: flex !important; + justify-content: flex-end !important; + align-items: flex-start; + } + + .chat-message.own-message > div { + display: flex !important; + justify-content: flex-end !important; + width: 100%; + } + + .chat-message.own-message > div > div.d-flex { + justify-content: flex-end !important; + } + + .own-message-content { + margin-left: auto !important; + margin-right: 0 !important; + max-width: 70%; + } +} + +/* Additional fix for very wide screens */ +@media (min-width: 1920px) { + .chat-message.own-message { + justify-content: flex-end !important; + } + + .own-message-content { + margin-left: auto !important; + margin-right: 0 !important; + } +} + +/* Responsive chat */ +@media (max-width: 768px) { + #chatMessages { + height: 250px !important; + max-height: 250px !important; + } + + .chat-container .input-group { + flex-direction: column; + } + + .chat-container .input-group #chatInput { + border-radius: 0.25rem 0.25rem 0 0; + margin-bottom: 0.25rem; + } + + .chat-container .input-group #sendBtn { + border-radius: 0 0 0.25rem 0.25rem; + width: 100%; + } + + .own-message-content { + max-width: 85%; + } +} diff --git a/src/js/main.js b/src/js/main.js index e7f4cc4..18d9f82 100644 --- a/src/js/main.js +++ b/src/js/main.js @@ -308,6 +308,349 @@ document.addEventListener('DOMContentLoaded', () => { }; fetchStreams(); + + /* ================= CHAT FUNCTIONALITY ================= */ + + const chatMessages = document.getElementById('chatMessages'); + const chatInput = document.getElementById('chatInput'); + const sendBtn = document.getElementById('sendBtn'); + + // Check if chat elements exist before initializing + if (!chatMessages || !chatInput || !sendBtn) { + console.warn('Chat elements not found, skipping chat initialization'); + return; + } + + // Get or create persistent user ID (MUST be before socket connection) + let persistentUserId = localStorage.getItem('chatUserId'); + if (!persistentUserId) { + // Generate a unique ID and save it + persistentUserId = 'guest_' + Date.now() + '_' + Math.random().toString(36).substring(2, 9); + localStorage.setItem('chatUserId', persistentUserId); + console.log('šŸ†” Generated new persistent user ID:', persistentUserId); + } else { + console.log('šŸ†” Using existing user ID:', persistentUserId); + } + + // Initialize Socket.IO connection + // Connect directly to the API server (port 3000) - CORS is configured to allow this + const isDevelopment = window.location.port === '5173' || window.location.hostname === 'localhost'; + const socketUrl = isDevelopment ? 'http://localhost:3000' : window.location.origin; + + console.log('šŸ”Œ Attempting to connect to Socket.IO server at:', socketUrl); + + const socket = io(socketUrl, { + auth: { + token: localStorage.getItem('token') || null, + persistentUserId: persistentUserId + }, + // Try polling first, then upgrade to websocket if available + transports: ['polling', 'websocket'], + // Auto-reconnect settings + reconnection: true, + reconnectionDelay: 1000, + reconnectionDelayMax: 5000, + reconnectionAttempts: 5, + timeout: 20000 + }); + + // Get user info from token or default to 'user' + let currentUserRole = 'user'; + let currentUsername = null; + try { + const token = localStorage.getItem('token'); + if (token) { + const payload = JSON.parse(atob(token.split('.')[1])); + currentUserRole = payload.role || 'user'; + currentUsername = payload.username || null; + } + } catch (e) { + // Token parsing failed, use default role + } + + // If no authenticated username, use persistent ID as username for message matching + if (!currentUsername) { + currentUsername = persistentUserId; + } + + // Store persistent ID for message matching + const userPersistentId = persistentUserId; + + // Role badge colors + const roleColors = { + user: 'secondary', + vip: 'warning', + moderator: 'info', + broadcaster: 'success', + administrator: 'danger', + admin: 'danger', + bot: 'dark' + }; + + // Role display names + const roleNames = { + user: 'User', + vip: 'VIP', + moderator: 'Mod', + broadcaster: 'Broadcaster', + administrator: 'Admin', + admin: 'Admin', + bot: 'Bot' + }; + + // Function to format timestamp + function formatTime(timestamp) { + const date = new Date(timestamp); + return date.toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit' }); + } + + // Function to add message to chat + function addMessageToChat(messageData) { + if (!chatMessages) return; + + const messageDiv = document.createElement('div'); + messageDiv.className = 'chat-message'; + messageDiv.dataset.messageId = messageData.id; + + const isSystem = messageData.type === 'system'; + const roleColor = roleColors[messageData.role] || 'secondary'; + const roleName = roleNames[messageData.role] || 'User'; + + // Check if this is the current user's message + // Match by persistent ID, userId, or username + const isOwnMessage = (currentUsername && messageData.username && + messageData.username.toLowerCase() === currentUsername.toLowerCase()) || + (messageData.userId && messageData.userId === userPersistentId) || + (messageData.persistentId && messageData.persistentId === userPersistentId) || + (messageData.username && messageData.username === userPersistentId); + + if (isOwnMessage) { + messageDiv.classList.add('own-message'); + } + + if (isSystem) { + messageDiv.className += ' text-muted text-center small'; + messageDiv.innerHTML = `${escapeHtml(messageData.message)}`; + } else { + if (isOwnMessage) { + // Right-aligned for own messages + messageDiv.innerHTML = ` +
+
+
+ ${formatTime(messageData.timestamp)} + ${escapeHtml(messageData.username)} + ${roleName} + You +
+
${escapeHtml(messageData.message)}
+
+
+ `; + } else { + // Left-aligned for other users' messages + messageDiv.innerHTML = ` +
+
+
+ ${roleName} + ${escapeHtml(messageData.username)} + ${formatTime(messageData.timestamp)} +
+
${escapeHtml(messageData.message)}
+
+
+ `; + } + } + + chatMessages.appendChild(messageDiv); + chatMessages.scrollTop = chatMessages.scrollHeight; + } + + // Update username when socket connects (server sends user info) + socket.on('userInfo', (userInfo) => { + if (userInfo) { + // Use persistent ID for message matching (most reliable) + if (userInfo.persistentId) { + // Keep persistent ID for matching, but use username for display + if (userInfo.username && userInfo.username !== userInfo.persistentId) { + // Authenticated user - use username for display but persistentId for matching + currentUsername = userInfo.persistentId; // Use persistent ID for matching + localStorage.setItem('chatUsername', userInfo.username); + } else { + currentUsername = userInfo.persistentId; + } + } else if (userInfo.id) { + currentUsername = userInfo.id; + } else if (userInfo.username) { + currentUsername = userInfo.username; + } + console.log('šŸ‘¤ Current user info:', { + username: userInfo.username, + id: userInfo.id, + persistentId: userInfo.persistentId, + currentUsername: currentUsername, + userPersistentId: userPersistentId + }); + } + }); + + // Helper function to escape HTML + function escapeHtml(text) { + const div = document.createElement('div'); + div.textContent = text; + return div.innerHTML; + } + + // Handle incoming chat messages + socket.on('chatMessage', (messageData) => { + addMessageToChat(messageData); + }); + + // Handle chat history on connection + socket.on('chatHistory', (history) => { + if (!chatMessages) return; + + // Clear existing messages (except any error messages) + const errorMessages = chatMessages.querySelectorAll('.alert'); + chatMessages.innerHTML = ''; + errorMessages.forEach(err => chatMessages.appendChild(err)); + + // Load history messages + if (Array.isArray(history) && history.length > 0) { + history.forEach(messageData => { + addMessageToChat(messageData); + }); + console.log(`šŸ“œ Loaded ${history.length} chat history messages`); + } else { + // If no history, show welcome message + addMessageToChat({ + id: Date.now(), + username: 'System', + message: 'Welcome to DevStream Chat!', + role: 'bot', + timestamp: new Date().toISOString(), + type: 'system' + }); + } + }); + + // Handle message deletion (for moderators) + socket.on('deleteMessage', ({ messageId }) => { + const messageElement = chatMessages.querySelector(`[data-message-id="${messageId}"]`); + if (messageElement) { + messageElement.remove(); + } + }); + + // Handle timeout + socket.on('timeout', ({ duration, reason }) => { + chatInput.disabled = true; + sendBtn.disabled = true; + chatInput.placeholder = `You are timed out for ${duration} seconds${reason ? `: ${reason}` : ''}`; + + setTimeout(() => { + chatInput.disabled = false; + sendBtn.disabled = false; + chatInput.placeholder = 'Send a message...'; + }, duration * 1000); + }); + + // Handle ban + socket.on('banned', ({ reason }) => { + chatInput.disabled = true; + sendBtn.disabled = true; + chatInput.placeholder = `You have been banned${reason ? `: ${reason}` : ''}`; + socket.disconnect(); + }); + + // Handle errors + socket.on('error', ({ message }) => { + const errorDiv = document.createElement('div'); + errorDiv.className = 'alert alert-danger alert-dismissible fade show'; + errorDiv.innerHTML = ` + ${escapeHtml(message)} + + `; + chatMessages.appendChild(errorDiv); + setTimeout(() => errorDiv.remove(), 5000); + }); + + socket.on('disconnect', () => { + console.log('āŒ Disconnected from chat server'); + }); + + socket.on('connect_error', (error) => { + console.error('āŒ Chat connection error:', error); + console.error('Error details:', { + message: error.message, + type: error.type, + description: error.description + }); + + if (chatMessages) { + // Remove any existing error messages + const existingError = chatMessages.querySelector('.alert-warning'); + if (existingError) existingError.remove(); + + const errorMsg = document.createElement('div'); + errorMsg.className = 'alert alert-warning alert-dismissible fade show'; + errorMsg.innerHTML = ` + Chat Connection Error: Unable to connect to chat server. + Please make sure the server is running on port 3000. + + `; + chatMessages.appendChild(errorMsg); + } + }); + + socket.on('reconnect_attempt', () => { + console.log('šŸ”„ Attempting to reconnect to chat server...'); + }); + + socket.on('reconnect', (attemptNumber) => { + console.log(`āœ… Reconnected to chat server after ${attemptNumber} attempts`); + if (chatMessages) { + const existingError = chatMessages.querySelector('.alert-warning'); + if (existingError) existingError.remove(); + } + }); + + socket.on('reconnect_failed', () => { + console.error('āŒ Failed to reconnect to chat server'); + if (chatMessages) { + const errorMsg = document.createElement('div'); + errorMsg.className = 'alert alert-danger'; + errorMsg.textContent = 'Failed to reconnect to chat. Please refresh the page.'; + chatMessages.appendChild(errorMsg); + } + }); + + // Send message function + function sendMessage() { + const message = chatInput.value.trim(); + if (!message) return; + + socket.emit('chatMessage', { message }); + chatInput.value = ''; + } + + // Event listeners for sending messages + sendBtn.addEventListener('click', sendMessage); + chatInput.addEventListener('keypress', (e) => { + if (e.key === 'Enter' && !e.shiftKey) { + e.preventDefault(); + sendMessage(); + } + }); + + // Handle connection - history will be loaded via chatHistory event + socket.on('connect', () => { + console.log('āœ… Connected to chat server'); + // Welcome message will be added only if no history is received + // (handled in chatHistory event handler) + }); }); /* ================= SERVICE WORKER ================= */ diff --git a/src/middleware/auth.js b/src/middleware/auth.js index 9d6a898..84e4b1a 100644 --- a/src/middleware/auth.js +++ b/src/middleware/auth.js @@ -11,28 +11,29 @@ const JWT_SECRET = process.env.JWT_SECRET; */ export const auth = (req, res, next) => { - const authHeader = req.header('Authorization'); - - if (!authHeader) { - return res.status(401).json({ message: 'No token, authorization denied.' }); - } - - const token = authHeader.split(' ')[1]; - - if (!token) { - return res.status(401).json({ message: 'Token format invalid. Use Bearer scheme.' }); - } - - try { - const decoded = jwt.verify(token, JWT_SECRET); - - req.user = decoded; - - next(); - - } catch (err) { - res.status(401).json({ message: 'Token is not valid or has expired.' }); - } + const authHeader = req.header('Authorization'); + + if (!authHeader) { + return res.status(401).json({ message: 'No token, authorization denied.' }); + } + + const token = authHeader.split(' ')[1]; + + if (!token) { + return res + .status(401) + .json({ message: 'Token format invalid. Use Bearer scheme.' }); + } + + try { + const decoded = jwt.verify(token, JWT_SECRET); + + req.user = decoded; + + next(); + } catch (err) { + res.status(401).json({ message: 'Token is not valid or has expired.' }); + } }; /** @@ -41,11 +42,15 @@ export const auth = (req, res, next) => { * @param {string[]} requiredRoles Array of roles allowed (e.g., ['admin', 'moderator']) */ export const authorizeRole = (requiredRoles) => (req, res, next) => { - if (!req.user || !req.user.role) { - return res.status(500).json({ message: 'Authorization setup error: User role not found.' }); - } - if (!requiredRoles.includes(req.user.role)) { - return res.status(403).json({ message: 'Access denied. Insufficient permissions.' }); - } - next(); -}; \ No newline at end of file + if (!req.user || !req.user.role) { + return res + .status(500) + .json({ message: 'Authorization setup error: User role not found.' }); + } + if (!requiredRoles.includes(req.user.role)) { + return res + .status(403) + .json({ message: 'Access denied. Insufficient permissions.' }); + } + next(); +}; diff --git a/src/models/User.js b/src/models/User.js index e82ea2a..cda73a9 100644 --- a/src/models/User.js +++ b/src/models/User.js @@ -1,49 +1,57 @@ import mongoose from 'mongoose'; const UserSchema = new mongoose.Schema({ - username: { - type: String, - required: [true, 'Username is required'], - unique: true, - trim: true, - lowercase: true, - maxlength: 50 - }, - email: { - type: String, - required: [true, 'Email is required'], - unique: true, - trim: true, - lowercase: true, - match: [/.+\@.+\..+/, 'Please fill a valid email address'] - }, - // Store the hashed password - password: { - type: String, - required: [true, 'Password is required'], - minlength: 6 - }, - role: { - type: String, - enum: ['user', 'admin'], // For future authorization - default: 'user' - }, - createdAt: { - type: Date, - default: Date.now - } + username: { + type: String, + required: [true, 'Username is required'], + unique: true, + trim: true, + lowercase: true, + maxlength: 50, + }, + email: { + type: String, + required: [true, 'Email is required'], + unique: true, + trim: true, + lowercase: true, + match: [/.+\@.+\..+/, 'Please fill a valid email address'], + }, + // Store the hashed password + password: { + type: String, + required: [true, 'Password is required'], + minlength: 6, + }, + role: { + type: String, + enum: [ + 'user', + 'admin', + 'moderator', + 'vip', + 'administrator', + 'broadcaster', + 'bot', + ], + default: 'user', + }, + createdAt: { + type: Date, + default: Date.now, + }, }); // Hide the password and version key when converting to JSON UserSchema.set('toJSON', { - transform: (document, returnedObject) => { - returnedObject.id = returnedObject._id.toString(); - delete returnedObject._id; - delete returnedObject.__v; - delete returnedObject.password; // Never send the hash to the client! - } + transform: (document, returnedObject) => { + returnedObject.id = returnedObject._id.toString(); + delete returnedObject._id; + delete returnedObject.__v; + delete returnedObject.password; // Never send the hash to the client! + }, }); const User = mongoose.model('User', UserSchema); -export default User; \ No newline at end of file +export default User;