commit d24d8bff7f37bc24b64d3652db112f6f02191d87 Author: jake Date: Fri Mar 15 22:54:21 2024 -0400 GIT THIS diff --git a/asset/0.png b/asset/0.png new file mode 100644 index 0000000..6917774 Binary files /dev/null and b/asset/0.png differ diff --git a/asset/1.png b/asset/1.png new file mode 100644 index 0000000..cc0263b Binary files /dev/null and b/asset/1.png differ diff --git a/asset/2.png b/asset/2.png new file mode 100644 index 0000000..d0739da Binary files /dev/null and b/asset/2.png differ diff --git a/asset/3.png b/asset/3.png new file mode 100644 index 0000000..a350044 Binary files /dev/null and b/asset/3.png differ diff --git a/asset/4.png b/asset/4.png new file mode 100644 index 0000000..3471138 Binary files /dev/null and b/asset/4.png differ diff --git a/asset/5.png b/asset/5.png new file mode 100644 index 0000000..275bcdf Binary files /dev/null and b/asset/5.png differ diff --git a/asset/6.png b/asset/6.png new file mode 100644 index 0000000..83b4e0a Binary files /dev/null and b/asset/6.png differ diff --git a/asset/7.png b/asset/7.png new file mode 100644 index 0000000..b76cc13 Binary files /dev/null and b/asset/7.png differ diff --git a/asset/8.png b/asset/8.png new file mode 100644 index 0000000..df4d63f Binary files /dev/null and b/asset/8.png differ diff --git a/asset/9.png b/asset/9.png new file mode 100644 index 0000000..ba3193d Binary files /dev/null and b/asset/9.png differ diff --git a/counter.numb b/counter.numb new file mode 100644 index 0000000..573541a --- /dev/null +++ b/counter.numb @@ -0,0 +1 @@ +0 diff --git a/myapp.pl b/myapp.pl new file mode 100755 index 0000000..9123211 --- /dev/null +++ b/myapp.pl @@ -0,0 +1,73 @@ +#!/usr/bin/env perl +use Mojolicious::Lite -signatures; + +my $counter_file = 'counter.numb'; +my $counter = 0; +my $number_length = 6; + +app->hook(before_server_start => sub ($server, $app) { + if (! (-e $counter_file)) { + open my $fh, '>', $counter_file; + syswrite $fh, $counter, length $counter, 0; + close $fh; + } + open my $fh, '<', $counter_file; + sysread $fh, $counter, 20; # 20 bytes to read which is more than enough for a counter + close $fh; + + -e '/bin/montage' or die 'ImageMagick not installed? `/bin/montage`'; +}); + +get '/' => sub ($c) { + make_image(to_number_length($counter++)); + $c->res->headers->header('Content-Security-Policy' => 'img-src * artemis.venus.place'); + $c->res->headers->header('Server' => 'nginx/1.22.1'); # lie :) + $c->reply->file('tmp/counter.png'); + open my $fh, '>', $counter_file; + syswrite $fh, $counter, length $counter, 0; + close $fh; +}; + +sub to_number_length ($counter) { + while (length $counter lt 6) { + $counter = "0$counter"; + } + return $counter; +} + +## returns path for image +sub make_image ($counter) { + + my @args; + for my $i (split(//, $counter)) { + push @args, "asset/$i.png"; + } + push @args, qw( -tile 6x1 -geometry +0+0 -background none -scale 50 ); + my $o = 'tmp/counter.png'; + push @args, $o; + + if (! (-w 'tmp/' and -d 'tmp/')) { + mkdir 'tmp'; + } + + # user can refresh the page faster than this can run + # I guess in theory someone can DOS me just by refreshing the page enough times + system('/bin/montage', @args); + + return $o; +} + +app->start; +__DATA__ + +@@ index.html.ep +% layout 'default'; +% title 'Welcome'; +

Welcome to the Mojolicious real-time web framework!

+ +@@ layouts/default.html.ep + + + <%= title %> + <%= content %> +