Skip to content

Commit c73695e

Browse files
committed
r0b08x [chore] 4/25/2024, 2:01:43 AM
1 parent 02e4f2d commit c73695e

File tree

9 files changed

+96
-36
lines changed

9 files changed

+96
-36
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ https://corifeus.com/redis-ui
1212

1313

1414
---
15-
# 🏍️ The p3x-redis-ui-server package motor that is connected to the p3x-redis-ui-material web user interface v2024.4.219
15+
# 🏍️ The p3x-redis-ui-server package motor that is connected to the p3x-redis-ui-material web user interface v2024.4.221
1616

1717

1818

@@ -26,7 +26,7 @@ https://corifeus.com/redis-ui
2626
### Built on NodeJs version
2727

2828
```txt
29-
v20.12.1
29+
v20.12.2
3030
```
3131

3232

@@ -112,7 +112,7 @@ All my domains ([patrikx3.com](https://patrikx3.com) and [corifeus.com](https://
112112

113113
---
114114

115-
[**P3X-REDIS-UI-SERVER**](https://corifeus.com/redis-ui-server) Build v2024.4.219
115+
[**P3X-REDIS-UI-SERVER**](https://corifeus.com/redis-ui-server) Build v2024.4.221
116116

117117
[![NPM](https://img.shields.io/npm/v/p3x-redis-ui-server.svg)](https://www.npmjs.com/package/p3x-redis-ui-server) [![Donate for Corifeus / P3X](https://img.shields.io/badge/Donate-Corifeus-003087.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=QZVM4V6HVZJW6) [![Contact Corifeus / P3X](https://img.shields.io/badge/Contact-P3X-ff9900.svg)](https://www.patrikx3.com/en/front/contact) [![Like Corifeus @ Facebook](https://img.shields.io/badge/LIKE-Corifeus-3b5998.svg)](https://www.facebook.com/corifeus.software)
118118

artifacts/boot/p3xrs.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
"p3xrs": {
33
"http": {
44
"port-info": "this is ommitted, it will be default 7843",
5-
"port": 7843
5+
"port": 7843,
6+
"bind-info": "the interface with listen to, could be 127.0.0.1 or 0.0.0.0 or specific interface",
7+
"bind": "0.0.0.0"
68
},
79
"connections": {
810
"home-dir-info": "if the dir config is empty or home, the connections are saved in the home folder, otherwise it will resolve the directory set as it is, either relative ./ or absolute starting with /. NodeJs will resolve this directory in p3xrs.connections.dir",

artifacts/cluster.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ All my domains ([patrikx3.com](https://patrikx3.com) and [corifeus.com](https://
2525

2626
---
2727

28-
[**P3X-REDIS-UI-SERVER**](https://corifeus.com/redis-ui-server) Build v2024.4.219
28+
[**P3X-REDIS-UI-SERVER**](https://corifeus.com/redis-ui-server) Build v2024.4.221
2929

3030
[![NPM](https://img.shields.io/npm/v/p3x-redis-ui-server.svg)](https://www.npmjs.com/package/p3x-redis-ui-server) [![Donate for Corifeus / P3X](https://img.shields.io/badge/Donate-Corifeus-003087.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=QZVM4V6HVZJW6) [![Contact Corifeus / P3X](https://img.shields.io/badge/Contact-P3X-ff9900.svg)](https://www.patrikx3.com/en/front/contact) [![Like Corifeus @ Facebook](https://img.shields.io/badge/LIKE-Corifeus-3b5998.svg)](https://www.facebook.com/corifeus.software)
3131

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"name": "p3x-redis-ui-server",
3-
"version": "2024.4.219",
3+
"version": "2024.4.221",
44
"description": "🏍️ The p3x-redis-ui-server package motor that is connected to the p3x-redis-ui-material web user interface",
55
"corifeus": {
66
"icon": "fas fa-flag-checkered",
77
"code": "Reverse",
88
"opencollective": false,
99
"build": true,
10-
"nodejs": "v20.12.1",
10+
"nodejs": "v20.12.2",
1111
"reponame": "redis-ui-server",
1212
"publish": true,
1313
"prefix": "p3x-",
@@ -58,8 +58,8 @@
5858
"chalk": "^4.1.2",
5959
"commander": "^12.0.0",
6060
"corifeus-utils": "^2024.4.118",
61-
"ioredis": "^5.3.2",
62-
"koa": "^2.15.2",
61+
"ioredis": "^5.4.1",
62+
"koa": "^2.15.3",
6363
"koa-send": "^5.0.1",
6464
"koa-static": "^5.0.0",
6565
"lodash": "^4.17.21",

src/lib/cli.js

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,25 @@ const cli = () => {
2020
if (!process.versions.hasOwnProperty('electron') && !process.env.hasOwnProperty('P3XRS_DOCKER_HOME')) {
2121

2222
if (!programOptions.config) {
23-
24-
25-
programOptions.config = path.resolve(path.dirname(require.main.filename) + path.sep + '..', `.${path.sep}p3xrs.json`)
23+
const path = require('path');
24+
const fs = require('fs');
25+
const findConfigFile = (startPath, filename) => {
26+
let currentPath = startPath;
27+
while (currentPath !== path.resolve(currentPath, '..')) { // Check until we reach the root directory
28+
const filePath = path.join(currentPath, filename);
29+
if (fs.existsSync(filePath)) {
30+
return filePath;
31+
}
32+
currentPath = path.resolve(currentPath, '..'); // Move up one directory level
33+
}
34+
throw new Error('The specified configuration file could not be found.');
35+
}
36+
const resolveConfigPath = () => {
37+
// Attempt to find the config file starting from the directory of the main script or current directory
38+
const startPath = process.cwd();
39+
return findConfigFile(startPath, 'p3xrs.json');
40+
}
41+
programOptions.config = resolveConfigPath()
2642

2743
// program.outputHelp()
2844
// return false
@@ -51,7 +67,9 @@ const cli = () => {
5167
p3xrs.cfg = {
5268
"http": {
5369
"port-info": "this is ommitted, it will be default 7843",
54-
"port": process.env.hasOwnProperty('P3XRS_DOCKER_HOME') ? 7843 : global.p3xrsElectronPort
70+
"port": process.env.hasOwnProperty('P3XRS_DOCKER_HOME') ? 7843 : global.p3xrsElectronPort,
71+
"bind-info": "the interface with listen to, could be 127.0.0.1 or 0.0.0.0 or specific interface",
72+
"bind": "0.0.0.0",
5573
},
5674
"connections": {
5775
"home-dir-info": "if the dir config is empty or home, the connections are saved in the home folder, otherwise it will resolve the directory set as it is, either relative ./ or absolute starting with /. NodeJs will resolve this directory in p3xrs.connections.dir",

src/service/koa/index.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,31 @@ const koaService = function () {
1818

1919
// app.use(koaBody());
2020

21+
const path = require('path');
22+
const fs = require('fs');
23+
24+
const findModulePath = (startPath, targetPath) => {
25+
let currentPath = startPath;
26+
while (currentPath !== path.resolve(currentPath, '..')) { // Check until we reach the root directory
27+
const nodeModulesPath = path.join(currentPath, targetPath);
28+
if (fs.existsSync(nodeModulesPath)) {
29+
return nodeModulesPath;
30+
}
31+
currentPath = path.resolve(currentPath, '..'); // Move up one directory level
32+
}
33+
throw new Error('The specified module could not be found in any node_modules directory');
34+
}
35+
2136
const resolvePath = (inputPath) => {
22-
let resolvedPath
2337
if (inputPath.startsWith('~')) {
24-
const inputPathFromNodeModules = inputPath.substring(1)
25-
resolvedPath = path.resolve(path.dirname(require.main.filename) + path.sep + '..', `node_modules${path.sep}${inputPathFromNodeModules}`)
38+
const inputPathFromNodeModules = inputPath.substring(1);
39+
// Attempt to find the module starting from the directory of the main script or current directory
40+
const startPath = __dirname;
41+
return findModulePath(startPath, inputPathFromNodeModules);
2642
} else {
27-
resolvedPath = path.resolve(process.cwd(), inputPath)
43+
// Resolve the path relative to the current working directory for non-module specific paths
44+
return path.resolve(process.cwd(), inputPath);
2845
}
29-
return resolvedPath
3046
}
3147

3248
let hasStatic = false

src/service/socket.io/request/connection-connect.js

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -322,24 +322,6 @@ module.exports = async (options) => {
322322
redis.on('disconnect', redisErrorFun)
323323
redisSubscriber.on('error', redisErrorFun)
324324

325-
//console.warn('create psubscribe', actualConnection.id)
326-
redisSubscriber.psubscribe('*', function (error, count) {
327-
if (error) {
328-
console.error(error)
329-
}
330-
})
331-
332-
//console.warn('create pmessage', actualConnection.id)
333-
redisSubscriber.on('pmessage', function (channel, pattern, message) {
334-
//console.log(`receive pmessage channel: ${channel} - pattern: ${pattern}, message: ${message}`);
335-
//console.log('list clients', actualConnection.id, JSON.stringify(p3xrs.redisConnections[actualConnection.id].clients, null, 4))
336-
337-
socket.emit('pubsub-message', {
338-
channel: pattern,
339-
message: message,
340-
})
341-
});
342-
343325
redis.on('connect', async function () {
344326

345327
try {
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
module.exports = async (options) => {
2+
const { socket, payload } = options;
3+
4+
try {
5+
if (socket.p3xrs && socket.p3xrs.subscription) {
6+
// Unsubscribe before clearing the old listener to prevent memory leaks
7+
await socket.p3xrs.ioredisSubscriber.punsubscribe('*');
8+
9+
// Remove old listeners to prevent multiple listeners from accumulating
10+
socket.p3xrs.ioredisSubscriber.removeAllListeners('pmessage');
11+
}
12+
13+
// Updating subscription settings
14+
socket.p3xrs.subscription = payload.subscription;
15+
if (typeof payload.subscriberPattern !== 'string' || payload.subscriberPattern.trim().length === 0) {
16+
payload.subscriberPattern = '*'; // Default pattern
17+
}
18+
19+
if (socket.p3xrs.subscription === true) {
20+
// Subscribe to the pattern
21+
await socket.p3xrs.ioredisSubscriber.psubscribe(payload.subscriberPattern);
22+
23+
console.log('socket.p3xrs.subscription', payload.subscriberPattern)
24+
25+
// Handle incoming messages
26+
socket.p3xrs.ioredisSubscriber.on('pmessage', (pattern, channel, message) => {
27+
//console.log('subscription', pattern, channel, message)
28+
socket.emit('pubsub-message', {
29+
channel: channel,
30+
message: message,
31+
});
32+
});
33+
}
34+
// Confirm successful setup
35+
socket.emit(options.responseEvent, { status: 'ok' });
36+
} catch (e) {
37+
console.error('Subscription error:', e);
38+
socket.emit(options.responseEvent, { status: 'error', error: e.message });
39+
}
40+
};
41+

src/service/socket.io/socket.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ module.exports = (io) => {
2727
tunnelClient: undefined,
2828
readonly: undefined,
2929
// commands: undefined,
30+
subsciber: false,
3031
}
3132

3233
console.info(`socket.io connected ${socket.id}`);

0 commit comments

Comments
 (0)