Add meta refresh option

This commit is contained in:
swagg boi 2023-11-03 00:14:08 -04:00
parent b8208fe50f
commit 92bf9c75ed
3 changed files with 43 additions and 16 deletions

View file

@ -26,18 +26,36 @@ $router.get(-> $request, $response {
$router.post(-> $request, $response {
my Str $return-url = $request.content.{'hyperlink'};
my Bool $meta-refresh = $request.content.<meta-refresh> ?? True !! False;
my Str $url-scheme = $request.headers.{'X-Forwarded-Proto'} || 'http';
my Str $url-host = $request.headers.{'Host'};
my Str $base-url = $url-scheme ~ '://' ~ $url-host ~ '/';
my Str $hyperlink = $base-url ~ encode-base64(gzip($return-url), :str);
my Str %stash =
my (Str $base-url, Str $hyperlink, Str %stash);
$base-url = $meta-refresh
?? $url-scheme ~ '://' ~ $url-host ~ '/--meta-refresh/'
!! $url-scheme ~ '://' ~ $url-host ~ '/';
$hyperlink = $base-url ~ encode-base64(gzip($return-url), :str);
%stash =
title => 'New hyperlink created',
hyperlink => $hyperlink;
$response.html($template.render: 'index', %stash);
});
# Try a wildcard to catch 'all' path
# Process the hyperlink
$router.get('/--meta-refresh/**', -> $request, $response {
my Str $return-url = $request.path.subst: /^ '/--meta-refresh/'/, Empty;
my Str $redirect-url = gunzip(decode-base64($return-url, :bin));
my Str %stash =
title => 'Hyperlinking...',
redirect-url => $redirect-url;
$response.html($template.render: 'index', %stash);
});
$router.get('/**', -> $request, $response {
my Str $return-url = $request.path.substr(1); # Omits the leading slash
my Str $redirect-url = gunzip(decode-base64($return-url, :bin));

View file

@ -2,6 +2,9 @@
<html lang="en">
<head>
<title>{{title}}</title>
{{#meta-refresh}}
<meta http-equiv="Refresh" content="0; url='{{redirect-url}}'">
{{/meta-refresh}}
</head>
<body>
<h1>{{title}}</h1>

View file

@ -1,11 +1,17 @@
{{> header}}
{{#hyperlink}}
<p>Your hyperlink is: <a href="{{hyperlink}}">{{hyperlink}}</a></p>
{{/hyperlink}}
<form method="post">
{{^meta-refresh}}
{{#hyperlink}}
<p>Your hyperlink is: <a href="{{hyperlink}}">{{hyperlink}}</a></p>
{{/hyperlink}}
<form method="post">
<label for="hyperlink">Hyperlink</label>
<input id="hyperlink" name="hyperlink" type="text" minlength="4"
maxlength="2097152" required>
maxlength="2083" required>
<label for="meta-refresh">
<a href="https://en.wikipedia.org/wiki/Meta_refresh">Meta refresh?</a>
</label>
<input id="meta-refresh" name="meta-refresh" type="checkbox">
<button type="submit">Process</button>
</form>
</form>
{{/meta-refresh}}
{{> footer}}