@pixelbyte-software/pixcode 1.53.12 → 1.53.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/dist/assets/{index-kP_gZ-wL.js → index-CZReJ0_S.js} +173 -173
- package/dist/index.html +1 -1
- package/dist-server/server/index.js +13 -3
- package/dist-server/server/index.js.map +1 -1
- package/dist-server/server/routes/auth.js +41 -1
- package/dist-server/server/routes/auth.js.map +1 -1
- package/dist-server/server/routes/network.js +17 -1
- package/dist-server/server/routes/network.js.map +1 -1
- package/dist-server/server/services/external-access.js +45 -21
- package/dist-server/server/services/external-access.js.map +1 -1
- package/dist-server/server/services/qr-login.js +115 -0
- package/dist-server/server/services/qr-login.js.map +1 -0
- package/dist-server/server/services/telegram/bot.js +18 -1
- package/dist-server/server/services/telegram/bot.js.map +1 -1
- package/dist-server/server/services/telegram/control-center.js +21 -3
- package/dist-server/server/services/telegram/control-center.js.map +1 -1
- package/dist-server/server/services/telegram/translations.js +8 -2
- package/dist-server/server/services/telegram/translations.js.map +1 -1
- package/package.json +1 -1
- package/server/index.js +13 -3
- package/server/routes/auth.js +47 -1
- package/server/routes/network.js +18 -1
- package/server/services/external-access.js +49 -21
- package/server/services/qr-login.js +126 -0
- package/server/services/telegram/bot.js +15 -0
- package/server/services/telegram/control-center.js +22 -3
- package/server/services/telegram/translations.js +8 -2
package/server/routes/auth.js
CHANGED
|
@@ -6,7 +6,13 @@ import express from 'express';
|
|
|
6
6
|
import bcrypt from 'bcryptjs';
|
|
7
7
|
|
|
8
8
|
import { userDb, db } from '../database/db.js';
|
|
9
|
-
import { generateToken, authenticateToken } from '../middleware/auth.js';
|
|
9
|
+
import { generateToken, authenticateToken, requireAdmin } from '../middleware/auth.js';
|
|
10
|
+
import {
|
|
11
|
+
consumeQrLoginToken,
|
|
12
|
+
createQrLoginToken,
|
|
13
|
+
getQrLoginSettings,
|
|
14
|
+
saveQrLoginSettings,
|
|
15
|
+
} from '../services/qr-login.js';
|
|
10
16
|
import {
|
|
11
17
|
getPublicRemoteConnectionConfig,
|
|
12
18
|
saveRemoteConnectionConfig,
|
|
@@ -51,6 +57,46 @@ router.put('/connection-mode', (req, res) => {
|
|
|
51
57
|
}
|
|
52
58
|
});
|
|
53
59
|
|
|
60
|
+
router.get('/qr-login/settings', authenticateToken, requireAdmin, (_req, res) => {
|
|
61
|
+
res.json({ success: true, settings: getQrLoginSettings() });
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
router.put('/qr-login/settings', authenticateToken, requireAdmin, (req, res) => {
|
|
65
|
+
try {
|
|
66
|
+
res.json({ success: true, settings: saveQrLoginSettings(req.body || {}) });
|
|
67
|
+
} catch (error) {
|
|
68
|
+
res.status(400).json({ success: false, error: error.message });
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
router.post('/qr-login/token', authenticateToken, requireAdmin, (req, res) => {
|
|
73
|
+
try {
|
|
74
|
+
const baseUrl = typeof req.body?.baseUrl === 'string' && req.body.baseUrl.trim()
|
|
75
|
+
? req.body.baseUrl.trim()
|
|
76
|
+
: null;
|
|
77
|
+
res.json({ success: true, ...createQrLoginToken({ userId: req.user.id, baseUrl }) });
|
|
78
|
+
} catch (error) {
|
|
79
|
+
const status = error?.code === 'QR_LOGIN_DISABLED' ? 409 : 400;
|
|
80
|
+
res.status(status).json({ success: false, error: error.message });
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
router.post('/qr-login', (req, res) => {
|
|
85
|
+
try {
|
|
86
|
+
const user = consumeQrLoginToken(req.body?.token);
|
|
87
|
+
const token = generateToken(user);
|
|
88
|
+
userDb.updateLastLogin(user.id);
|
|
89
|
+
res.json({
|
|
90
|
+
success: true,
|
|
91
|
+
user: publicUser(user),
|
|
92
|
+
token,
|
|
93
|
+
});
|
|
94
|
+
} catch (error) {
|
|
95
|
+
const status = error?.code === 'QR_LOGIN_DISABLED' ? 409 : 401;
|
|
96
|
+
res.status(status).json({ success: false, error: error.message });
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
|
|
54
100
|
// User registration (setup) - only allowed if no users exist
|
|
55
101
|
router.post('/register', async (req, res) => {
|
|
56
102
|
try {
|
package/server/routes/network.js
CHANGED
|
@@ -19,6 +19,19 @@ const resolveServerPort = () => {
|
|
|
19
19
|
return Number.isFinite(port) && port > 0 ? port : 3001;
|
|
20
20
|
};
|
|
21
21
|
|
|
22
|
+
const PRIVATE_IPV4_REGEX = /^(10\.|192\.168\.|172\.(1[6-9]|2\d|3[0-1])\.)/u;
|
|
23
|
+
const VIRTUAL_INTERFACE_REGEX = /(docker|veth|bridge|br-|vmnet|vbox|virtualbox|tailscale|utun|wg|tun|tap|zerotier|zt)/iu;
|
|
24
|
+
|
|
25
|
+
const classifyEndpoint = (ifaceName, address) => {
|
|
26
|
+
const isPrivate = PRIVATE_IPV4_REGEX.test(address);
|
|
27
|
+
const isVirtual = VIRTUAL_INTERFACE_REGEX.test(ifaceName);
|
|
28
|
+
return {
|
|
29
|
+
scope: isPrivate ? 'private' : 'public',
|
|
30
|
+
kind: isVirtual ? 'virtual' : (isPrivate ? 'lan' : 'public'),
|
|
31
|
+
usableForSameNetwork: isPrivate && !isVirtual,
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
|
|
22
35
|
// Filter to usable LAN addresses. We skip:
|
|
23
36
|
// - internal (loopback) addresses, since QR-ing "127.0.0.1" is useless for a phone
|
|
24
37
|
// - link-local IPv6, since pasting "fe80::…%iface" into a phone browser won't resolve
|
|
@@ -32,10 +45,13 @@ const listLanEndpoints = () => {
|
|
|
32
45
|
for (const addr of addrs) {
|
|
33
46
|
if (addr.internal) continue;
|
|
34
47
|
if (addr.family !== 'IPv4' && addr.family !== 4) continue;
|
|
48
|
+
const classification = classifyEndpoint(ifaceName, addr.address);
|
|
49
|
+
if (!classification.usableForSameNetwork) continue;
|
|
35
50
|
endpoints.push({
|
|
36
51
|
host: addr.address,
|
|
37
52
|
label: ifaceName,
|
|
38
53
|
family: 'IPv4',
|
|
54
|
+
...classification,
|
|
39
55
|
});
|
|
40
56
|
}
|
|
41
57
|
}
|
|
@@ -97,7 +113,8 @@ router.delete('/upnp', (_req, res) => {
|
|
|
97
113
|
router.post('/tunnel', requireAdmin, async (req, res) => {
|
|
98
114
|
const port = resolveServerPort();
|
|
99
115
|
try {
|
|
100
|
-
const
|
|
116
|
+
const provider = req.body?.provider === 'ngrok' ? 'ngrok' : 'cloudflare';
|
|
117
|
+
const state = await startTunnel({ port, provider, persistPreference: true });
|
|
101
118
|
res.json({ success: true, tunnel: state });
|
|
102
119
|
} catch (error) {
|
|
103
120
|
console.error('Tunnel start failed:', error);
|
|
@@ -44,6 +44,7 @@ let restoreInFlight = null;
|
|
|
44
44
|
let tunnelState = {
|
|
45
45
|
running: false,
|
|
46
46
|
binary: null, // 'cloudflared' | 'ngrok'
|
|
47
|
+
provider: null, // 'cloudflare' | 'ngrok'
|
|
47
48
|
url: null,
|
|
48
49
|
error: null,
|
|
49
50
|
installHint: null,
|
|
@@ -55,7 +56,7 @@ let tunnelState = {
|
|
|
55
56
|
const DEFAULT_TUNNEL_PREFERENCE = Object.freeze({
|
|
56
57
|
desired: false,
|
|
57
58
|
port: null,
|
|
58
|
-
provider:
|
|
59
|
+
provider: 'cloudflare',
|
|
59
60
|
lastUrl: null,
|
|
60
61
|
lastStartedAt: null,
|
|
61
62
|
lastStoppedAt: null,
|
|
@@ -97,8 +98,14 @@ const appendLog = (line) => {
|
|
|
97
98
|
if (tunnelState.log.length > 200) tunnelState.log.shift();
|
|
98
99
|
};
|
|
99
100
|
|
|
100
|
-
const
|
|
101
|
-
|
|
101
|
+
const normalizeTunnelProvider = (provider) => (provider === 'ngrok' ? 'ngrok' : 'cloudflare');
|
|
102
|
+
|
|
103
|
+
const tunnelProviderBinary = (provider) => (normalizeTunnelProvider(provider) === 'ngrok' ? 'ngrok' : 'cloudflared');
|
|
104
|
+
|
|
105
|
+
const tunnelBinaryProvider = (binary) => (binary === 'ngrok' ? 'ngrok' : 'cloudflare');
|
|
106
|
+
|
|
107
|
+
const detectBinary = async (provider = null) => {
|
|
108
|
+
const candidates = provider ? [tunnelProviderBinary(provider)] : ['cloudflared', 'ngrok'];
|
|
102
109
|
for (const name of candidates) {
|
|
103
110
|
try {
|
|
104
111
|
// `which` isn't guaranteed on Windows; we probe with `--version` instead
|
|
@@ -116,17 +123,31 @@ const detectBinary = async () => {
|
|
|
116
123
|
return null;
|
|
117
124
|
};
|
|
118
125
|
|
|
119
|
-
const createTunnelInstallHint = () =>
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
126
|
+
const createTunnelInstallHint = (provider = 'cloudflare') => {
|
|
127
|
+
if (normalizeTunnelProvider(provider) === 'ngrok') {
|
|
128
|
+
return {
|
|
129
|
+
title: 'ngrok binary required',
|
|
130
|
+
message: 'Install and authenticate ngrok to create a public mobile URL. Local LAN QR codes still work on the same Wi-Fi/network.',
|
|
131
|
+
commands: [
|
|
132
|
+
'macOS: brew install ngrok/ngrok/ngrok',
|
|
133
|
+
'Windows: winget install ngrok.ngrok',
|
|
134
|
+
'Linux: install ngrok from https://ngrok.com/download',
|
|
135
|
+
],
|
|
136
|
+
docsUrl: 'https://ngrok.com/download',
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return {
|
|
141
|
+
title: 'Cloudflare Tunnel binary required',
|
|
142
|
+
message: 'Install cloudflared to create a public Cloudflare URL. Local LAN QR codes still work on the same Wi-Fi/network.',
|
|
143
|
+
commands: [
|
|
144
|
+
'macOS: brew install cloudflared',
|
|
145
|
+
'Windows: winget install Cloudflare.cloudflared',
|
|
146
|
+
'Linux: install cloudflared from https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/downloads/',
|
|
147
|
+
],
|
|
148
|
+
docsUrl: 'https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/downloads/',
|
|
149
|
+
};
|
|
150
|
+
};
|
|
130
151
|
|
|
131
152
|
const cloudflareUrlRegex = /https?:\/\/[a-z0-9.-]+trycloudflare\.com/i;
|
|
132
153
|
const ngrokUrlRegex = /https?:\/\/[a-z0-9.-]+\.ngrok(-free)?\.(app|io)/i;
|
|
@@ -143,13 +164,14 @@ const extractUrl = (binary, text) => {
|
|
|
143
164
|
return null;
|
|
144
165
|
};
|
|
145
166
|
|
|
146
|
-
export const startTunnel = async ({ port, persistPreference = false, restoring = false } = {}) => {
|
|
167
|
+
export const startTunnel = async ({ port, provider: requestedProvider = 'cloudflare', persistPreference = false, restoring = false } = {}) => {
|
|
168
|
+
const provider = normalizeTunnelProvider(requestedProvider);
|
|
147
169
|
if (tunnelProc) {
|
|
148
170
|
if (persistPreference) {
|
|
149
171
|
await persistTunnelPreference({
|
|
150
172
|
desired: true,
|
|
151
173
|
port,
|
|
152
|
-
provider: tunnelState.binary,
|
|
174
|
+
provider: tunnelState.provider || tunnelBinaryProvider(tunnelState.binary),
|
|
153
175
|
lastUrl: tunnelState.url,
|
|
154
176
|
});
|
|
155
177
|
tunnelState = { ...tunnelState, desired: true, restoring: false };
|
|
@@ -158,20 +180,21 @@ export const startTunnel = async ({ port, persistPreference = false, restoring =
|
|
|
158
180
|
}
|
|
159
181
|
suppressNextTunnelRestore = false;
|
|
160
182
|
|
|
161
|
-
const binary = await detectBinary();
|
|
183
|
+
const binary = await detectBinary(provider);
|
|
162
184
|
if (!binary) {
|
|
163
|
-
const installHint = createTunnelInstallHint();
|
|
185
|
+
const installHint = createTunnelInstallHint(provider);
|
|
164
186
|
tunnelState = {
|
|
165
187
|
running: false,
|
|
166
188
|
binary: null,
|
|
189
|
+
provider,
|
|
167
190
|
url: null,
|
|
168
|
-
error: '
|
|
191
|
+
error: provider === 'cloudflare' ? 'cloudflared was not found' : 'ngrok was not found',
|
|
169
192
|
installHint,
|
|
170
193
|
desired: Boolean(persistPreference || restoring),
|
|
171
194
|
restoring,
|
|
172
195
|
log: [],
|
|
173
196
|
};
|
|
174
|
-
const err = new Error(
|
|
197
|
+
const err = new Error(tunnelState.error);
|
|
175
198
|
err.code = 'ENOENT_TUNNEL';
|
|
176
199
|
err.installHint = installHint;
|
|
177
200
|
throw err;
|
|
@@ -183,6 +206,7 @@ export const startTunnel = async ({ port, persistPreference = false, restoring =
|
|
|
183
206
|
tunnelState = {
|
|
184
207
|
running: true,
|
|
185
208
|
binary,
|
|
209
|
+
provider,
|
|
186
210
|
url: null,
|
|
187
211
|
error: null,
|
|
188
212
|
installHint: null,
|
|
@@ -207,6 +231,7 @@ export const startTunnel = async ({ port, persistPreference = false, restoring =
|
|
|
207
231
|
tunnelState = {
|
|
208
232
|
running: false,
|
|
209
233
|
binary,
|
|
234
|
+
provider,
|
|
210
235
|
url: null,
|
|
211
236
|
error: code === 0 ? null : `Tunnel exited with code ${code}`,
|
|
212
237
|
installHint: null,
|
|
@@ -242,7 +267,7 @@ export const startTunnel = async ({ port, persistPreference = false, restoring =
|
|
|
242
267
|
await persistTunnelPreference({
|
|
243
268
|
desired: true,
|
|
244
269
|
port,
|
|
245
|
-
provider
|
|
270
|
+
provider,
|
|
246
271
|
lastUrl: tunnelState.url,
|
|
247
272
|
lastStartedAt: new Date().toISOString(),
|
|
248
273
|
});
|
|
@@ -284,6 +309,7 @@ export const stopTunnel = async ({ persistPreference = true } = {}) => {
|
|
|
284
309
|
tunnelState = {
|
|
285
310
|
running: false,
|
|
286
311
|
binary: null,
|
|
312
|
+
provider: null,
|
|
287
313
|
url: null,
|
|
288
314
|
error: null,
|
|
289
315
|
installHint: null,
|
|
@@ -302,6 +328,7 @@ export const stopTunnel = async ({ persistPreference = true } = {}) => {
|
|
|
302
328
|
tunnelState = {
|
|
303
329
|
running: false,
|
|
304
330
|
binary: null,
|
|
331
|
+
provider: null,
|
|
305
332
|
url: null,
|
|
306
333
|
error: null,
|
|
307
334
|
installHint: null,
|
|
@@ -341,6 +368,7 @@ export const restoreRequestedTunnel = async ({ port } = {}) => {
|
|
|
341
368
|
try {
|
|
342
369
|
return await startTunnel({
|
|
343
370
|
port: restorePort,
|
|
371
|
+
provider: preference.provider || 'cloudflare',
|
|
344
372
|
persistPreference: true,
|
|
345
373
|
restoring: true,
|
|
346
374
|
});
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import crypto from 'node:crypto';
|
|
2
|
+
|
|
3
|
+
import { appConfigDb, userDb } from '../database/db.js';
|
|
4
|
+
|
|
5
|
+
const CONFIG_KEY = 'qr_login_settings';
|
|
6
|
+
const DEFAULT_SETTINGS = Object.freeze({
|
|
7
|
+
enabled: false,
|
|
8
|
+
ttlSeconds: 300,
|
|
9
|
+
});
|
|
10
|
+
const MIN_TTL_SECONDS = 60;
|
|
11
|
+
const MAX_TTL_SECONDS = 15 * 60;
|
|
12
|
+
const qrLoginTokens = new Map();
|
|
13
|
+
|
|
14
|
+
function clampTtl(value) {
|
|
15
|
+
const parsed = Number.parseInt(String(value || ''), 10);
|
|
16
|
+
if (!Number.isFinite(parsed)) return DEFAULT_SETTINGS.ttlSeconds;
|
|
17
|
+
return Math.min(MAX_TTL_SECONDS, Math.max(MIN_TTL_SECONDS, parsed));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function normalizeSettings(value = {}) {
|
|
21
|
+
const raw = value && typeof value === 'object' ? value : {};
|
|
22
|
+
return {
|
|
23
|
+
enabled: raw.enabled === true,
|
|
24
|
+
ttlSeconds: clampTtl(raw.ttlSeconds),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function readStoredSettings() {
|
|
29
|
+
const raw = appConfigDb.get(CONFIG_KEY);
|
|
30
|
+
if (!raw) return { ...DEFAULT_SETTINGS };
|
|
31
|
+
try {
|
|
32
|
+
return normalizeSettings(JSON.parse(raw));
|
|
33
|
+
} catch {
|
|
34
|
+
return { ...DEFAULT_SETTINGS };
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function cleanupExpiredTokens() {
|
|
39
|
+
const now = Date.now();
|
|
40
|
+
for (const [token, entry] of qrLoginTokens.entries()) {
|
|
41
|
+
if (!entry || entry.expiresAtMs <= now) {
|
|
42
|
+
qrLoginTokens.delete(token);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function appendQrLoginToken(baseUrl, token) {
|
|
48
|
+
const url = new URL(baseUrl);
|
|
49
|
+
url.searchParams.set('qrLoginToken', token);
|
|
50
|
+
return url.toString();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function getQrLoginSettings() {
|
|
54
|
+
return readStoredSettings();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function saveQrLoginSettings(input = {}) {
|
|
58
|
+
const settings = normalizeSettings(input);
|
|
59
|
+
appConfigDb.set(CONFIG_KEY, JSON.stringify(settings));
|
|
60
|
+
if (!settings.enabled) {
|
|
61
|
+
qrLoginTokens.clear();
|
|
62
|
+
}
|
|
63
|
+
return settings;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function createQrLoginToken({ userId, baseUrl }) {
|
|
67
|
+
const settings = readStoredSettings();
|
|
68
|
+
if (!settings.enabled) {
|
|
69
|
+
const error = new Error('QR login is disabled.');
|
|
70
|
+
error.code = 'QR_LOGIN_DISABLED';
|
|
71
|
+
throw error;
|
|
72
|
+
}
|
|
73
|
+
const user = userDb.getUserById(userId);
|
|
74
|
+
if (!user) {
|
|
75
|
+
const error = new Error('QR login user was not found.');
|
|
76
|
+
error.code = 'QR_LOGIN_USER_NOT_FOUND';
|
|
77
|
+
throw error;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
cleanupExpiredTokens();
|
|
81
|
+
const token = crypto.randomBytes(32).toString('base64url');
|
|
82
|
+
const expiresAtMs = Date.now() + settings.ttlSeconds * 1000;
|
|
83
|
+
qrLoginTokens.set(token, {
|
|
84
|
+
userId: user.id,
|
|
85
|
+
createdAtMs: Date.now(),
|
|
86
|
+
expiresAtMs,
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
return {
|
|
90
|
+
token,
|
|
91
|
+
expiresAt: new Date(expiresAtMs).toISOString(),
|
|
92
|
+
ttlSeconds: settings.ttlSeconds,
|
|
93
|
+
qrUrl: baseUrl ? appendQrLoginToken(baseUrl, token) : null,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function consumeQrLoginToken(token) {
|
|
98
|
+
const settings = readStoredSettings();
|
|
99
|
+
if (!settings.enabled) {
|
|
100
|
+
const error = new Error('QR login is disabled.');
|
|
101
|
+
error.code = 'QR_LOGIN_DISABLED';
|
|
102
|
+
throw error;
|
|
103
|
+
}
|
|
104
|
+
if (!token || typeof token !== 'string') {
|
|
105
|
+
const error = new Error('QR login token is required.');
|
|
106
|
+
error.code = 'QR_LOGIN_TOKEN_REQUIRED';
|
|
107
|
+
throw error;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
cleanupExpiredTokens();
|
|
111
|
+
const entry = qrLoginTokens.get(token);
|
|
112
|
+
qrLoginTokens.delete(token);
|
|
113
|
+
if (!entry) {
|
|
114
|
+
const error = new Error('QR login token is invalid or expired.');
|
|
115
|
+
error.code = 'QR_LOGIN_INVALID';
|
|
116
|
+
throw error;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const user = userDb.getUserById(entry.userId);
|
|
120
|
+
if (!user) {
|
|
121
|
+
const error = new Error('QR login user was not found.');
|
|
122
|
+
error.code = 'QR_LOGIN_USER_NOT_FOUND';
|
|
123
|
+
throw error;
|
|
124
|
+
}
|
|
125
|
+
return user;
|
|
126
|
+
}
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
handleTelegramControlCallback,
|
|
8
8
|
handleTelegramControlMessage,
|
|
9
9
|
isTelegramControlCommand,
|
|
10
|
+
sendActiveTerminalAttachedNotice,
|
|
10
11
|
showMainMenu,
|
|
11
12
|
} from './control-center.js';
|
|
12
13
|
import { t } from './translations.js';
|
|
@@ -359,6 +360,20 @@ export const notifyUser = async ({ userId, kind, title, error }) => {
|
|
|
359
360
|
return sendToUser(userId, text);
|
|
360
361
|
};
|
|
361
362
|
|
|
363
|
+
export const notifyTelegramTerminalAttached = async ({ userId, terminal }) => {
|
|
364
|
+
const link = telegramLinksDb.getByUserId(userId);
|
|
365
|
+
if (!bot) return { ok: false, reason: 'bot_not_running' };
|
|
366
|
+
if (!link?.chat_id || !link?.verified_at) return { ok: false, reason: 'telegram_not_paired' };
|
|
367
|
+
if (!terminal) return { ok: false, reason: 'missing_terminal' };
|
|
368
|
+
try {
|
|
369
|
+
await sendActiveTerminalAttachedNotice({ bot, chatId: link.chat_id, link, terminal });
|
|
370
|
+
return { ok: true };
|
|
371
|
+
} catch (err) {
|
|
372
|
+
console.warn('[telegram] terminal attach notice failed:', err?.message || err);
|
|
373
|
+
return { ok: false, reason: err?.message || String(err) };
|
|
374
|
+
}
|
|
375
|
+
};
|
|
376
|
+
|
|
362
377
|
// Boot the bot automatically if a token was previously persisted. This runs
|
|
363
378
|
// once during server startup so a restart doesn't silently un-pair everyone.
|
|
364
379
|
export const restoreBotFromConfig = async () => {
|
|
@@ -598,7 +598,7 @@ function terminalOutputUrl(terminal, maxChars = 3200) {
|
|
|
598
598
|
return `/api/shell/sessions/provider-output?${params.toString()}`;
|
|
599
599
|
}
|
|
600
600
|
|
|
601
|
-
function renderTerminalSnapshot(lang, terminal, data, { prefix = '' } = {}) {
|
|
601
|
+
function renderTerminalSnapshot(lang, terminal, data, { prefix = '', includeOutput = false } = {}) {
|
|
602
602
|
const active = data?.active !== false;
|
|
603
603
|
const lifecycle = data?.terminalState || data?.lifecycleState || (active ? 'running' : 'not running');
|
|
604
604
|
const output = String(data?.output || '').trim();
|
|
@@ -612,15 +612,34 @@ function renderTerminalSnapshot(lang, terminal, data, { prefix = '' } = {}) {
|
|
|
612
612
|
if (terminal.sessionId || data?.sessionId) {
|
|
613
613
|
lines.push(`🧵 ${t(lang, 'control.activity.session')}: ${terminal.sessionId || data.sessionId}`);
|
|
614
614
|
}
|
|
615
|
-
if (output) {
|
|
615
|
+
if (includeOutput && output) {
|
|
616
616
|
lines.push('', `💬 ${t(lang, 'control.activity.output')}:`);
|
|
617
617
|
lines.push(truncate(output, 2400));
|
|
618
618
|
} else {
|
|
619
|
-
lines.push('', t(lang, 'control.
|
|
619
|
+
lines.push('', t(lang, 'control.terminalOutputHidden'));
|
|
620
620
|
}
|
|
621
621
|
return truncate(lines.join('\n'), 3400);
|
|
622
622
|
}
|
|
623
623
|
|
|
624
|
+
export async function sendActiveTerminalAttachedNotice({ bot, chatId, link, terminal }) {
|
|
625
|
+
const lang = languageFor(link);
|
|
626
|
+
const lines = [
|
|
627
|
+
t(lang, 'control.terminalAttached'),
|
|
628
|
+
'',
|
|
629
|
+
`🤖 ${t(lang, 'control.activity.provider')}: ${terminal.provider}`,
|
|
630
|
+
`📁 ${t(lang, 'control.activity.project')}: ${compact(terminalProjectLabel(terminal), 90)}`,
|
|
631
|
+
`📌 ${t(lang, 'control.activity.status')}: ${t(lang, 'control.terminalReadyStatus')}`,
|
|
632
|
+
];
|
|
633
|
+
if (terminal.sessionId) {
|
|
634
|
+
lines.push(`🧵 ${t(lang, 'control.activity.session')}: ${terminal.sessionId}`);
|
|
635
|
+
}
|
|
636
|
+
lines.push('', t(lang, 'control.terminalReadyPrompt'));
|
|
637
|
+
await send(bot, chatId, truncate(lines.join('\n'), 3400), {
|
|
638
|
+
parse_mode: undefined,
|
|
639
|
+
reply_markup: { inline_keyboard: terminalControlKeyboard(lang) },
|
|
640
|
+
});
|
|
641
|
+
}
|
|
642
|
+
|
|
624
643
|
async function showActiveTerminalStatus({ bot, chatId, link, editMessageId }) {
|
|
625
644
|
const lang = languageFor(link);
|
|
626
645
|
const state = getState(link.user_id);
|
|
@@ -79,10 +79,13 @@ const EN = {
|
|
|
79
79
|
'control.recentSessions': 'Recent sessions:',
|
|
80
80
|
'control.noActiveTerminal': 'No web CLI session is attached to this Telegram chat. Open a CLI tab in Pixcode and press the Telegram button.',
|
|
81
81
|
'control.terminalAttached': '📲 Telegram is attached to this web CLI session. New plain messages will be sent to the terminal.',
|
|
82
|
+
'control.terminalReadyStatus': 'attached',
|
|
83
|
+
'control.terminalReadyPrompt': 'Write your next message here to continue this web CLI session. Use /detach to return Telegram to the normal AI router.',
|
|
82
84
|
'control.terminalNotRunning': 'The attached CLI terminal is not running anymore.',
|
|
83
85
|
'control.terminalNoOutput': 'No terminal output yet.',
|
|
86
|
+
'control.terminalOutputHidden': 'Live CLI screen output is not dumped into Telegram because full-screen terminal UIs are noisy. Keep sending messages here, or open Pixcode for the live terminal.',
|
|
84
87
|
'control.terminalSending': '📲 Sending to {{provider}} terminal on {{project}}...',
|
|
85
|
-
'control.terminalSent': '📲 Sent to the active terminal.
|
|
88
|
+
'control.terminalSent': '📲 Sent to the active terminal.',
|
|
86
89
|
'control.terminalSendFailed': 'Could not send to the active terminal: {{error}}',
|
|
87
90
|
'control.terminalStatusFailed': 'Could not read the active terminal: {{error}}',
|
|
88
91
|
'control.terminalDetached': 'Telegram is detached from the web CLI session. Plain messages will use the normal AI router again.',
|
|
@@ -236,10 +239,13 @@ const TR = {
|
|
|
236
239
|
'control.recentSessions': 'Son oturumlar:',
|
|
237
240
|
'control.noActiveTerminal': 'Bu Telegram sohbetine bağlı web CLI oturumu yok. Pixcode içinde CLI tabı açıp Telegram butonuna bas.',
|
|
238
241
|
'control.terminalAttached': '📲 Telegram bu web CLI oturumuna bağlı. Düz mesajlar terminale gönderilecek.',
|
|
242
|
+
'control.terminalReadyStatus': 'bağlandı',
|
|
243
|
+
'control.terminalReadyPrompt': 'Bu web CLI oturumuna devam etmek için sonraki mesajını buraya yaz. Telegramı normal AI router akışına döndürmek için /detach kullan.',
|
|
239
244
|
'control.terminalNotRunning': 'Bağlı CLI terminali artık çalışmıyor.',
|
|
240
245
|
'control.terminalNoOutput': 'Henüz terminal çıktısı yok.',
|
|
246
|
+
'control.terminalOutputHidden': 'Canlı CLI ekran çıktısı Telegrama dökülmez; tam ekran terminal arayüzleri burada gürültülü görünür. Buradan mesaj göndermeye devam et veya canlı terminal için Pixcodeu aç.',
|
|
241
247
|
'control.terminalSending': '📲 {{project}} üzerinde {{provider}} terminaline gönderiliyor...',
|
|
242
|
-
'control.terminalSent': '📲 Aktif terminale gönderildi.
|
|
248
|
+
'control.terminalSent': '📲 Aktif terminale gönderildi.',
|
|
243
249
|
'control.terminalSendFailed': 'Aktif terminale gönderilemedi: {{error}}',
|
|
244
250
|
'control.terminalStatusFailed': 'Aktif terminal okunamadı: {{error}}',
|
|
245
251
|
'control.terminalDetached': 'Telegram web CLI oturumundan ayrıldı. Düz mesajlar tekrar normal AI router akışına gidecek.',
|