@lethevimlet/sshift 1.9.0 → 1.9.1
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/package.json
CHANGED
|
@@ -3,11 +3,92 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
const fs = require('fs');
|
|
6
|
+
const https = require('https');
|
|
6
7
|
const path = require('path');
|
|
7
8
|
const { getDataDir, getCertPath, getKeyPath, getConfigPath } = require('../../utils/config');
|
|
8
9
|
|
|
9
10
|
const { SSL_CERT_FILE, SSL_KEY_FILE, SSL_CA_CERT_FILE } = require('../../utils/certs');
|
|
10
11
|
const UPDATE_MARKER_FILE = '.updating';
|
|
12
|
+
const VERSION_PATTERN = /^\d+\.\d+\.\d+$/;
|
|
13
|
+
|
|
14
|
+
function fetchJson(options, request = https.request) {
|
|
15
|
+
return new Promise((resolve, reject) => {
|
|
16
|
+
const req = request(options, (response) => {
|
|
17
|
+
let body = '';
|
|
18
|
+
|
|
19
|
+
response.on('data', (chunk) => {
|
|
20
|
+
body += chunk;
|
|
21
|
+
if (body.length > 1024 * 1024) {
|
|
22
|
+
req.destroy(new Error('Update metadata response is too large'));
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
response.on('end', () => {
|
|
26
|
+
if (response.statusCode !== 200) {
|
|
27
|
+
reject(new Error(`${options.hostname} returned ${response.statusCode}`));
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
try {
|
|
32
|
+
resolve(JSON.parse(body));
|
|
33
|
+
} catch (error) {
|
|
34
|
+
reject(new Error(`Invalid JSON from ${options.hostname}: ${error.message}`));
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
req.on('error', reject);
|
|
40
|
+
req.setTimeout(10000, () => req.destroy(new Error(`${options.hostname} request timed out`)));
|
|
41
|
+
req.end();
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async function getLatestPublishedVersion(request = https.request) {
|
|
46
|
+
try {
|
|
47
|
+
const npmPackage = await fetchJson({
|
|
48
|
+
hostname: 'registry.npmjs.org',
|
|
49
|
+
path: '/%40lethevimlet%2Fsshift/latest',
|
|
50
|
+
method: 'GET',
|
|
51
|
+
headers: {
|
|
52
|
+
'User-Agent': 'sshift-update-checker',
|
|
53
|
+
'Accept': 'application/json'
|
|
54
|
+
}
|
|
55
|
+
}, request);
|
|
56
|
+
|
|
57
|
+
if (!VERSION_PATTERN.test(npmPackage.version)) {
|
|
58
|
+
throw new Error('npm returned an invalid version');
|
|
59
|
+
}
|
|
60
|
+
return npmPackage.version;
|
|
61
|
+
} catch (npmError) {
|
|
62
|
+
console.warn('[UPDATE] npm version check failed, trying GitHub:', npmError.message);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const githubResponse = await fetchJson({
|
|
66
|
+
hostname: 'api.github.com',
|
|
67
|
+
path: '/repos/lethevimlet/sshift/contents/package.json',
|
|
68
|
+
method: 'GET',
|
|
69
|
+
headers: {
|
|
70
|
+
'User-Agent': 'sshift-update-checker',
|
|
71
|
+
'Accept': 'application/vnd.github.v3+json'
|
|
72
|
+
}
|
|
73
|
+
}, request);
|
|
74
|
+
const content = Buffer.from(githubResponse.content, 'base64').toString('utf8');
|
|
75
|
+
const githubVersion = JSON.parse(content).version;
|
|
76
|
+
if (!VERSION_PATTERN.test(githubVersion)) {
|
|
77
|
+
throw new Error('GitHub returned an invalid version');
|
|
78
|
+
}
|
|
79
|
+
return githubVersion;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function compareVersions(v1, v2) {
|
|
83
|
+
const parts1 = v1.split('.').map(Number);
|
|
84
|
+
const parts2 = v2.split('.').map(Number);
|
|
85
|
+
|
|
86
|
+
for (let i = 0; i < 3; i++) {
|
|
87
|
+
if (parts1[i] < parts2[i]) return -1;
|
|
88
|
+
if (parts1[i] > parts2[i]) return 1;
|
|
89
|
+
}
|
|
90
|
+
return 0;
|
|
91
|
+
}
|
|
11
92
|
|
|
12
93
|
/**
|
|
13
94
|
* Register system endpoints
|
|
@@ -61,78 +142,18 @@ function registerSystemEndpoints(app, io) {
|
|
|
61
142
|
// API: Check for updates
|
|
62
143
|
app.get('/api/check-update', async (req, res) => {
|
|
63
144
|
try {
|
|
64
|
-
const https = require('https');
|
|
65
|
-
|
|
66
145
|
// Get local version
|
|
67
146
|
const packagePath = path.join(__dirname, '../../../../package.json');
|
|
68
147
|
const packageData = JSON.parse(fs.readFileSync(packagePath, 'utf8'));
|
|
69
148
|
const localVersion = packageData.version;
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
'User-Agent': 'sshift-update-checker',
|
|
78
|
-
'Accept': 'application/vnd.github.v3+json'
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
const githubRequest = https.request(options, (githubResponse) => {
|
|
83
|
-
let data = '';
|
|
84
|
-
|
|
85
|
-
githubResponse.on('data', (chunk) => {
|
|
86
|
-
data += chunk;
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
githubResponse.on('end', () => {
|
|
90
|
-
try {
|
|
91
|
-
if (githubResponse.statusCode !== 200) {
|
|
92
|
-
console.error('GitHub API error:', githubResponse.statusCode, data);
|
|
93
|
-
res.status(500).json({ error: 'Failed to check for updates' });
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const response = JSON.parse(data);
|
|
98
|
-
const content = Buffer.from(response.content, 'base64').toString('utf8');
|
|
99
|
-
const remotePackage = JSON.parse(content);
|
|
100
|
-
const remoteVersion = remotePackage.version;
|
|
101
|
-
|
|
102
|
-
// Compare versions
|
|
103
|
-
const compareVersions = (v1, v2) => {
|
|
104
|
-
const parts1 = v1.split('.').map(Number);
|
|
105
|
-
const parts2 = v2.split('.').map(Number);
|
|
106
|
-
|
|
107
|
-
for (let i = 0; i < 3; i++) {
|
|
108
|
-
if (parts1[i] < parts2[i]) return -1;
|
|
109
|
-
if (parts1[i] > parts2[i]) return 1;
|
|
110
|
-
}
|
|
111
|
-
return 0;
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
const comparison = compareVersions(localVersion, remoteVersion);
|
|
115
|
-
const updateAvailable = comparison < 0;
|
|
116
|
-
|
|
117
|
-
res.json({
|
|
118
|
-
localVersion,
|
|
119
|
-
remoteVersion,
|
|
120
|
-
updateAvailable,
|
|
121
|
-
checkedAt: new Date().toISOString()
|
|
122
|
-
});
|
|
123
|
-
} catch (err) {
|
|
124
|
-
console.error('Error parsing GitHub response:', err);
|
|
125
|
-
res.status(500).json({ error: 'Failed to parse update information' });
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
githubRequest.on('error', (err) => {
|
|
131
|
-
console.error('Error checking for updates:', err);
|
|
132
|
-
res.status(500).json({ error: 'Failed to check for updates' });
|
|
149
|
+
const remoteVersion = await getLatestPublishedVersion();
|
|
150
|
+
|
|
151
|
+
res.json({
|
|
152
|
+
localVersion,
|
|
153
|
+
remoteVersion,
|
|
154
|
+
updateAvailable: compareVersions(localVersion, remoteVersion) < 0,
|
|
155
|
+
checkedAt: new Date().toISOString()
|
|
133
156
|
});
|
|
134
|
-
|
|
135
|
-
githubRequest.end();
|
|
136
157
|
} catch (err) {
|
|
137
158
|
console.error('Error in check-update:', err);
|
|
138
159
|
res.status(500).json({ error: 'Failed to check for updates' });
|
|
@@ -258,7 +279,6 @@ function registerSystemEndpoints(app, io) {
|
|
|
258
279
|
let targetVersion = 'latest';
|
|
259
280
|
const currentPkg = require('../../../../package.json');
|
|
260
281
|
try {
|
|
261
|
-
const https = require('https');
|
|
262
282
|
const githubVersion = await new Promise((resolve, reject) => {
|
|
263
283
|
const opts = {
|
|
264
284
|
hostname: 'api.github.com',
|
|
@@ -691,4 +711,4 @@ fi
|
|
|
691
711
|
});
|
|
692
712
|
}
|
|
693
713
|
|
|
694
|
-
module.exports = { registerSystemEndpoints };
|
|
714
|
+
module.exports = { compareVersions, getLatestPublishedVersion, registerSystemEndpoints };
|
package/src/webapp/js/app.js
CHANGED
|
@@ -13914,6 +13914,9 @@ async syncTabsFromServer(tabs, isInitialSync = false, activeTabsByPanel = null,
|
|
|
13914
13914
|
this.showToast('You are running the latest version', 'success');
|
|
13915
13915
|
}
|
|
13916
13916
|
}
|
|
13917
|
+
} else {
|
|
13918
|
+
const error = await response.json().catch(() => ({}));
|
|
13919
|
+
throw new Error(error.error || `Update check failed with status ${response.status}`);
|
|
13917
13920
|
}
|
|
13918
13921
|
} catch (error) {
|
|
13919
13922
|
console.error('Failed to check for updates:', error);
|