diff options
author | Birte Kristina Friesel <derf@finalrewind.org> | 2023-09-10 16:51:01 +0200 |
---|---|---|
committer | Birte Kristina Friesel <derf@finalrewind.org> | 2023-09-10 16:51:01 +0200 |
commit | d81251419b2f6b18b3d96a14afe9163cc2ef6661 (patch) | |
tree | 5fc19b82beb33103be41d9f76e1b00f9c608e19e /lib/DBInfoscreen/Controller/Stationboard.pm | |
parent | 77ac1e6a8b304a0af2d46c890c270a322dfdf34d (diff) |
Always accept IRIS and HAFAS stations in input field4.18.0
Diffstat (limited to 'lib/DBInfoscreen/Controller/Stationboard.pm')
-rw-r--r-- | lib/DBInfoscreen/Controller/Stationboard.pm | 46 |
1 files changed, 44 insertions, 2 deletions
diff --git a/lib/DBInfoscreen/Controller/Stationboard.pm b/lib/DBInfoscreen/Controller/Stationboard.pm index 8cfdbfe..faf7c13 100644 --- a/lib/DBInfoscreen/Controller/Stationboard.pm +++ b/lib/DBInfoscreen/Controller/Stationboard.pm @@ -511,7 +511,7 @@ sub handle_request { $station, { errstr => $err, - status => ( $err =~ m{station name$} ? 300 : 500 ), + status => ( $err =~ m{Ambiguous|LOCATION} ? 300 : 500 ), }, $api_version ); @@ -521,7 +521,7 @@ sub handle_request { $station, { errstr => $err, - status => ( $err =~ m{station name$} ? 300 : 500 ), + status => ( $err =~ m{Ambiguous|LOCATION} ? 300 : 500 ), }, $hafas ); @@ -1873,4 +1873,46 @@ sub autocomplete { ); } +sub redirect_to_station { + my ($self) = @_; + my $input = $self->param('input'); + my $params = $self->req->params; + + $params->remove('input'); + + for my $param (qw(platforms mode admode via)) { + if ( + not $params->param($param) + or ( exists $default{$param} + and $params->param($param) eq $default{$param} ) + ) + { + $params->remove($param); + } + } + + if ( $input =~ m{ ^ [a-zA-Z]{1,5} \s+ \d+ $ }x ) { + $params = $params->to_string; + $self->redirect_to("/z/${input}?${params}"); + } + else { + my @candidates + = Travel::Status::DE::IRIS::Stations::get_station($input); + if ( + @candidates == 1 + and ( $input eq $candidates[0][0] + or lc($input) eq lc( $candidates[0][1] ) + or $input eq $candidates[0][2] ) + ) + { + $params->remove('hafas'); + } + else { + $params->param( hafas => 1 ); + } + $params = $params->to_string; + $self->redirect_to("/${input}?${params}"); + } +} + 1; |