summaryrefslogtreecommitdiff
path: root/app.pl
diff options
context:
space:
mode:
Diffstat (limited to 'app.pl')
-rw-r--r--app.pl74
1 files changed, 74 insertions, 0 deletions
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(<namespace>, <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;