@@ -21,15 +21,20 @@ sub dispatch_request {
21
21
my @all = $machines -> refresh-> active-> all;
22
22
$self -> json_response({json => {
23
23
total => scalar @all ,
24
- recent => [ map {$_ -> TO_JSON} @all ]
24
+ recent => [
25
+ map { {
26
+ hash => $_ -> email,
27
+ last_seen => $_ -> last_seen." "
28
+ } } @all
29
+ ]
25
30
}})
26
31
},
27
- sub (PUT + /ident) {
32
+ sub (PUT | POST + /ident) {
28
33
my $data = decode_json $self -> req-> content;
29
34
# get the local IP of the request
30
35
# machine should've already broadcast for IP so we should have current
31
36
# mac address
32
- if (my $client = $machines -> search({ ip => $self -> req-> address }, {
37
+ if (my $client = $machines -> refresh -> search({ ip => $self -> req-> address }, {
33
38
order_by => {-desc => [' last_seen' ] }
34
39
})-> first) {
35
40
$client -> update({email => $data -> {' hash' }});
@@ -39,15 +44,15 @@ sub dispatch_request {
39
44
},
40
45
sub (GET + /status/* ) {
41
46
my ($self , $hash ) = @_ ;
42
- if (my $client = $machines -> search({ email => $hash })-> first) {
47
+ if (my $client = $machines -> refresh -> active -> search({ email => $hash })-> first) {
43
48
$self -> json_response({json => {
44
49
status => JSON::XS::true,
45
- seen => $client -> last_seen
46
- });
50
+ seen => $client -> last_seen-> ymd( ' - ' )
51
+ }} );
47
52
} else {
48
53
$self -> json_response({json => {
49
54
status => JSON::XS::false,
50
- });
55
+ }} );
51
56
}
52
57
},
53
58
sub (GET + /all) {
@@ -73,14 +78,4 @@ sub json_response {
73
78
], [ encode_json $json ] ];
74
79
}
75
80
76
- around ' to_psgi_app' , sub {
77
- my ($orig ,$self ) = (shift , shift );
78
- my $app = $self -> $orig (@_ );
79
- builder {
80
- enable ' CrossOrigin' , origins => ' http://skiffprofile.herokuapp.com' , headers => [' *' ];
81
- # enable "JSONP", callback_key => 'callback';
82
- $app ;
83
- };
84
- };
85
-
86
81
__PACKAGE__ -> run_if_script;
0 commit comments