Force update checks on startup (#595)

This commit is contained in:
Kevin Chung
2018-03-21 18:03:01 -04:00
committed by GitHub
parent 352e2503a6
commit 0022b6978a
2 changed files with 34 additions and 27 deletions

View File

@@ -139,7 +139,7 @@ def create_app(config='CTFd.config.Config'):
cache.init_app(app)
app.cache = cache
update_check()
update_check(force=True)
version = utils.get_config('ctf_version')

View File

@@ -730,35 +730,42 @@ def base64decode(s, urldecode=False):
def update_check(force=False):
update = app.config.get('UPDATE_CHECK') or force
# If UPDATE_CHECK is disabled don't check for updates at all.
if app.config.get('UPDATE_CHECK') is False:
return
# Get when we should check for updates next.
next_update_check = get_config('next_update_check') or 0
# If we have passed our saved time or we are forcing we should check.
update = (next_update_check < time.time()) or force
if update:
next_update_check = get_config('next_update_check') or 0
if (next_update_check < time.time()) or force:
try:
params = {
'current': app.VERSION
}
check = requests.get(
'https://versioning.ctfd.io/versions/latest',
params=params,
timeout=0.1
).json()
except requests.exceptions.RequestException as e:
pass
else:
try:
params = {
'current': app.VERSION
}
check = requests.get(
'https://versioning.ctfd.io/versions/latest',
params=params,
timeout=0.1
).json()
except requests.exceptions.RequestException as e:
pass
else:
try:
latest = check['resource']['tag']
html_url = check['resource']['html_url']
if StrictVersion(latest) > StrictVersion(app.VERSION):
set_config('version_latest', html_url)
elif StrictVersion(latest) <= StrictVersion(app.VERSION):
set_config('version_latest', None)
except KeyError:
latest = check['resource']['tag']
html_url = check['resource']['html_url']
if StrictVersion(latest) > StrictVersion(app.VERSION):
set_config('version_latest', html_url)
elif StrictVersion(latest) <= StrictVersion(app.VERSION):
set_config('version_latest', None)
finally:
# 12 hours later
next_update_check_time = int(time.time() + 43200)
set_config('next_update_check', next_update_check_time)
except KeyError:
set_config('version_latest', None)
finally:
# 12 hours later
next_update_check_time = int(time.time() + 43200)
set_config('next_update_check', next_update_check_time)
else:
set_config('version_latest', None)