topnic-https 0.1.8 β 0.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/cli.js +26 -19
- package/package.json +5 -1
- package/src/main/index.js +7 -1
- package/src/main/websocket.js +2 -2
- package/src/sharing/shareManager.js +25 -27
- package/src/utils/monitor.js +7 -2
package/bin/cli.js
CHANGED
@@ -2,7 +2,14 @@
|
|
2
2
|
|
3
3
|
const { program } = require('commander');
|
4
4
|
const server = require('../src/main/index.js');
|
5
|
-
const shareManager = require('../src/sharing/shareManager');
|
5
|
+
const shareManager = require('../src/sharing/shareManager.js');
|
6
|
+
|
7
|
+
program
|
8
|
+
.command('help')
|
9
|
+
.description('Show help for commands')
|
10
|
+
.action(() => {
|
11
|
+
program.help();
|
12
|
+
});
|
6
13
|
|
7
14
|
program
|
8
15
|
.version('1.0.0')
|
@@ -38,20 +45,20 @@ program
|
|
38
45
|
|
39
46
|
program
|
40
47
|
.command('share')
|
41
|
-
.description('Share
|
48
|
+
.description('Share local server temporarily')
|
42
49
|
.option('-p, --port <number>', 'Port to share', 3000)
|
43
50
|
.option('-d, --duration <minutes>', 'Share duration in minutes', 60)
|
44
51
|
.action(async (options) => {
|
45
52
|
try {
|
46
53
|
const share = await shareManager.createShare(options.port, options.duration);
|
47
|
-
console.log('\
|
48
|
-
console.log('
|
49
|
-
console.log(
|
50
|
-
console.log(
|
51
|
-
console.log(
|
52
|
-
console.log('
|
54
|
+
console.log('\nShare Information:');
|
55
|
+
console.log('--------------------------------');
|
56
|
+
console.log(`Public URL: ${share.url}`);
|
57
|
+
console.log(`Share ID: ${share.id}`);
|
58
|
+
console.log(`Duration: ${options.duration} minutes`);
|
59
|
+
console.log('--------------------------------\n');
|
53
60
|
} catch (error) {
|
54
|
-
console.error('
|
61
|
+
console.error('Failed to create share:', error.message);
|
55
62
|
}
|
56
63
|
});
|
57
64
|
|
@@ -61,30 +68,30 @@ program
|
|
61
68
|
.action(() => {
|
62
69
|
const shares = shareManager.getActiveShares();
|
63
70
|
if (shares.length === 0) {
|
64
|
-
console.log('
|
71
|
+
console.log('No active shares');
|
65
72
|
return;
|
66
73
|
}
|
67
74
|
|
68
|
-
console.log('\
|
69
|
-
console.log('
|
75
|
+
console.log('\nActive Shares:');
|
76
|
+
console.log('--------------------------------');
|
70
77
|
shares.forEach(share => {
|
71
|
-
console.log(
|
72
|
-
console.log(
|
73
|
-
console.log(
|
74
|
-
console.log('
|
78
|
+
console.log(`URL: ${share.url}`);
|
79
|
+
console.log(`ID: ${share.id}`);
|
80
|
+
console.log(`Remaining: ${share.remainingMinutes} minutes`);
|
81
|
+
console.log('--------------------------------');
|
75
82
|
});
|
76
83
|
console.log('');
|
77
84
|
});
|
78
85
|
|
79
86
|
program
|
80
87
|
.command('unshare <shareId>')
|
81
|
-
.description('Stop
|
88
|
+
.description('Stop a specific share')
|
82
89
|
.action(async (shareId) => {
|
83
90
|
try {
|
84
91
|
await shareManager.closeShare(shareId);
|
85
|
-
console.log(
|
92
|
+
console.log(`Share ${shareId} stopped successfully`);
|
86
93
|
} catch (error) {
|
87
|
-
console.error('
|
94
|
+
console.error('Failed to stop share:', error.message);
|
88
95
|
}
|
89
96
|
});
|
90
97
|
|
package/package.json
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
{
|
2
2
|
"name": "topnic-https",
|
3
|
-
"version": "0.1.
|
3
|
+
"version": "0.1.10",
|
4
4
|
"main": "./src/main/index.js",
|
5
|
+
"type": "commonjs",
|
5
6
|
"scripts": {
|
6
7
|
"test": "echo \"Error: no test specified\" && exit 1"
|
7
8
|
},
|
@@ -89,12 +90,15 @@
|
|
89
90
|
"dependencies": {
|
90
91
|
"chokidar": "^4.0.1",
|
91
92
|
"commander": "^12.1.0",
|
93
|
+
"crypto": "^1.0.1",
|
92
94
|
"electron": "^33.2.0",
|
93
95
|
"fs": "^0.0.1-security",
|
94
96
|
"https": "^1.0.0",
|
95
97
|
"localtunnel": "^2.0.2",
|
96
98
|
"nanoid": "^5.0.8",
|
99
|
+
"os": "^0.1.2",
|
97
100
|
"path": "^0.12.7",
|
101
|
+
"uuid": "^11.0.3",
|
98
102
|
"ws": "^8.18.0"
|
99
103
|
}
|
100
104
|
}
|
package/src/main/index.js
CHANGED
@@ -275,6 +275,13 @@ function changePort(newPort) {
|
|
275
275
|
console.log(`Port changed to ${currentPort}`);
|
276
276
|
}
|
277
277
|
|
278
|
+
function help(){
|
279
|
+
console.log('Usage: topnic-https [command]');
|
280
|
+
console.log('Commands:');
|
281
|
+
console.log(' run Start the HTTPS server');
|
282
|
+
console.log(' stop Stop the HTTPS server');
|
283
|
+
console.log(' restart Restart the HTTPS server');
|
284
|
+
}
|
278
285
|
function registerShortcuts() {
|
279
286
|
globalShortcut.register('CommandOrControl+Shift+H+R', () => {
|
280
287
|
console.log('π Starting server via shortcut...');
|
@@ -301,7 +308,6 @@ module.exports = {
|
|
301
308
|
stop,
|
302
309
|
restart,
|
303
310
|
changePort,
|
304
|
-
configure,
|
305
311
|
registerShortcuts,
|
306
312
|
unregisterShortcuts
|
307
313
|
};
|
package/src/main/websocket.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
import WebSocket from 'ws';
|
2
2
|
|
3
3
|
function setupWebSocket(server) {
|
4
4
|
const wss = new WebSocket.Server({ server });
|
@@ -22,4 +22,4 @@ function notifyClients(wss, message) {
|
|
22
22
|
});
|
23
23
|
}
|
24
24
|
|
25
|
-
|
25
|
+
export { setupWebSocket, notifyClients };
|
@@ -1,6 +1,5 @@
|
|
1
1
|
const localtunnel = require('localtunnel');
|
2
|
-
const {
|
3
|
-
const Logger = require('../utils/logger');
|
2
|
+
const { v4: uuidv4 } = require('uuid');
|
4
3
|
|
5
4
|
class ShareManager {
|
6
5
|
constructor() {
|
@@ -9,54 +8,53 @@ class ShareManager {
|
|
9
8
|
|
10
9
|
async createShare(port, duration) {
|
11
10
|
try {
|
12
|
-
const shareId = nanoid(8);
|
13
|
-
|
14
11
|
const tunnel = await localtunnel({ port });
|
12
|
+
const shareId = uuidv4().slice(0, 8);
|
15
13
|
|
16
|
-
const
|
14
|
+
const share = {
|
17
15
|
id: shareId,
|
18
16
|
url: tunnel.url,
|
17
|
+
tunnel,
|
19
18
|
startTime: Date.now(),
|
20
|
-
duration: duration * 60 * 1000
|
21
|
-
tunnel
|
19
|
+
duration: duration * 60 * 1000 // ΨͺΨΩΩΩ Ψ§ΩΨ―ΩΨ§Ψ¦Ω Ψ₯ΩΩ Ω
ΩΩΩ Ψ«Ψ§ΩΩΨ©
|
22
20
|
};
|
23
|
-
|
24
|
-
this.activeShares.set(shareId,
|
25
|
-
|
21
|
+
|
22
|
+
this.activeShares.set(shareId, share);
|
23
|
+
|
24
|
+
// Ψ₯ΨΊΩΨ§Ω Ψ§ΩΩ
Ψ΄Ψ§Ψ±ΩΨ© ΨͺΩΩΨ§Ψ¦ΩΨ§Ω Ψ¨ΨΉΨ― Ψ§ΩΨͺΩΨ§Ψ‘ Ψ§ΩΩ
Ψ―Ψ©
|
26
25
|
setTimeout(() => {
|
27
26
|
this.closeShare(shareId);
|
28
|
-
},
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
27
|
+
}, share.duration);
|
28
|
+
|
29
|
+
return {
|
30
|
+
id: shareId,
|
31
|
+
url: tunnel.url
|
32
|
+
};
|
34
33
|
} catch (error) {
|
35
|
-
|
36
|
-
throw error;
|
34
|
+
throw new Error(`ΩΨ΄Ω Ψ₯ΩΨ΄Ψ§Ψ‘ Ψ§ΩΩ
Ψ΄Ψ§Ψ±ΩΨ©: ${error.message}`);
|
37
35
|
}
|
38
36
|
}
|
39
37
|
|
40
38
|
async closeShare(shareId) {
|
41
39
|
const share = this.activeShares.get(shareId);
|
42
|
-
if (share) {
|
43
|
-
|
44
|
-
this.activeShares.delete(shareId);
|
45
|
-
Logger.info(`π Share ${shareId} closed`);
|
40
|
+
if (!share) {
|
41
|
+
throw new Error('ΩΩ
ΩΨͺΩ
Ψ§ΩΨΉΨ«ΩΨ± ΨΉΩΩ Ψ§ΩΩ
Ψ΄Ψ§Ψ±ΩΨ©');
|
46
42
|
}
|
43
|
+
|
44
|
+
await share.tunnel.close();
|
45
|
+
this.activeShares.delete(shareId);
|
47
46
|
}
|
48
47
|
|
49
48
|
getActiveShares() {
|
50
49
|
const shares = [];
|
51
50
|
for (const [id, share] of this.activeShares) {
|
52
|
-
const remainingTime =
|
53
|
-
|
54
|
-
);
|
51
|
+
const remainingTime = share.duration - (Date.now() - share.startTime);
|
52
|
+
const remainingMinutes = Math.max(0, Math.floor(remainingTime / (60 * 1000)));
|
55
53
|
|
56
54
|
shares.push({
|
57
|
-
id
|
55
|
+
id,
|
58
56
|
url: share.url,
|
59
|
-
remainingMinutes
|
57
|
+
remainingMinutes
|
60
58
|
});
|
61
59
|
}
|
62
60
|
return shares;
|
package/src/utils/monitor.js
CHANGED
@@ -1,4 +1,9 @@
|
|
1
|
-
|
1
|
+
import os from 'os';
|
2
|
+
import { fileURLToPath } from 'url';
|
3
|
+
import { dirname } from 'path';
|
4
|
+
|
5
|
+
const __filename = fileURLToPath(import.meta.url);
|
6
|
+
const __dirname = dirname(__filename);
|
2
7
|
|
3
8
|
class ServerMonitor {
|
4
9
|
constructor() {
|
@@ -35,4 +40,4 @@ class ServerMonitor {
|
|
35
40
|
}
|
36
41
|
}
|
37
42
|
|
38
|
-
|
43
|
+
export default new ServerMonitor();
|