diff options
Diffstat (limited to 'lib/DBInfoscreen.pm')
-rw-r--r-- | lib/DBInfoscreen.pm | 81 |
1 files changed, 24 insertions, 57 deletions
diff --git a/lib/DBInfoscreen.pm b/lib/DBInfoscreen.pm index 53944fd..c784e96 100644 --- a/lib/DBInfoscreen.pm +++ b/lib/DBInfoscreen.pm @@ -1,29 +1,24 @@ package DBInfoscreen; -# Copyright (C) 2011-2020 Daniel Friesel +# Copyright (C) 2011-2020 Birte Kristina Friesel # # SPDX-License-Identifier: AGPL-3.0-or-later use Mojo::Base 'Mojolicious'; use Cache::File; +use DBInfoscreen::Helper::EFA; use DBInfoscreen::Helper::HAFAS; -use DBInfoscreen::Helper::Marudor; use DBInfoscreen::Helper::Wagonorder; use File::Slurp qw(read_file); use JSON; -use Travel::Status::DE::IRIS::Stations; use utf8; -no if $] >= 5.018, warnings => 'experimental::smartmatch'; - sub startup { my ($self) = @_; $self->config( - hafas_rest_api => $ENV{DBFAKEDISPLAY_HAFAS_API} - // 'https://v5.db.transport.rest', hypnotoad => { accepts => $ENV{DBFAKEDISPLAY_ACCEPTS} // 100, clients => $ENV{DBFAKEDISPLAY_CLIENTS} // 10, @@ -41,6 +36,7 @@ sub startup { ); chomp $self->config->{version}; + $self->defaults( version => $self->config->{version} // 'UNKNOWN' ); # Generally, the reverse proxy handles compression. # Also, Mojolicious compression breaks legacy callback-based JSON endpoints @@ -51,15 +47,14 @@ sub startup { before_dispatch => sub { my ($self) = @_; - # The "theme" cookie is set client-side if the theme we delivered was - # changed by dark mode detection or by using the theme switcher. It's - # not part of Mojolicious' session data (and can't be, due to - # signing and HTTPOnly), so we need to add it here. + # The "theme" cookie is set client-side if the theme we delivered was + # changed by dark mode detection or by using the theme switcher. It's + # not part of Mojolicious' session data (and can't be, due to + # signing and HTTPOnly), so we need to add it here. for my $cookie ( @{ $self->req->cookies } ) { if ( $cookie->name eq 'theme' ) { $self->session( theme => $cookie->value ); - return; } } } @@ -90,36 +85,6 @@ sub startup { ); $self->attr( - ice_type_map => sub { - if ( -r 'share/zugbildungsplan.json' ) { - my $ice_type_map = JSON->new->utf8->decode( - scalar read_file('share/zugbildungsplan.json') ); - my $ret = {}; - while ( my ( $k, $v ) = each %{ $ice_type_map->{train} } ) { - if ( $v->{type} ) { - $ret->{$k} = [ - $v->{type}, $v->{shortType}, - exists $v->{wagons} ? 1 : 0 - ]; - } - } - return $ret; - } - return {}; - } - ); - - $self->attr( - train_details_db => sub { - if ( -r 'share/zugbildungsplan.json' ) { - return JSON->new->utf8->decode( - scalar read_file('share/zugbildungsplan.json') )->{train}; - } - return {}; - } - ); - - $self->attr( dbdb_wagon => sub { return JSON->new->utf8->decode( scalar read_file('share/dbdb_wagen.json') ); @@ -127,10 +92,9 @@ sub startup { ); $self->helper( - hafas => sub { + efa => sub { my ($self) = @_; - state $hafas = DBInfoscreen::Helper::HAFAS->new( - api => $self->config->{hafas_rest_api}, + state $efa = DBInfoscreen::Helper::EFA->new( log => $self->app->log, main_cache => $self->app->cache_iris_main, realtime_cache => $self->app->cache_iris_rt, @@ -142,9 +106,9 @@ sub startup { ); $self->helper( - marudor => sub { + hafas => sub { my ($self) = @_; - state $hafas = DBInfoscreen::Helper::Marudor->new( + state $hafas = DBInfoscreen::Helper::HAFAS->new( log => $self->app->log, main_cache => $self->app->cache_iris_main, realtime_cache => $self->app->cache_iris_rt, @@ -243,7 +207,9 @@ sub startup { $self->helper( 'utilization_icon' => sub { my ( $self, $utilization ) = @_; - my ( $first, $second ) = @{ $utilization // [ 0, 0 ] }; + my ( $first, $second ) = @{ $utilization // [] }; + $first //= 0; + $second //= 0; my $sum = ( $first + $second ) / 2; my @symbols @@ -291,7 +257,7 @@ sub startup { my $r = $self->routes; - $r->get('/_redirect')->to('static#redirect'); + $r->get('/_redirect')->to('stationboard#redirect_to_station'); # legacy entry point $r->get('/_auto')->to('static#geostop'); @@ -306,24 +272,25 @@ sub startup { $r->get('/_impressum')->to('static#imprint'); + $r->get('/dyn/:av/autocomplete.js')->to('stationboard#autocomplete'); + $r->get('/_wr/:train/:departure')->to('wagenreihung#wagenreihung'); - $r->get('/wr/:train')->to('wagenreihung#zugbildung_db'); $r->get('/w/*wagon')->to('wagenreihung#wagen'); $r->get('/_ajax_mapinfo/:tripid/:lineno')->to('map#ajax_route'); $r->get('/map/:tripid/:lineno')->to('map#route'); - $r->get('/intersection/:trips')->to('map#intersection'); - $r->get('/z/:train/*station')->to('stationboard#station_train_details'); - $r->get('/z/:train')->to('stationboard#train_details'); - - $r->get('/map')->to('map#search_form'); - $r->get('/_trainsearch')->to('map#search'); + $r->get( '/z/:train/*station' => [ format => [ 'html', 'json' ] ] ) + ->to( 'stationboard#station_train_details', format => undef ) + ->name('train_at_station'); + $r->get( '/z/:train' => [ format => [ 'html', 'json' ] ] ) + ->to( 'stationboard#train_details', format => undef )->name('train'); $self->defaults( layout => 'app' ); $r->get('/')->to('stationboard#handle_request'); $r->get('/multi/*station')->to('stationboard#handle_request'); - $r->get('/*station')->to('stationboard#handle_request'); + $r->get( '/*station' => [ format => [ 'html', 'json' ] ] ) + ->to( 'stationboard#handle_request', format => undef ); $self->types->type( json => 'application/json; charset=utf-8' ); |