summaryrefslogtreecommitdiff
path: root/app.pl
blob: b0aca9c06b440420e4e52a03fca5a8b83ddb1ab0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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;