Skip to content

Commit

Permalink
feat: wait 3 seconds when redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
LLaammTTeerr committed Jun 26, 2024
1 parent 6647b97 commit 49b85bd
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
4 changes: 2 additions & 2 deletions judge/views/URL.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.http import HttpResponseBadRequest, HttpResponseForbidden, HttpResponseRedirect
from django.http import HttpResponseBadRequest, HttpResponseForbidden
from django.shortcuts import render

from judge.forms import URLForm
Expand All @@ -21,6 +21,6 @@ def shorten_url(request):
def redirect_url(request, short_code):
try:
url = URL.objects.get(short_code=short_code)
return HttpResponseRedirect(url.original_url)
return render(request, 'shortener/wait_redirect.html', {'original_url': url.original_url})
except URL.DoesNotExist:
return HttpResponseForbidden('URL not exist')
24 changes: 24 additions & 0 deletions templates/shortener/wait_redirect.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html>
<head>
<title>Redirecting...</title>
<script>
function startCountdown() {
var count = 3;
var countdownElement = document.getElementById('countdown');
var interval = setInterval(function() {
countdownElement.innerText = count;
count--;
if (count < 0) {
clearInterval(interval);
window.location.replace("{{ original_url }}");
}
}, 1000);
}
window.onload = startCountdown;
</script>
</head>
<body>
<h1>Redirecting in <span id="countdown">3</span> seconds...</h1>
</body>
</html>

0 comments on commit 49b85bd

Please sign in to comment.