From ae0e6d987781d2fbf225611e2f8df37380a2bbcd Mon Sep 17 00:00:00 2001 From: yo mama Date: Thu, 12 Feb 2015 18:29:27 -0800 Subject: first --- app.pl | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 app.pl (limited to 'app.pl') diff --git a/app.pl b/app.pl new file mode 100644 index 0000000..b0aca9c --- /dev/null +++ b/app.pl @@ -0,0 +1,74 @@ +#!/usr/bin/env perl +use Dancer; +use Data::Dumper; +use Data::UUID; + +sub create_uuid{ + my $ug = Data::UUID->new; + my $uuid1 = $ug->create(); + return $uuid1; +# $uuid2 = $ug->create_from_name(, ); +# +# $res = $ug->compare($uuid1, $uuid2); +# +# $str = $ug->to_string( $uuid ); +# $uuid = $ug->from_string( $str ); +} + +sub cleanup{ + my $tmpdir = shift; + my $clean_exec = system("rm -r ${tmpdir}"); + if( $clean_exec){ + return { error => "Unable to cleanup tempdir" } + } +} + +sub resize_texture { + my $img = shift; + my $tmpdir = shift; + my $tmp_img = $img; + $tmp_img =~ s/\./00./g; + my $exec_im = system ("imagemagick -resize 256x256! $img $tmp_img"); + if ($exec_im){ + return { error => "Unable to resize image" } ; + } + return {}; +} + + +set public => './'; + +get '/download/*.*' => sub { + my ($file, $ext) = splat; + # do something with $file.$ext here +}; + +get qr{/img/([\w\.\-_]+)} => sub { + my ($filename) = splat; + send_file sprintf("/img/%s", $filename); +}; +get qr{/css/([\w\.\-_]+)} => sub { + my ($filename) = splat; + send_file sprintf("/css/%s", $filename); +}; +get qr{/js/([\w\.\-_]+)} => sub { + my ($filename) = splat; + send_file sprintf("/js/%s", $filename); +}; +get '/' => sub { + send_file "index.html"; +}; +get qr{/fonts/([\w\.\-_]+)} => sub { + my ($filename) = splat; + send_file sprintf("/fonts/%s", $filename); +}; + +post '/img/load' => sub { + my $texture = params->{texture}; + my $heightmap = params->{heightmap}; + to_json( { texture => $texture, heightmap => $heightmap } ); + +}; +post 'img/save' => sub { +}; +dance; -- cgit v1.2.3-70-g09d2