Skip to content
This repository was archived by the owner on Jan 6, 2026. It is now read-only.

Commit 3f08a42

Browse files
author
Alexander Wirt
committed
Improve delete handling
1 parent 3b6b7d5 commit 3f08a42

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

lib/Paste.pm

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,12 @@ sub add_paste {
257257
$lang = $self->get_lang($lang);
258258
return 0 if $self->error;
259259
}
260-
if ( $expire !~ /^(-1|[0-9]+)/ ) {
261-
$self->{error} = "Expire must be an integer or -1";
260+
261+
# Enforce 90 days max expiration (7776000 seconds)
262+
my $max_expire = 7776000;
263+
264+
if ( $expire !~ /^[0-9]+$/ || $expire > $max_expire ) {
265+
$self->{error} = "Expire must be an integer <= $max_expire (90 days)";
262266
return 0;
263267
}
264268

lib/Paste/App.pm

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,21 @@ sub startup {
8181

8282
$self->helper( paste_model => sub { return $paste } );
8383
$self->helper( tt => sub { return $tt } );
84+
85+
# Periodic cleanup (every hour)
86+
Mojo::IOLoop->recurring(
87+
3600 => sub {
88+
$self->log->debug("Running scheduled paste cleanup...");
89+
$paste->cleanup_expired;
90+
}
91+
);
92+
8493
$self->helper(
8594
render_tt => sub {
8695
my ( $c, $template, $vars ) = @_;
8796
my $output = '';
8897
local %ENV = %{ $c->req->env }; # TT CGI plugin expects %ENV
89-
$c->paste_model->cleanup_expired;
98+
9099
my $user_pastes = [];
91100
if ( $c->current_user ) {
92101
my $sid = Digest::SHA::sha1_hex( $c->current_user->{id} );

templates/paste

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
</select>
2727
<label for="expire"><b>Expiration</b></label>
2828
<select name="expire" id="expire">
29-
<option value="-1">Never</option>
3029
<option value="7776000">90d</option>
3130
<option value="259200">3d</option>
3231
<option value="86400" selected>24h</option>

0 commit comments

Comments
 (0)