reading update.json

This commit is contained in:
antelle 2021-01-07 23:00:16 +01:00
parent 9ec23fac5d
commit bee96ebf15
No known key found for this signature in database
GPG Key ID: 63C9777AAB7C563C
2 changed files with 14 additions and 11 deletions

View File

@ -97,13 +97,12 @@ const Updater = {
} }
logger.info('Checking for update...'); logger.info('Checking for update...');
Transport.httpGet({ Transport.httpGet({
url: Links.Manifest, url: Links.UpdateJson,
utf8: true, json: true,
success: (data) => { success: (updateJson) => {
const dt = new Date(); const dt = new Date();
const match = data.match(/#\s*(\d+\-\d+\-\d+):v([\d+\.\w]+)/); logger.info('Update check: ' + (updateJson.version || 'unknown'));
logger.info('Update check: ' + (match ? match[0] : 'unknown')); if (!updateJson.version) {
if (!match) {
const errMsg = 'No version info found'; const errMsg = 'No version info found';
UpdateModel.set({ UpdateModel.set({
status: 'error', status: 'error',
@ -114,16 +113,15 @@ const Updater = {
this.scheduleNextCheck(); this.scheduleNextCheck();
return; return;
} }
const updateMinVersionMatch = data.match(/#\s*updmin:v([\d+\.\w]+)/);
const prevLastVersion = UpdateModel.lastVersion; const prevLastVersion = UpdateModel.lastVersion;
UpdateModel.set({ UpdateModel.set({
status: 'ok', status: 'ok',
lastCheckDate: dt, lastCheckDate: dt,
lastSuccessCheckDate: dt, lastSuccessCheckDate: dt,
lastVersionReleaseDate: new Date(match[1]), lastVersionReleaseDate: new Date(updateJson.date),
lastVersion: match[2], lastVersion: updateJson.version,
lastCheckError: null, lastCheckError: null,
lastCheckUpdMin: updateMinVersionMatch ? updateMinVersionMatch[1] : null lastCheckUpdMin: updateJson.minVersion || null
}); });
UpdateModel.save(); UpdateModel.save();
this.scheduleNextCheck(); this.scheduleNextCheck();

View File

@ -62,8 +62,13 @@ const Transport = {
}); });
res.on('end', () => { res.on('end', () => {
data = window.Buffer.concat(data); data = window.Buffer.concat(data);
if (config.utf8) { if (config.json) {
data = data.toString('utf8'); data = data.toString('utf8');
try {
data = JSON.parse(data);
} catch (e) {
config.error('Error parsing JSON: ' + e.message);
}
} }
config.success(data); config.success(data);
}); });