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 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 your local server temporarily')
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('\nπŸ“’ Share 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');
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('❌ Failed to create share:', error.message);
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('πŸ“­ No active shares');
71
+ console.log('No active shares');
72
72
  return;
73
73
  }
74
74
 
75
- console.log('\nπŸ“‹ Active Shares:');
76
- console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
75
+ console.log('\nActive Shares:');
76
+ console.log('--------------------------------');
77
77
  shares.forEach(share => {
78
- console.log(`πŸ”— URL: ${share.url}`);
79
- console.log(`πŸ†” ID: ${share.id}`);
80
- console.log(`⏱️ Remaining: ${share.remainingMinutes} minutes`);
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 sharing a specific server')
88
+ .description('Stop a specific share')
89
89
  .action(async (shareId) => {
90
90
  try {
91
91
  await shareManager.closeShare(shareId);
92
- console.log(`βœ… Share ${shareId} has been stopped`);
92
+ console.log(`Share ${shareId} stopped successfully`);
93
93
  } catch (error) {
94
- console.error('❌ Failed to stop share:', error.message);
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.1.9",
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
  }
@@ -1,4 +1,4 @@
1
- const WebSocket = require('ws');
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
- module.exports = { setupWebSocket, notifyClients };
25
+ export { setupWebSocket, notifyClients };
@@ -1,6 +1,5 @@
1
1
  const localtunnel = require('localtunnel');
2
- const { nanoid } = require('nanoid');
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 shareInfo = {
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, shareInfo);
25
-
21
+
22
+ this.activeShares.set(shareId, share);
23
+
24
+ // Ψ₯ΨΊΩ„Ψ§Ω‚ Ψ§Ω„Ω…Ψ΄Ψ§Ψ±ΩƒΨ© ΨͺΩ„Ω‚Ψ§Ψ¦ΩŠΨ§Ω‹ Ψ¨ΨΉΨ― Ψ§Ω†ΨͺΩ‡Ψ§Ψ‘ Ψ§Ω„Ω…Ψ―Ψ©
26
25
  setTimeout(() => {
27
26
  this.closeShare(shareId);
28
- }, shareInfo.duration);
29
-
30
- Logger.success(`🌍 Share created: ${tunnel.url}`);
31
- Logger.info(`⏱️ Share will expire in ${duration} minutes`);
32
-
33
- return shareInfo;
27
+ }, share.duration);
28
+
29
+ return {
30
+ id: shareId,
31
+ url: tunnel.url
32
+ };
34
33
  } catch (error) {
35
- Logger.error(`Share creation failed: ${error.message}`);
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
- await share.tunnel.close();
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 = Math.max(0,
53
- (share.startTime + share.duration - Date.now()) / 1000 / 60
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: share.id,
55
+ id,
58
56
  url: share.url,
59
- remainingMinutes: Math.round(remainingTime)
57
+ remainingMinutes
60
58
  });
61
59
  }
62
60
  return shares;
@@ -1,4 +1,9 @@
1
- const os = require('os');
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
- module.exports = new ServerMonitor();
43
+ export default new ServerMonitor();