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 | |
894b2dc8 |
8 | my %LEGACY_DISPATCH = ( |
7ce87dff |
9 | opml => sub { '/opml/opml' }, |
10 | project_index => sub { '/legacyuri/project_index' }, |
894b2dc8 |
11 | '(?:summary|heads|tags)' => sub { |
7ce87dff |
12 | my($c, $action, $repos) = @_; |
13 | return "/repository/$action", [$repos]; |
894b2dc8 |
14 | }, |
15 | blob => sub { |
7ce87dff |
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'); |
4a3445c1 |
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'); |
2a3e4697 |
24 | }, |
25 | blobdiff => sub { |
26 | my($c, $action, $repos) = @_; |
27 | my $ref = $c->req->param('hb') || $c->req->param('h'); |
28 | my $compare = $c->req->param('hbp') || $c->req->param('hp'); |
29 | return '/ref/diff', [$repos, $ref], $compare, $c->req->param('f'); |
f38d7a26 |
30 | }, |
31 | blobdiff_plain => sub { |
32 | my($c, $action, $repos) = @_; |
33 | my $ref = $c->req->param('hb') || $c->req->param('h'); |
34 | my $compare = $c->req->param('hbp') || $c->req->param('hp'); |
35 | return '/ref/diff_plain', [$repos, $ref], $compare, $c->req->param('f'); |
894b2dc8 |
36 | }, |
37 | ); |
38 | |
39 | sub _legacy_uri { |
40 | my($self, $c, $repos, $action) = @_; |
41 | |
42 | return |
7ce87dff |
43 | unless $action; |
894b2dc8 |
44 | |
45 | my @result = grep { $action =~ /^$_$/ } keys %LEGACY_DISPATCH; |
46 | die "Matched too many actions for '$a' - @result" |
7ce87dff |
47 | if @result > 1; |
894b2dc8 |
48 | |
49 | return $LEGACY_DISPATCH{$result[0]}->($c, $action, $repos) |
7ce87dff |
50 | if $result[0]; |
894b2dc8 |
51 | } |
52 | |
319537bf |
53 | sub handler : Chained('/base') PathPart('legacy') Args() { |
20503690 |
54 | my ( $self, $c, $repos ) = @_; |
894b2dc8 |
55 | |
56 | my ($action, $captures, @args) = $self->_legacy_uri($c, $repos, $c->req->param('a')); |
57 | |
58 | die("Not supported") |
7ce87dff |
59 | unless $action; |
894b2dc8 |
60 | |
61 | $c->res->redirect($c->uri_for_action($action, $captures || [], @args)); |
ad6d2173 |
62 | $c->res->status(301); |
319537bf |
63 | } |
64 | |
ad6d2173 |
65 | sub project_index : Chained('/base') Args(0) { |
9c515df2 |
66 | my ( $self, $c ) = @_; |
67 | |
68 | $c->response->content_type('text/plain'); |
69 | $c->response->body( |
70 | join "\n", map $_->name, $c->model()->repositories->flatten |
71 | ) or die 'No repositories found in '. $c->model->repo_dir; |
72 | } |
73 | |
319537bf |
74 | __PACKAGE__->meta->make_immutable; |