fix check-for-update fetching code

This commit is contained in:
Nick Sweeting 2024-01-02 17:17:35 -08:00
parent 73993d26c0
commit 8ee2981957
2 changed files with 37 additions and 36 deletions

View file

@ -429,7 +429,7 @@ def get_versions_available_on_github(config):
# we only want to perform the (relatively expensive) check for new versions # we only want to perform the (relatively expensive) check for new versions
# when its most relevant, e.g. when the user runs a long-running command # when its most relevant, e.g. when the user runs a long-running command
subcommand_run_by_user = sys.argv[3] subcommand_run_by_user = sys.argv[3] if len(sys.argv) > 3 else 'help'
long_running_commands = ('add', 'schedule', 'update', 'status', 'server') long_running_commands = ('add', 'schedule', 'update', 'status', 'server')
if subcommand_run_by_user not in long_running_commands: if subcommand_run_by_user not in long_running_commands:
return None return None
@ -446,7 +446,7 @@ def get_versions_available_on_github(config):
# find current version or nearest older version (to link to) # find current version or nearest older version (to link to)
current_version = None current_version = None
for idx, release in enumerate(all_releases): for idx, release in enumerate(all_releases):
release_version = parse_version_string(release["tag_name"]) release_version = parse_version_string(release['tag_name'])
if release_version <= installed_version: if release_version <= installed_version:
current_version = release current_version = release
break break
@ -460,7 +460,7 @@ def get_versions_available_on_github(config):
except IndexError: except IndexError:
recommended_version = None recommended_version = None
return {"recommended_version": recommended_version, "current_version": current_version} return {'recommended_version': recommended_version, 'current_version': current_version}
def can_upgrade(config): def can_upgrade(config):
if config['VERSIONS_AVAILABLE'] and config['VERSIONS_AVAILABLE']['recommended_version']: if config['VERSIONS_AVAILABLE'] and config['VERSIONS_AVAILABLE']['recommended_version']:
@ -783,7 +783,7 @@ def load_config(defaults: ConfigDefaultDict,
return extended_config return extended_config
def parse_version_string(version: str) -> Tuple[int, int int]: def parse_version_string(version: str) -> Tuple[int, int, int]:
"""parses a version tag string formatted like 'vx.x.x' into (major, minor, patch) ints""" """parses a version tag string formatted like 'vx.x.x' into (major, minor, patch) ints"""
base = v.split('+')[0].split('v')[-1] # remove 'v' prefix and '+editable' suffix base = v.split('+')[0].split('v')[-1] # remove 'v' prefix and '+editable' suffix
return tuple(int(part) for part in base.split('.'))[:3] return tuple(int(part) for part in base.split('.'))[:3]

View file

@ -141,42 +141,43 @@
{% block footer %}<div id="footer"></div>{% endblock %} {% block footer %}<div id="footer"></div>{% endblock %}
</div> </div>
<script> {% if user.is_authenticated and user.is_superuser and CAN_UPGRADE %}
{% if user.is_authenticated and user.is_superuser and CAN_UPGRADE %} <script>
if (!localStorage.getItem("bannerDismissed")) { if (!localStorage.getItem("bannerDismissed")) {
const upgradeVersionTag = "{{VERSIONS_AVAILABLE.recommended_version.tag_name}}" const upgradeVersionTag = "{{VERSIONS_AVAILABLE.recommended_version.tag_name}}"
const upgradeVersionURL = "{{VERSIONS_AVAILABLE.recommended_version.html_url}}" const upgradeVersionURL = "{{VERSIONS_AVAILABLE.recommended_version.html_url}}"
const currentVersionTag = "{{VERSION}}" const currentVersionTag = "{{VERSION}}"
const currentVersionURL = "{{VERSIONS_AVAILABLE.recommended_version.html_url}}" const currentVersionURL = "{{VERSIONS_AVAILABLE.recommended_version.html_url}}"
createBanner(currentVersionTag, currentVersionURL, upgradeVersionTag, upgradeVersionURL) createBanner(currentVersionTag, currentVersionURL, upgradeVersionTag, upgradeVersionURL)
}
function createBanner(currentVersionTag, currentVersionURL, upgradeVersionTag, upgradeVersionURL) {
const banner = document.createElement('div')
banner.setAttribute('id', 'upgrade-banner');
banner.innerHTML = `
<p>There's a new version of ArchiveBox available!</p>
Your version: <a href=${currentVersionURL}>${currentVersionTag}</a> | New version: <a href=${upgradeVersionURL}>${upgradeVersionTag}</a>
<p>
<a href=https://github.com/ArchiveBox/ArchiveBox/wiki/Upgrading-or-Merging-Archives>Upgrade Instructions</a> | <a href=https://github.com/ArchiveBox/ArchiveBox/releases>Changelog</a> | <a href=https://github.com/ArchiveBox/ArchiveBox/wiki/Roadmap>Roadmap</a>
</p>
<button id="dismiss-btn">Dismiss</button>
`
document.body.appendChild(banner);
const dismissButton = document.querySelector("#dismiss-btn")
if (dismissButton) {
dismissButton.addEventListener("click", dismissBanner)
} }
}
function dismissBanner() { function createBanner(currentVersionTag, currentVersionURL, upgradeVersionTag, upgradeVersionURL) {
const banner = document.getElementById("upgrade-banner") const banner = document.createElement('div')
banner.style.display = "none" banner.setAttribute('id', 'upgrade-banner');
localStorage.setItem("bannerDismissed", "true") banner.innerHTML = `
} <p>There's a new version of ArchiveBox available!</p>
{% endif %} Your version: <a href=${currentVersionURL}>${currentVersionTag}</a> | New version: <a href=${upgradeVersionURL}>${upgradeVersionTag}</a>
<p>
<a href=https://github.com/ArchiveBox/ArchiveBox/wiki/Upgrading-or-Merging-Archives>Upgrade Instructions</a> | <a href=https://github.com/ArchiveBox/ArchiveBox/releases>Changelog</a> | <a href=https://github.com/ArchiveBox/ArchiveBox/wiki/Roadmap>Roadmap</a>
</p>
<button id="dismiss-btn">Dismiss</button>
`
document.body.appendChild(banner);
const dismissButton = document.querySelector("#dismiss-btn")
if (dismissButton) {
dismissButton.addEventListener("click", dismissBanner)
}
}
function dismissBanner() {
const banner = document.getElementById("upgrade-banner")
banner.style.display = "none"
localStorage.setItem("bannerDismissed", "true")
}
</script>
{% endif %}
<script>
$ = django.jQuery; $ = django.jQuery;
$.fn.reverse = [].reverse; $.fn.reverse = [].reverse;