fix: should notify new version only once a day even when an error occurs (#353)

Add more messages in console

fixes #353
This commit is contained in:
Joxit 2024-02-08 04:25:14 +01:00
parent 6318ccfdf5
commit 6c3c27e215
No known key found for this signature in database
GPG Key ID: F526592B8E012263
3 changed files with 12 additions and 6 deletions

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
{
"name": "docker-registry-ui",
"version": "2.5.6",
"version": "2.5.7",
"type": "module",
"scripts": {
"format": "npm run format-html && npm run format-js && npm run format-riot",

View File

@ -43,7 +43,7 @@
if (latest && latest.tag_name) {
this.update({ tag_name: latest.tag_name, latest });
}
if (!latest || isNaN(expires) || new Date().getTime() > expires) {
if (isNaN(expires) || new Date().getTime() > expires) {
this.checkForUpdates(props, state);
}
},
@ -64,16 +64,22 @@
const self = this;
oReq.addEventListener('load', function () {
localStorage.setItem(EXPIRES, new Date().getTime() + ONE_DAY);
if (this.status === 200) {
const latest = parseJSON(this.responseText);
if (latest && self.tag_name !== latest.tag_name && !isNewestVersion(props.version, latest.tag_name)) {
props.onNotify('A new version of Docker Registry UI is available!');
}
localStorage.setItem(LATEST, this.responseText);
localStorage.setItem(EXPIRES, new Date().getTime() + ONE_DAY);
self.update({ tag_name: latest.tag_name, latest });
} else {
props.onNotify('Cannot check for new updates. See the browser console.');
} else if (this.status !== 404) {
// Should not notify if the project is not found.
props.onNotify('Cannot check for new updates. Will try again in 24 hours. See the browser console.');
console.error(
`Cannot check for new Docker Registry UI updates. This is most likely a GitHub issue. You don't need to worry about it.`
);
console.error(`Got status code ${this.status} from Github API with response ${this.responseText}`);
}
});