Mind-Fuck/multipart-form/multipart-form.raku

67 lines
1.7 KiB
Raku
Executable file

#!/usr/bin/env raku
=begin pod
=begin comment
uuuuuuu
uu$$$$$$$$$$$uu
uu$$$$$$$$$$$$$$$$$uu
u$$$$$$$$$$$$$$$$$$$$$u
u$$$$$$$$$$$$$$$$$$$$$$$u
u$$$$$$$$$$$$$$$$$$$$$$$$$u
u$$$$$$$$$$$$$$$$$$$$$$$$$u
u$$$$$$" "$$$" "$$$$$$u
"$$$$" u$u $$$$"
$$$u u$u u$$$
$$$u u$$$u u$$$
"$$$$uu$$$ $$$uu$$$$"
"$$$$$$$" "$$$$$$$"
u$$$$$$$u$$$$$$$u
u$"$"$"$"$"$"$u
uuu $$u$ $ $ $ $u$$ uuu
u$$$$ $$$$$u$u$u$$$ u$$$$
$$$$$uu "$$$$$$$$$" uu$$$$$$
u$$$$$$$$$$$uu """"" uuuu$$$$$$$$$$
$$$$"""$$$$$$$$$$uuu uu$$$$$$$$$"""$$$"
""" ""$$$$$$$$$$$uu ""$"""
uuuu ""$$$$$$$$$$uuu
u$$$uuu$$$$$$$$$uu ""$$$$$$$$$$$uuu$$$
$$$$$$$$$$"""" ""$$$$$$$$$$$"
"$$$$$" ""$$$$""
$$$" $$$$"
=end comment
=end pod
use v6.d;
use Humming-Bird::Core;
use Humming-Bird::Middleware;
use Humming-Bird::Advice;
use Template::Mustache;
# 'Config-y' stuff
my $template = Template::Mustache.new: :from<./templates>;
middleware &middleware-logger;
advice &advice-logger;
# Begin routing
get '/', -> $request, $response {
my Str %stash = title => 'File upload';
$response.html($template.render: 'index', %stash);
};
post '/', -> $request, $response {
my Str $filename =
$request.content<file><filename> ~
'.' ~
$request.content<file><headers><content-type>.split('/')[1];
my Buf $file-body = $request.content<file><body>;
('uploads/' ~ $filename).IO.spurt: $file-body;
$response.redirect('/');
};
# Send it
listen 3000;