diff options
Diffstat (limited to 'lib/DBInfoscreen')
-rw-r--r-- | lib/DBInfoscreen/Controller/Stationboard.pm | 2 | ||||
-rw-r--r-- | lib/DBInfoscreen/Helper/Wagonorder.pm | 52 |
2 files changed, 13 insertions, 41 deletions
diff --git a/lib/DBInfoscreen/Controller/Stationboard.pm b/lib/DBInfoscreen/Controller/Stationboard.pm index 2eb7b12..85a94e5 100644 --- a/lib/DBInfoscreen/Controller/Stationboard.pm +++ b/lib/DBInfoscreen/Controller/Stationboard.pm @@ -775,7 +775,7 @@ sub render_train { if ( $self->param('detailed') ) { my $cycle_req = Mojo::Promise->new; push( @requests, $cycle_req ); - $self->wagonorder->has_umlauf_p( $result->train_no )->then( + $self->wagonorder->has_cycle_p( $result->train_no )->then( sub { $departure->{has_cycle} = 1; } diff --git a/lib/DBInfoscreen/Helper/Wagonorder.pm b/lib/DBInfoscreen/Helper/Wagonorder.pm index 5904d86..d303d18 100644 --- a/lib/DBInfoscreen/Helper/Wagonorder.pm +++ b/lib/DBInfoscreen/Helper/Wagonorder.pm @@ -57,12 +57,11 @@ sub is_available_p { return $promise; } -sub has_umlauf_p { - my ( $self, $train_no ) = @_; +sub head_dbdb_p { + my ( $self, $url ) = @_; my $promise = Mojo::Promise->new; - my $url = "https://lib.finalrewind.org/dbdb/db_umlauf/${train_no}.png"; my $cache = $self->{main_cache}; if ( my $content = $cache->get($url) ) { @@ -98,46 +97,19 @@ sub has_umlauf_p { return $promise; } -sub check_wagonorder_p { - my ( $self, $train_no, $wr_link ) = @_; - - my $promise = Mojo::Promise->new; +sub has_cycle_p { + my ( $self, $train_no ) = @_; - my $url - = "https://lib.finalrewind.org/dbdb/has_wagonorder/${train_no}/${wr_link}"; - my $cache = $self->{main_cache}; + return $self->head_dbdb_p( + "https://lib.finalrewind.org/dbdb/db_umlauf/${train_no}.png"); +} - if ( my $content = $cache->get($url) ) { - if ( $content eq 'y' ) { - return $promise->resolve; - } - else { - return $promise->reject; - } - } +sub check_wagonorder_p { + my ( $self, $train_no, $wr_link ) = @_; - $self->{user_agent}->request_timeout(5)->head_p( $url => $self->{header} ) - ->then( - sub { - my ($tx) = @_; - if ( $tx->result->is_success ) { - $cache->set( $url, 'y' ); - $promise->resolve; - } - else { - $cache->set( $url, 'n' ); - $promise->reject; - } - return; - } - )->catch( - sub { - $cache->set( $url, 'n' ); - $promise->reject; - return; - } - )->wait; - return $promise; + return $self->head_dbdb_p( + "https://lib.finalrewind.org/dbdb/has_wagonorder/${train_no}/${wr_link}" + ); } sub get_p { |