diff options
author | Andinus <andinus@nand.sh> | 2022-02-04 13:11:42 +0530 |
---|---|---|
committer | Andinus <andinus@nand.sh> | 2022-02-04 13:11:42 +0530 |
commit | ba8aea585c95477e7002666cc0ee461504734003 (patch) | |
tree | c06b19121571c22bbc70aa1b0269d8f9cdc4c583 /server | |
parent | 3f8a1326dffb01512a1b19a141360180bf6b7fd8 (diff) | |
download | vela-ba8aea585c95477e7002666cc0ee461504734003.tar.gz |
Implement getting smiles
Diffstat (limited to 'server')
-rw-r--r-- | server/service.raku | 26 |
1 files changed, 25 insertions, 1 deletions
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; } |