topnic-https 0.1.9 β 0.2.11
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 +19 -19
- package/package.json +5 -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,7 @@
|
|
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
6
|
|
7
7
|
program
|
8
8
|
.command('help')
|
@@ -45,20 +45,20 @@ program
|
|
45
45
|
|
46
46
|
program
|
47
47
|
.command('share')
|
48
|
-
.description('Share
|
48
|
+
.description('Share local server temporarily')
|
49
49
|
.option('-p, --port <number>', 'Port to share', 3000)
|
50
50
|
.option('-d, --duration <minutes>', 'Share duration in minutes', 60)
|
51
51
|
.action(async (options) => {
|
52
52
|
try {
|
53
53
|
const share = await shareManager.createShare(options.port, options.duration);
|
54
|
-
console.log('\
|
55
|
-
console.log('
|
56
|
-
console.log(
|
57
|
-
console.log(
|
58
|
-
console.log(
|
59
|
-
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');
|
60
60
|
} catch (error) {
|
61
|
-
console.error('
|
61
|
+
console.error('Failed to create share:', error.message);
|
62
62
|
}
|
63
63
|
});
|
64
64
|
|
@@ -68,30 +68,30 @@ program
|
|
68
68
|
.action(() => {
|
69
69
|
const shares = shareManager.getActiveShares();
|
70
70
|
if (shares.length === 0) {
|
71
|
-
console.log('
|
71
|
+
console.log('No active shares');
|
72
72
|
return;
|
73
73
|
}
|
74
74
|
|
75
|
-
console.log('\
|
76
|
-
console.log('
|
75
|
+
console.log('\nActive Shares:');
|
76
|
+
console.log('--------------------------------');
|
77
77
|
shares.forEach(share => {
|
78
|
-
console.log(
|
79
|
-
console.log(
|
80
|
-
console.log(
|
81
|
-
console.log('
|
78
|
+
console.log(`URL: ${share.url}`);
|
79
|
+
console.log(`ID: ${share.id}`);
|
80
|
+
console.log(`Remaining: ${share.remainingMinutes} minutes`);
|
81
|
+
console.log('--------------------------------');
|
82
82
|
});
|
83
83
|
console.log('');
|
84
84
|
});
|
85
85
|
|
86
86
|
program
|
87
87
|
.command('unshare <shareId>')
|
88
|
-
.description('Stop
|
88
|
+
.description('Stop a specific share')
|
89
89
|
.action(async (shareId) => {
|
90
90
|
try {
|
91
91
|
await shareManager.closeShare(shareId);
|
92
|
-
console.log(
|
92
|
+
console.log(`Share ${shareId} stopped successfully`);
|
93
93
|
} catch (error) {
|
94
|
-
console.error('
|
94
|
+
console.error('Failed to stop share:', error.message);
|
95
95
|
}
|
96
96
|
});
|
97
97
|
|
package/package.json
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
{
|
2
2
|
"name": "topnic-https",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.2.11",
|
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/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();
|