Add meta refresh option

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

View File

@ -25,19 +25,37 @@ $router.get(-> $request, $response {
}); });
$router.post(-> $request, $response { $router.post(-> $request, $response {
my Str $return-url = $request.content.{'hyperlink'}; my Str $return-url = $request.content.{'hyperlink'};
my Str $url-scheme = $request.headers.{'X-Forwarded-Proto'} || 'http'; my Bool $meta-refresh = $request.content.<meta-refresh> ?? True !! False;
my Str $url-host = $request.headers.{'Host'}; my Str $url-scheme = $request.headers.{'X-Forwarded-Proto'} || 'http';
my Str $base-url = $url-scheme ~ '://' ~ $url-host ~ '/'; my Str $url-host = $request.headers.{'Host'};
my Str $hyperlink = $base-url ~ encode-base64(gzip($return-url), :str); my (Str $base-url, Str $hyperlink, Str %stash);
my 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', title => 'New hyperlink created',
hyperlink => $hyperlink; hyperlink => $hyperlink;
$response.html($template.render: 'index', %stash); $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 { $router.get('/**', -> $request, $response {
my Str $return-url = $request.path.substr(1); # Omits the leading slash my Str $return-url = $request.path.substr(1); # Omits the leading slash
my Str $redirect-url = gunzip(decode-base64($return-url, :bin)); my Str $redirect-url = gunzip(decode-base64($return-url, :bin));

View File

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

View File

@ -1,11 +1,17 @@
{{> header}} {{> header}}
{{#hyperlink}} {{^meta-refresh}}
<p>Your hyperlink is: <a href="{{hyperlink}}">{{hyperlink}}</a></p> {{#hyperlink}}
{{/hyperlink}} <p>Your hyperlink is: <a href="{{hyperlink}}">{{hyperlink}}</a></p>
<form method="post"> {{/hyperlink}}
<label for="hyperlink">Hyperlink</label> <form method="post">
<input id="hyperlink" name="hyperlink" type="text" minlength="4" <label for="hyperlink">Hyperlink</label>
maxlength="2097152" required> <input id="hyperlink" name="hyperlink" type="text" minlength="4"
<button type="submit">Process</button> maxlength="2083" required>
</form> <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>
{{/meta-refresh}}
{{> footer}} {{> footer}}