mirror of
https://github.com/Unleash/unleash.git
synced 2025-02-19 00:15:43 +01:00
fix: version-checker must have instanceId
This commit is contained in:
parent
5d284e3ac9
commit
b6793d2957
@ -12,49 +12,53 @@ class VersionService {
|
|||||||
oss: version,
|
oss: version,
|
||||||
enterprise: enterpriseVersion,
|
enterprise: enterpriseVersion,
|
||||||
};
|
};
|
||||||
this.setInstanceId();
|
this.enabled =
|
||||||
if (versionCheck && versionCheck.url) {
|
versionCheck && versionCheck.enable === 'true' && versionCheck.url;
|
||||||
this.versionCheckUrl = versionCheck.url;
|
this.versionCheckUrl = versionCheck ? versionCheck.url : undefined;
|
||||||
if (versionCheck.enable === 'true') {
|
process.nextTick(() => this.setup());
|
||||||
this.enabled = true;
|
}
|
||||||
this.checkLatestVersion(this.instanceId);
|
|
||||||
setInterval(
|
async setup() {
|
||||||
() => this.checkLatestVersion(this.instanceId),
|
await this.setInstanceId();
|
||||||
TWO_DAYS,
|
await this.checkLatestVersion(this.instanceId);
|
||||||
);
|
setInterval(
|
||||||
} else {
|
async () => this.checkLatestVersion(this.instanceId),
|
||||||
this.enabled = false;
|
TWO_DAYS,
|
||||||
}
|
);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async setInstanceId() {
|
async setInstanceId() {
|
||||||
try {
|
try {
|
||||||
const { id } = await this.settingStore.get('instanceInfo');
|
const { id } = await this.settingStore.get('instanceInfo');
|
||||||
this.instanceId = id;
|
this.instanceId = id;
|
||||||
return id;
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.logger.warn('Could not find instanceInfo');
|
this.logger.warn('Could not find instanceInfo');
|
||||||
return undefined;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async checkLatestVersion(instanceId) {
|
async checkLatestVersion() {
|
||||||
if (this.enabled) {
|
if (this.enabled) {
|
||||||
try {
|
try {
|
||||||
const data = await fetch(this.versionCheckUrl, {
|
const res = await fetch(this.versionCheckUrl, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
versions: this.current,
|
versions: this.current,
|
||||||
instanceId,
|
instanceId: this.instanceId,
|
||||||
}),
|
}),
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
}).then(res => res.json());
|
});
|
||||||
this.latest = {
|
if (res.ok) {
|
||||||
oss: data.versions.oss,
|
const data = await res.json();
|
||||||
enterprise: data.versions.enterprise,
|
this.latest = {
|
||||||
};
|
oss: data.versions.oss,
|
||||||
this.isLatest = data.latest;
|
enterprise: data.versions.enterprise,
|
||||||
|
};
|
||||||
|
this.isLatest = data.latest;
|
||||||
|
} else {
|
||||||
|
this.logger.info(
|
||||||
|
`Could not check newest version. Status: ${res.status}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.logger.info('Could not check newest version', err);
|
this.logger.info('Could not check newest version', err);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user