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 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 your local server temporarily')
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('\nπŸ“’ Share Information:');
48
- console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
49
- console.log(`πŸ”— Public URL: ${share.url}`);
50
- console.log(`πŸ†” Share ID: ${share.id}`);
51
- console.log(`⏱️ Duration: ${options.duration} minutes`);
52
- 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');
53
60
  } catch (error) {
54
- console.error('❌ Failed to create share:', error.message);
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('πŸ“­ No active shares');
71
+ console.log('No active shares');
65
72
  return;
66
73
  }
67
74
 
68
- console.log('\nπŸ“‹ Active Shares:');
69
- console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
75
+ console.log('\nActive Shares:');
76
+ console.log('--------------------------------');
70
77
  shares.forEach(share => {
71
- console.log(`πŸ”— URL: ${share.url}`);
72
- console.log(`πŸ†” ID: ${share.id}`);
73
- console.log(`⏱️ Remaining: ${share.remainingMinutes} minutes`);
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 sharing a specific server')
88
+ .description('Stop a specific share')
82
89
  .action(async (shareId) => {
83
90
  try {
84
91
  await shareManager.closeShare(shareId);
85
- console.log(`βœ… Share ${shareId} has been stopped`);
92
+ console.log(`Share ${shareId} stopped successfully`);
86
93
  } catch (error) {
87
- console.error('❌ Failed to stop share:', error.message);
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.8",
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
  };
@@ -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();