Return stats about last backup download times
This commit is contained in:
parent
221e83ccab
commit
4a117eff83
|
@ -388,20 +388,34 @@ 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:
|
||||||
|
raise Http404
|
||||||
|
|
||||||
if not backup_path:
|
backup_url = 'https://static.{}/backups/{}'.format(
|
||||||
raise Http404
|
settings.PRODUCTION_HOST,
|
||||||
|
backup_path,
|
||||||
|
)
|
||||||
|
cache.set(backup_user['name'], datetime.datetime.now())
|
||||||
|
|
||||||
backup_url = 'https://static.{}/backups/{}'.format(
|
return redirect(backup_url)
|
||||||
settings.PRODUCTION_HOST,
|
else:
|
||||||
backup_path,
|
backup_stats = []
|
||||||
)
|
for backup_user in secrets.BACKUP_TOKENS.values():
|
||||||
|
download_time = cache.get(backup_user['name'], None)
|
||||||
return redirect(backup_url)
|
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):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user