copy gitweblite soruce code
|
1 |
use 5.008007; |
renamed gitpub to gitprep
|
2 |
package Gitprep; |
copy gitweblite soruce code
|
3 | |
improved design
|
4 |
our $VERSION = '0.01'; |
copy gitweblite soruce code
|
5 | |
6 |
use Mojo::Base 'Mojolicious'; |
|
renamed gitpub to gitprep
|
7 |
use Gitprep::Git; |
added start page
|
8 |
use DBIx::Custom; |
9 |
use Validator::Custom; |
|
added user management featur...
|
10 |
use Encode qw/encode decode/; |
11 |
use Mojo::JSON; |
|
little more secure login
|
12 |
use Gitprep::API; |
added create repository feat...
|
13 |
use Carp 'croak'; |
added RepManager rename feat...
|
14 |
use Gitprep::RepManager; |
15 |
use Scalar::Util 'weaken'; |
|
fixed git_bin not found bug
|
16 |
use Carp 'croak'; |
copy gitweblite soruce code
|
17 | |
18 |
has 'git'; |
|
added start page
|
19 |
has 'dbi'; |
20 |
has 'validator'; |
|
added RepManager rename feat...
|
21 |
has 'manager'; |
copy gitweblite soruce code
|
22 | |
23 |
sub startup { |
|
24 |
my $self = shift; |
|
25 |
|
|
26 |
# Config |
|
update Mojolicious and added...
|
27 |
$self->plugin('INIConfig', {ext => 'conf'}); |
28 |
|
|
29 |
# My Config(Development) |
|
30 |
my $my_conf_file = $self->home->rel_file('gitprep.my.conf'); |
|
31 |
$self->plugin('INIConfig', {file => $my_conf_file}) if -f $my_conf_file; |
|
32 |
|
|
fixed git_bin not found bug
|
33 |
# Config |
copy gitweblite soruce code
|
34 |
my $conf = $self->config; |
added create repository feat...
|
35 |
$conf->{hypnotoad} ||= {listen => ["http://*:10020"]}; |
fixed listen bug
|
36 |
my $listen = $conf->{hypnotoad}{listen} || ''; |
37 |
if ($listen ne '' && ref $listen ne 'ARRAY') { |
|
38 |
$listen = [ split /,/, $listen ]; |
|
39 |
} |
|
40 |
$conf->{hypnotoad}{listen} = $listen; |
|
copy gitweblite soruce code
|
41 |
|
fixed git_bin not found bug
|
42 |
# Git command |
renamed gitpub to gitprep
|
43 |
my $git = Gitprep::Git->new; |
fixed git_bin not found bug
|
44 |
my $git_bin = $conf->{basic}{git_bin} ? $conf->{basic}{git_bin} : $git->search_bin; |
fix mini bug
|
45 |
if (!$git_bin || ! -e $git_bin) { |
46 |
$git_bin ||= ''; |
|
47 |
my $error = "Can't detect or found git command ($git_bin). set git_bin in gitprep.conf"; |
|
fixed git_bin not found bug
|
48 |
$self->log->error($error); |
49 |
croak $error; |
|
50 |
} |
|
copy gitweblite soruce code
|
51 |
$git->bin($git_bin); |
added AutoRoute plugin
|
52 | |
53 |
# Repository Manager |
|
54 |
my $manager = Gitprep::RepManager->new(app => $self); |
|
55 |
weaken $manager->{app}; |
|
56 |
$self->manager($manager); |
|
fixed git_bin not found bug
|
57 |
|
58 |
# Repository home |
|
move database and repository...
|
59 |
my $rep_home = $self->home->rel_file('data/rep'); |
added create repository feat...
|
60 |
$git->rep_home($rep_home); |
61 |
unless (-d $rep_home) { |
|
62 |
mkdir $rep_home |
|
63 |
or croak "Can't create directory $rep_home: $!"; |
|
64 |
} |
|
copy gitweblite soruce code
|
65 |
$self->git($git); |
66 | ||
improved create repository f...
|
67 |
# DBI |
move database and repository...
|
68 |
my $db_file = $self->home->rel_file('data/gitprep.db'); |
improved create repository f...
|
69 |
my $dbi = DBIx::Custom->connect( |
70 |
dsn => "dbi:SQLite:database=$db_file", |
|
71 |
connector => 1, |
|
72 |
option => {sqlite_unicode => 1} |
|
73 |
); |
|
74 |
$self->dbi($dbi); |
|
75 |
|
|
added tab_index columns
|
76 |
# Setup database |
77 |
$self->manager->setup_database; |
|
improved create repository f...
|
78 |
|
79 |
# Model |
|
80 |
my $models = [ |
|
81 |
{table => 'user', primary_key => 'id'}, |
|
82 |
{table => 'project', primary_key => ['user_id', 'name']} |
|
83 |
]; |
|
84 |
$dbi->create_model($_) for @$models; |
|
85 | ||
86 |
# Fiter |
|
87 |
$dbi->register_filter(json => sub { |
|
88 |
my $value = shift; |
|
89 |
|
|
90 |
if (ref $value) { |
|
91 |
return decode('UTF-8', Mojo::JSON->new->encode($value)); |
|
92 |
} |
|
93 |
else { |
|
94 |
return Mojo::JSON->new->decode(encode('UTF-8', $value)); |
|
95 |
} |
|
96 |
}); |
|
97 |
|
|
98 |
# Validator |
|
99 |
my $validator = Validator::Custom->new; |
|
100 |
$self->validator($validator); |
|
added project delete feature
|
101 |
$validator->register_constraint( |
102 |
user_name => sub { |
|
103 |
my $value = shift; |
|
104 |
|
|
105 |
return ($value || '') =~ /^[a-zA-Z0-9_\-]+$/ |
|
106 |
}, |
|
107 |
project_name => sub { |
|
108 |
my $value = shift; |
|
109 |
|
|
110 |
return ($value || '') =~ /^[a-zA-Z0-9_\-]+$/ |
|
111 |
} |
|
112 |
); |
|
improved create repository f...
|
113 |
|
114 |
# Helper |
|
115 |
$self->helper(gitprep_api => sub { Gitprep::API->new(shift) }); |
|
added AutoRoute plugin
|
116 | |
added feature that project c...
|
117 |
# Routes |
118 |
my $r = $self->routes; |
|
119 | ||
improved create repository f...
|
120 |
# DBViewer(only development) |
121 |
if ($self->mode eq 'development') { |
|
122 |
eval { |
|
123 |
$self->plugin( |
|
124 |
'DBViewer', |
|
added feature that project c...
|
125 |
dsn => "dbi:SQLite:database=$db_file" |
improved create repository f...
|
126 |
); |
127 |
}; |
|
128 |
} |
|
added user delete feature
|
129 |
|
added AutoRoute plugin
|
130 |
# Auto route |
added user delete feature
|
131 |
{ |
132 |
my $r = $r->under(sub { |
|
133 |
my $self = shift; |
|
134 |
|
|
135 |
my $api = $self->gitprep_api; |
|
136 |
|
|
137 |
# Admin page authentication |
|
138 |
{ |
|
139 |
my $path = $self->req->url->path->parts->[0] || ''; |
|
140 | ||
141 |
if ($path eq '_admin' && !$api->logined_admin) { |
|
142 |
$self->redirect_to('/'); |
|
143 |
return; |
|
144 |
} |
|
145 |
} |
|
146 |
|
|
147 |
return 1; |
|
148 |
}); |
|
149 |
$self->plugin('AutoRoute', route => $r); |
|
150 |
} |
|
added feature that project c...
|
151 | |
added AutoRoute plugin
|
152 |
# User defined Routes |
added login page
|
153 |
{ |
added user management featur...
|
154 |
# User |
added reset password feature
|
155 |
my $r = $r->route('/:user'); |
156 |
{ |
|
157 |
# Home |
|
158 |
$r->get('/')->name('user'); |
|
159 |
|
|
160 |
# Settings |
|
161 |
$r->get('/_settings')->name('user-settings'); |
|
162 |
} |
|
added AutoRoute plugin
|
163 |
|
164 |
# Project |
|
cleanup many pages
|
165 |
{ |
added reset password feature
|
166 |
my $r = $r->route('/:project'); |
167 |
|
|
168 |
# Home |
|
added AutoRoute plugin
|
169 |
$r->get('/')->name('project'); |
cleanup many pages
|
170 |
|
added AutoRoute plugin
|
171 |
# Commit |
172 |
$r->get('/commit/#diff')->name('commit'); |
|
173 |
|
|
174 |
# Commits |
|
175 |
$r->get('/commits/#rev', {id => 'HEAD'})->name('commits'); |
|
176 |
$r->get('/commits/#rev/(*blob)')->name('commits'); |
|
177 |
|
|
178 |
# Branches |
|
added admin password reset s...
|
179 |
$r->get('/branches')->name('branches'); |
Fixed repositories page
|
180 | |
added AutoRoute plugin
|
181 |
# Tags |
added admin password reset s...
|
182 |
$r->get('/tags')->name('tags'); |
improved repository page des...
|
183 | |
added AutoRoute plugin
|
184 |
# Tree |
185 |
$r->get('/tree/(*object)')->name('tree'); |
|
186 |
|
|
187 |
# Blob |
|
188 |
$r->get('/blob/(*object)')->name('blob'); |
|
189 |
|
|
190 |
# Blob diff |
|
191 |
$r->get('/blobdiff/(#diff)/(*file)')->name('blobdiff'); |
|
192 |
|
|
193 |
# Raw |
|
194 |
$r->get('/raw/(*object)')->name('raw'); |
|
195 |
|
|
196 |
# Archive |
|
197 |
$r->get('/archive/(#rev).tar.gz')->name('archive')->to(archive_type => 'tar'); |
|
198 |
$r->get('/archive/(#rev).zip')->name('archive')->to(archive_type => 'zip'); |
|
199 |
|
|
200 |
# Compare |
|
201 |
$r->get('/compare/(#rev1)...(#rev2)')->name('compare'); |
|
202 |
|
|
203 |
# Settings |
|
added reset password feature
|
204 |
$r->any('/settings')->name('project-settings'); |
added AutoRoute plugin
|
205 |
|
206 |
# Fork |
|
added admin password reset s...
|
207 |
$r->any('/fork')->name('fork'); |
added feature that you see p...
|
208 | |
209 |
# Fork |
|
210 |
$r->get('/network')->name('network'); |
|
added AutoRoute plugin
|
211 |
} |
212 |
} |
|
added downloads page
|
213 | |
added AutoRoute plugin
|
214 |
# Reverse proxy support |
215 |
$ENV{MOJO_REVERSE_PROXY} = 1; |
|
216 |
$self->hook('before_dispatch' => sub { |
|
217 |
my $self = shift; |
|
added fork feature
|
218 |
|
added AutoRoute plugin
|
219 |
if ($self->req->headers->header('X-Forwarded-Host')) { |
220 |
my $prefix = shift @{$self->req->url->path->parts}; |
|
221 |
push @{$self->req->url->base->path->parts}, $prefix |
|
222 |
if defined $prefix; |
|
223 |
} |
|
224 |
}); |
|
copy gitweblite soruce code
|
225 |
} |
226 | ||
227 |
1; |