Commit | Line | Data |
319537bf |
1 | package Gitalist::Controller::LegacyURI; |
2 | use Moose; |
9c515df2 |
3 | use Moose::Autobox; |
319537bf |
4 | use namespace::autoclean; |
5 | |
6 | BEGIN { extends 'Gitalist::Controller' } |
7 | |
592fa490 |
8 | my %LEGACY_DISPATCH = ( |
6806ac0d |
9 | opml => sub { '/opml/opml' }, |
10 | project_index => sub { '/legacyuri/project_index' }, |
592fa490 |
11 | '(?:summary|heads|tags)' => sub { |
6806ac0d |
12 | my($c, $action, $repos) = @_; |
13 | return "/repository/$action", [$repos]; |
592fa490 |
14 | }, |
15 | blob => sub { |
6806ac0d |
16 | my($c, $action, $repos) = @_; |
17 | my $ref = $c->req->param('hb') || $c->req->param('h'); |
18 | return '/ref/blob', [$repos, $ref], $c->req->param('f'); |
24450117 |
19 | }, |
20 | blob_plain => sub { |
21 | my($c, $action, $repos) = @_; |
22 | my $ref = $c->req->param('hb') || $c->req->param('h'); |
23 | return '/ref/raw', [$repos, $ref], $c->req->param('f'); |
592fa490 |
24 | }, |
25 | ); |
26 | |
27 | sub _legacy_uri { |
28 | my($self, $c, $repos, $action) = @_; |
29 | |
30 | return |
6806ac0d |
31 | unless $action; |
592fa490 |
32 | |
33 | my @result = grep { $action =~ /^$_$/ } keys %LEGACY_DISPATCH; |
34 | die "Matched too many actions for '$a' - @result" |
6806ac0d |
35 | if @result > 1; |
592fa490 |
36 | |
37 | return $LEGACY_DISPATCH{$result[0]}->($c, $action, $repos) |
6806ac0d |
38 | if $result[0]; |
592fa490 |
39 | } |
40 | |
319537bf |
41 | sub handler : Chained('/base') PathPart('legacy') Args() { |
20503690 |
42 | my ( $self, $c, $repos ) = @_; |
592fa490 |
43 | |
44 | my ($action, $captures, @args) = $self->_legacy_uri($c, $repos, $c->req->param('a')); |
45 | |
46 | die("Not supported") |
6806ac0d |
47 | unless $action; |
592fa490 |
48 | |
49 | $c->res->redirect($c->uri_for_action($action, $captures || [], @args)); |
ad6d2173 |
50 | $c->res->status(301); |
319537bf |
51 | } |
52 | |
ad6d2173 |
53 | sub project_index : Chained('/base') Args(0) { |
9c515df2 |
54 | my ( $self, $c ) = @_; |
55 | |
56 | $c->response->content_type('text/plain'); |
57 | $c->response->body( |
58 | join "\n", map $_->name, $c->model()->repositories->flatten |
59 | ) or die 'No repositories found in '. $c->model->repo_dir; |
60 | } |
61 | |
319537bf |
62 | __PACKAGE__->meta->make_immutable; |