From ba8aea585c95477e7002666cc0ee461504734003 Mon Sep 17 00:00:00 2001 From: Andinus Date: Fri, 4 Feb 2022 13:11:42 +0530 Subject: Implement getting smiles --- server/service.raku | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'server') diff --git a/server/service.raku b/server/service.raku index 638989c..1ccbb85 100644 --- a/server/service.raku +++ b/server/service.raku @@ -67,7 +67,7 @@ my $application = route { my Str @messages; @messages.push("Max file size exceeded") if $img.body-blob.bytes > 2097152; # 1024 * 1024 * 2 - @messages.push("Only png/jpeg allowed"); + @messages.push("Only png/jpeg allowed") if $img.content-type ne "image/png"|"image/jpeg"; $stored = False if @messages.elems; @@ -86,6 +86,30 @@ my $application = route { } } + get -> 'smile', $id { + my IO() $user-store = "%s/%s".sprintf: $store, $id; + + my $img; + if "$user-store/images".IO.d { + put "huh"; + my @imgs = dir("$user-store/images").grep(*.f); + if @imgs.elems { + $img = @imgs.pick(1).first; + } else { + response.status = 406; + } + } else { + response.status = 404; + } + + if $img { + static $img; + $img.unlink; + } else { + content 'text/plain', ''; + } + } + # Serving static assets. get -> 'js', *@path { static 'dist/js', @path; } get -> 'css', *@path { static 'dist/css', @path; } -- cgit 1.4.1-2-gfad0