add useless debug panel and do not allow user to subscribe twice to room to be safe

This commit is contained in:
hippoz 2020-11-20 13:25:08 +02:00
parent 9d1adfe748
commit ced4d4652a
3 changed files with 52 additions and 15 deletions

View file

@ -30,7 +30,7 @@ GatewayServer.prototype.eventSetup = function() {
setTimeout(() => {
if (socket.isConnected) return;
console.log('[*] [gateway] [handshake] User still not connected after timeout, removing...');
console.log('[E] [gateway] [handshake] User still not connected after timeout, removing...');
socket.disconnect();
socket.disconnect(true);
}, config.gatewayStillNotConnectedTimeoutMS);
@ -108,13 +108,15 @@ GatewayServer.prototype.eventSetup = function() {
socket.on('subscribe', async (categories) => {
if (!categories || !Array.isArray(categories) || categories === []) return;
for (let v of categories) {
for (const v of categories) {
if (!v) continue;
// TODO: When/if category permissions are added, check if the user has permissions for that category
const category = await Category.findById(v);
if (category && category.title && category._id) {
if (!socket.joinedCategories) socket.joinedCategories = {};
socket.joinedCategories[v] = category.title;
socket.join(v);
if (socket.joinedCategories[category._id]) continue;
socket.joinedCategories[category._id] = category.title;
socket.join(category._id);
}
}
});

View file

@ -47,6 +47,29 @@
<body>
<div id="app">
<div id="appContainer" v-if="showApp">
<md-dialog id="debug-dialog" :md-active.sync="dialog.show.debug">
<md-dialog-title>Debug info and shit</md-dialog-title>
<md-dialog-content>
<p>gateway.isConnected: {{ gateway.isConnected }}</p>
<p v-if="gateway.socket.id">gateway.socket.id: {{ gateway.socket.id }}</p>
<p v-if="gateway.debugInfo">gateway.debugInfo: {{ JSON.stringify(gateway.debugInfo) }}</p>
<p v-if="loggedInUser._id">userLoggedIn: true</p>
<p v-if="!loggedInUser._id">userLoggedIn: false</p>
<div id="debug-logged-in-data" v-if="loggedInUser">
<p>loggedInUser.username: {{ loggedInUser.username }}</p>
<p>loggedInUser._id: {{ loggedInUser._id }}</p>
<p>loggedInUser.permissionLevel: {{ loggedInUser.permissionLevel }}</p>
<p>loggedInUser.role: {{ loggedInUser.role }}</p>
</div>
<md-dialog-actions>
<md-button @click="debugDump()">Dump</md-button>
<md-button @click="dialog.show.debug = false">Close</md-button>
</md-dialog-actions>
</md-dialog-content>
</md-dialog>
<md-dialog id="create-category-dialog" :md-active.sync="dialog.show.createCategory">
<md-dialog-title>Create category</md-dialog-title>
@ -102,6 +125,7 @@
<md-button md-menu-trigger>{{ loggedInUser.username }}</md-button>
<md-menu-content>
<md-menu-item @click="navigateToAccountManager()">Manage account</md-menu-item>
<md-menu-item @click="toggleDebugDialog()">Debug info and shit</md-menu-item>
</md-menu-content>
</md-menu>
</md-toolbar>

View file

@ -84,6 +84,7 @@ GatewayConnection.prototype.connect = function(token) {
console.log('[*] [gateway] [handshake] Got hello from server, sending yoo...', debugInfo);
this.socket.emit('yoo');
this.isConnected = true;
this.debugInfo = debugInfo;
this.onConnect('CONNECT_RECEIVED_HELLO');
console.log('[*] [gateway] [handshake] Assuming that server received yoo and that connection is completed.');
});
@ -150,7 +151,8 @@ const app = new Vue({
dialog: {
show: {
createPost: false,
createCategory: false
createCategory: false,
debug: false
},
text: {
createPost: {
@ -242,6 +244,15 @@ const app = new Vue({
this.message.typed = '';
},
// Debug
toggleDebugDialog: async function() {
this.dialog.show.debug = !this.dialog.show.debug;
},
debugDump: async function() {
console.log('[DEBUG DUMP] [gateway]', this.gateway);
console.log('[DEBUG DUMP] [loggedInUser] (this contains sensitive information about the current logged in user, do not leak it to other people lol)', this.loggedInUser);
},
// Category and post browsing
browseCategories: async function() {
const res = await fetch(`${window.location.origin}/api/v1/content/category/list?count=50`, {
@ -387,6 +398,11 @@ const app = new Vue({
});
if (res.ok) {
this.okNotification('Successfully created post');
this.dialog.show.createPost = false;
this.browse(this.selection.category);
return;
} else {
if (res.status === 401 || res.status === 403) {
this.okNotification('You are not allowed to do that');
return;
@ -399,11 +415,6 @@ const app = new Vue({
const json = await res.json();
this.okNotification(getCreatePostError(json));
return;
} else {
this.okNotification('Successfully created post');
this.dialog.show.createPost = false;
this.browse(this.selection.category);
return;
}
},
createCategory: async function() {
@ -422,6 +433,11 @@ const app = new Vue({
});
if (res.ok) {
this.okNotification('Successfully created category');
this.dialog.show.createCategory = false;
this.browseCategories();
return;
} else {
if (res.status === 401 || res.status === 403) {
this.okNotification('You are not allowed to do that');
return;
@ -434,11 +450,6 @@ const app = new Vue({
const json = await res.json();
this.okNotification(getCreateCategoryError(json));
return;
} else {
this.okNotification('Successfully created category');
this.dialog.show.createCategory = false;
this.browseCategories();
return;
}
},