Return stats about last backup download times

This commit is contained in:
Tanner Collin 2020-02-27 22:45:50 +00:00
parent 221e83ccab
commit 4a117eff83

View File

@ -388,9 +388,7 @@ class BackupView(views.APIView):
backup_user = secrets.BACKUP_TOKENS.get(auth_token, None) backup_user = secrets.BACKUP_TOKENS.get(auth_token, None)
if not backup_user: if backup_user:
raise exceptions.PermissionDenied()
backup_path = cache.get(backup_user['cache_key'], None) backup_path = cache.get(backup_user['cache_key'], None)
if not backup_path: if not backup_path:
@ -400,8 +398,24 @@ class BackupView(views.APIView):
settings.PRODUCTION_HOST, settings.PRODUCTION_HOST,
backup_path, backup_path,
) )
cache.set(backup_user['name'], datetime.datetime.now())
return redirect(backup_url) return redirect(backup_url)
else:
backup_stats = []
for backup_user in secrets.BACKUP_TOKENS.values():
download_time = cache.get(backup_user['name'], None)
if download_time:
time_delta = datetime.datetime.now() - download_time
less_than_24h = bool(time_delta.days == 0)
else:
less_than_24h = False
backup_stats.append(dict(
backup_user=backup_user['name'],
download_time=download_time,
less_than_24h=less_than_24h,
))
return Response(backup_stats)
class PasteView(views.APIView): class PasteView(views.APIView):