topnic-https 0.2.11 → 0.2.13
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 +5 -5
- package/package.json +2 -1
- package/src/sharing/shareManager.js +28 -7
package/bin/cli.js
CHANGED
@@ -51,14 +51,14 @@ program
|
|
51
51
|
.action(async (options) => {
|
52
52
|
try {
|
53
53
|
const share = await shareManager.createShare(options.port, options.duration);
|
54
|
-
console.log('\
|
54
|
+
console.log('\n🌍 مشاركة المشروع');
|
55
55
|
console.log('--------------------------------');
|
56
|
-
console.log(
|
57
|
-
console.log(
|
58
|
-
console.log(
|
56
|
+
console.log(`📎 رابط المشاركة المباشر:`);
|
57
|
+
console.log(`${share.url}`);
|
58
|
+
console.log(`⏱️ مدة المشاركة: ${options.duration} دقيقة`);
|
59
59
|
console.log('--------------------------------\n');
|
60
60
|
} catch (error) {
|
61
|
-
console.error('
|
61
|
+
console.error('❌ فشل إنشاء المشاركة:', error.message);
|
62
62
|
}
|
63
63
|
});
|
64
64
|
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "topnic-https",
|
3
|
-
"version": "0.2.
|
3
|
+
"version": "0.2.13",
|
4
4
|
"main": "./src/main/index.js",
|
5
5
|
"type": "commonjs",
|
6
6
|
"scripts": {
|
@@ -96,6 +96,7 @@
|
|
96
96
|
"https": "^1.0.0",
|
97
97
|
"localtunnel": "^2.0.2",
|
98
98
|
"nanoid": "^5.0.8",
|
99
|
+
"ngrok": "^5.0.0-beta.2",
|
99
100
|
"os": "^0.1.2",
|
100
101
|
"path": "^0.12.7",
|
101
102
|
"uuid": "^11.0.3",
|
@@ -1,27 +1,48 @@
|
|
1
|
-
const
|
2
|
-
const {
|
1
|
+
const ngrok = require('ngrok');
|
2
|
+
const { nanoid } = require('nanoid/non-secure');
|
3
3
|
|
4
4
|
class ShareManager {
|
5
5
|
constructor() {
|
6
6
|
this.activeShares = new Map();
|
7
7
|
}
|
8
8
|
|
9
|
+
async createTunnel(port) {
|
10
|
+
try {
|
11
|
+
const url = await ngrok.connect({
|
12
|
+
addr: port,
|
13
|
+
onStatusChange: status => {
|
14
|
+
if (status === 'closed') {
|
15
|
+
console.log('🔄 تم إغلاق النفق');
|
16
|
+
}
|
17
|
+
},
|
18
|
+
onLogEvent: data => {
|
19
|
+
if (data.err) {
|
20
|
+
console.error('❌ خطأ في النفق:', data.err);
|
21
|
+
}
|
22
|
+
}
|
23
|
+
});
|
24
|
+
|
25
|
+
return { url, disconnect: ngrok.disconnect };
|
26
|
+
} catch (error) {
|
27
|
+
throw new Error(`فشل إنشاء النفق: ${error.message}`);
|
28
|
+
}
|
29
|
+
}
|
30
|
+
|
9
31
|
async createShare(port, duration) {
|
10
32
|
try {
|
11
|
-
const tunnel = await
|
12
|
-
const shareId =
|
33
|
+
const tunnel = await this.createTunnel(port);
|
34
|
+
const shareId = nanoid(6);
|
13
35
|
|
14
36
|
const share = {
|
15
37
|
id: shareId,
|
16
38
|
url: tunnel.url,
|
17
39
|
tunnel,
|
18
40
|
startTime: Date.now(),
|
19
|
-
duration: duration * 60 * 1000
|
41
|
+
duration: duration * 60 * 1000
|
20
42
|
};
|
21
43
|
|
22
44
|
this.activeShares.set(shareId, share);
|
23
45
|
|
24
|
-
// إغلاق المشاركة تلقائياً بعد انتهاء المدة
|
25
46
|
setTimeout(() => {
|
26
47
|
this.closeShare(shareId);
|
27
48
|
}, share.duration);
|
@@ -41,7 +62,7 @@ class ShareManager {
|
|
41
62
|
throw new Error('لم يتم العثور على المشاركة');
|
42
63
|
}
|
43
64
|
|
44
|
-
await share.tunnel.
|
65
|
+
await share.tunnel.disconnect();
|
45
66
|
this.activeShares.delete(shareId);
|
46
67
|
}
|
47
68
|
|