feat: introduce CHANNEL_SELECTION_REQUIRES_ADMIN option

This commit is contained in:
antebrl
2025-10-07 23:09:43 +02:00
parent b5c0769654
commit 4fe017a15c
11 changed files with 53 additions and 39 deletions

View File

@@ -30,6 +30,7 @@ module.exports = {
checkAdminStatus(req, res) {
res.json({
enabled: authService.isAdminEnabled(),
channelSelectionRequiresAdmin: authService.channelSelectionRequiresAdmin(),
});
},

View File

@@ -10,7 +10,6 @@
"license": "ISC",
"dependencies": {
"child_process": "^1.0.2",
"cookie-parser": "^1.4.6",
"crypto": "^1.0.1",
"dotenv": "^16.4.5",
"express": "^4.21.1",
@@ -232,28 +231,6 @@
"node": ">= 0.6"
}
},
"node_modules/cookie-parser": {
"version": "1.4.7",
"resolved": "https://registry.npmjs.org/cookie-parser/-/cookie-parser-1.4.7.tgz",
"integrity": "sha512-nGUvgXnotP3BsjiLX2ypbQnWoGUPIIfHQNZkkC668ntrzGWEZVW70HDEB1qnNGMicPje6EttlIgzo51YSwNQGw==",
"license": "MIT",
"dependencies": {
"cookie": "0.7.2",
"cookie-signature": "1.0.6"
},
"engines": {
"node": ">= 0.8.0"
}
},
"node_modules/cookie-parser/node_modules/cookie": {
"version": "0.7.2",
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.2.tgz",
"integrity": "sha512-yki5XnKuf750l50uGTllt6kKILY4nQ1eNIQatoXEByZ5dWgnKqbnqmTrBE5B4N7lrMJKQ2ytWMiTO2o0v6Ew/w==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/cookie-signature": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz",

View File

@@ -20,7 +20,6 @@
"homepage": "https://github.com/antebrl/iptv-restream#readme",
"dependencies": {
"child_process": "^1.0.2",
"cookie-parser": "^1.4.6",
"crypto": "^1.0.1",
"dotenv": "^16.4.5",
"express": "^4.21.1",

View File

@@ -1,7 +1,6 @@
const express = require('express');
const dotenv = require('dotenv');
const { Server } = require('socket.io');
const cookieParser = require('cookie-parser');
const ChatSocketHandler = require('./socket/ChatSocketHandler');
const ChannelSocketHandler = require('./socket/ChannelSocketHandler');
@@ -20,7 +19,6 @@ dotenv.config();
const app = express();
app.use(express.json());
app.use(cookieParser());
// CORS middleware
app.use((req, res, next) => {

View File

@@ -8,6 +8,8 @@ require("dotenv").config();
class AuthService {
constructor() {
this.ADMIN_ENABLED = process.env.ADMIN_ENABLED === "true";
this.CHANNEL_SELECTION_REQUIRES_ADMIN =
process.env.CHANNEL_SELECTION_REQUIRES_ADMIN === "true";
this.ADMIN_PASSWORD = process.env.ADMIN_PASSWORD;
this.JWT_EXPIRY = process.env.JWT_EXPIRY || "24h";
@@ -28,6 +30,13 @@ class AuthService {
.update(this.ADMIN_PASSWORD || "")
.digest("hex");
}
/**
* Check if channel selection needs admin
* @returns {boolean}
*/
channelSelectionRequiresAdmin() {
return this.CHANNEL_SELECTION_REQUIRES_ADMIN && this.ADMIN_ENABLED;
}
/**
* Generate a JWT token for an admin user

View File

@@ -28,6 +28,15 @@ module.exports = (io, socket) => {
socket.on("set-current-channel", async (id) => {
try {
if (
authService.isAdminEnabled() &&
authService.channelSelectionRequiresAdmin() &&
!socket.user?.isAdmin
) {
return socket.emit("app-error", {
message: "Admin access required to switch channel",
});
}
const nextChannel = await ChannelService.setCurrentChannel(id);
io.emit("channel-selected", nextChannel); // Broadcast to all clients
} catch (err) {

View File

@@ -5,8 +5,6 @@ const Playlist = require("../models/Playlist");
const authService = require("../services/auth/AuthService");
require("dotenv").config();
const ADMIN_ENABLED = process.env.ADMIN_ENABLED === "true";
async function handleAddPlaylist(
{ playlist, playlistName, mode, playlistUpdate, headers },
io,